Package com.github.sommeri.less4j.core.ast

Examples of com.github.sommeri.less4j.core.ast.SelectorPart


    Selector selector = (Selector) switchOn(children.get(0));
    if (selector.isExtending()) {
      problemsHandler.warnExtendInsideExtend(selector);
    }

    SelectorPart lastPart = selector.getLastPart();
    if (lastPart == null || !(lastPart instanceof SimpleSelector))
      return new Extend(token, selector);

    SimpleSelector possibleAll = (SimpleSelector) lastPart;
    if (possibleAll.hasSubsequent() || !possibleAll.hasElement())
View Full Code Here


  public Selector buildSelector() {
    Iterator<HiddenTokenAwareTree> iterator = token.getChildren().iterator();
    Selector result = new Selector(token, new ArrayList<SelectorPart>());
    while (iterator.hasNext()) {
      SelectorCombinator combinator = null;
      SelectorPart part = null;
      HiddenTokenAwareTree kid = iterator.next();

      if (ConversionUtils.isSelectorCombinator(kid)) {
        combinator = ConversionUtils.createSelectorCombinator(kid);
        kid = iterator.next();
        part = (SelectorPart) parent.switchOn(kid);
        // Ignore descendant combinator before appender. This info is already hidden in appender.isDirectlyBefore.
        if (isDescendant(combinator) && kid.getType() == LessLexer.NESTED_APPENDER)
          combinator = null;
      } else {
        //if it is not a combinator, then it is either nested appender, simple selector or escaped selector  
        part = (SelectorPart) parent.switchOn(kid);
      }

      part.setLeadingCombinator(combinator);
      if (combinator != null)
        part.getUnderlyingStructure().moveHidden(combinator.getUnderlyingStructure(), null);

      addPart(result, part);
    }
    return result;
  }
View Full Code Here

    List<MatchMarker<SelectorPart>> matches = listsComparator.findMatches(lookForParts, inSelectorParts, selectorPartsComparator);
    if (matches.isEmpty() || originalReplaceBy == null || originalReplaceBy.isEmpty())
      return ;

    SelectorPart lastRemainder = null;
    MatchMarker<SelectorPart> previousMatch = null;
    for (MatchMarker<SelectorPart> currentMatch : matches) {
      SelectorPart firstMatch = currentMatch.getFirst();
      SelectorPart lastMatch = currentMatch.getLast();
     
      if (!inSelectorParts.contains(firstMatch) && (previousMatch==null || lastRemainder==null ||  previousMatch.getLast()!=currentMatch.getFirst())) { //particularly ugly condition
        previousMatch = currentMatch;
        continue ;
      }
      boolean prefixNeeded = true;
     
      if (!inSelectorParts.contains(firstMatch) && lastRemainder!=null) { //particularly ugly code
        firstMatch = ArraysUtils.last(builder.getParts());
        prefixNeeded = false;
      }
     
      previousMatch = currentMatch;
      List<SelectorPart> replaceBy = ArraysUtils.deeplyClonedList(originalReplaceBy);

      if (firstMatch == lastMatch) {
        if (lookForParts.size() != 1)
          throw new BugHappened("Impossible state happened.", lookForParts.isEmpty() ? null : lookForParts.get(0));

        List<SelectorPart> replaceInside = replaceInsidePart(lookForParts.get(0), lastMatch, replaceBy);
        ArraysUtils.replace(lastMatch, inSelectorParts, replaceInside);
      } else {
        if (prefixNeeded)
          builder.addUpTo(inSelectorParts, firstMatch);
        ArraysUtils.chopFirst(inSelectorParts); // now we are chopping firstMatch

        SelectorPart firstRemainder = selectorPartsComparator.cutSuffix(lookForParts.get(0), firstMatch);
        if (firstRemainder != null) {
          if (prefixNeeded)
            builder.add(firstRemainder);
          builder.directlyAttach(replaceBy);
        } else {
View Full Code Here

  public void directlyAttach(SelectorPart part) {
    if (newInSelectorParts.isEmpty()) {
      add(part);
    } else {
      SelectorPart tail = ArraysUtils.last(newInSelectorParts);
      manipulator.directlyJoinParts(tail, part);
    }
  }
View Full Code Here

    }
  }

  public void directlyAttach(List<SelectorPart> list) {
    if (!newInSelectorParts.isEmpty()) {
      SelectorPart tail = ArraysUtils.last(newInSelectorParts);
      SelectorPart firstReplaceBy = list.remove(0);
      manipulator.directlyJoinParts(tail, firstReplaceBy);
    }
    addAll(list);
  }
View Full Code Here

      return secondI.clone();

    Selector first = firstI.clone();
    List<SelectorPart> secondParts = ArraysUtils.deeplyClonedList(secondI.getParts());
    List<Extend> secondExtends = ArraysUtils.deeplyClonedList(secondI.getExtend());
    SelectorPart secondHead = secondParts.get(0);

    if (secondHead.isAppender())
      return indirectJoinNoClone(first, secondHead.getLeadingCombinator(), secondParts, secondExtends);

    /*
     * FIXME: test on old whether survives if first is not simple selector. (say, if:
     * (~"escaped") {
     *   &:pseudo() {
     *   }
     * }
     *
     */
    SelectorPart attachToHead = first.getLastPart();
    directlyJoinParts(attachToHead, secondHead);

    secondParts.remove(0);
    SelectorCombinator leadingCombinator = secondParts.isEmpty() ? null : secondParts.get(0).getLeadingCombinator();
    return indirectJoinNoClone(first, leadingCombinator, secondParts, secondExtends);
View Full Code Here

  private boolean isEmptySelector(Selector selector) {
    if (selector.isCombined())
      return false;

    SelectorPart head = selector.getHead();
    if (head.getType() != ASTCssNodeType.SIMPLE_SELECTOR)
      return false;

    SimpleSelector simpleHead = (SimpleSelector) head;
    if (!simpleHead.isEmptyForm() || !simpleHead.isStar()) {
      return false;
View Full Code Here

TOP

Related Classes of com.github.sommeri.less4j.core.ast.SelectorPart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.