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

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


        Selector selector = handleSelector(kid);
        if (selector != null)
          selectors.add(selector);
        previousKid = selector;
      } else if (kid.getType() == LessLexer.BODY) {
        GeneralBody body = handleGeneralBody(kid);
        ruleSet.setBody(body);
        previousKid = body;
      } else if (kid.getType() == LessLexer.GUARD) {
        guards.add(handleGuard(kid));
      } else if (kid.getType() == LessLexer.COMMA) {
View Full Code Here


    if (list.isEmpty()) {
      token.addOrphans(orphansOrFollowLastMember);
    } else {
      list.get(list.size() - 1).getUnderlyingStructure().addFollowing(orphansOrFollowLastMember);
    }
    return new GeneralBody(token, lbrace, rbrace, list);
  }
View Full Code Here

  }

  private void replaceMixinReferences(Map<ASTCssNode, GeneralBody> solvedReferences) {
    for (Entry<ASTCssNode, GeneralBody> entry : solvedReferences.entrySet()) {
      ASTCssNode mixinReference = entry.getKey();
      GeneralBody replacement = entry.getValue();

      manipulator.setTreeSilentness(replacement, mixinReference.isSilent());
      manipulator.replaceInBody(mixinReference, replacement.getMembers());
    }
  }
View Full Code Here

    for (ASTCssNode kid : childs) {
      if (isMixinReference(kid)) {
        MixinReference reference = (MixinReference) kid;

        List<FullMixinDefinition> foundMixins = findReferencedMixins(reference, referenceScope);
        GeneralBody replacement = mixinsSolver.buildMixinReferenceReplacement(reference, referenceScope, foundMixins);

        AstLogic.validateLessBodyCompatibility(reference, replacement.getMembers(), problemsHandler);
        solvedMixinReferences.put(reference, replacement);
      } else if (isDetachedRulesetReference(kid)) {
        DetachedRulesetReference detachedRulesetReference = (DetachedRulesetReference) kid;
        Expression fullNodeDefinition = referenceScope.getValue(detachedRulesetReference.getVariable());
       
        if (fullNodeDefinition == null) {
          handleUnavailableDetachedRulesetReference(detachedRulesetReference, solvedMixinReferences);
        } else {
          ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator(referenceScope, problemsHandler, configuration);
          Expression evaluatedDetachedRuleset = expressionEvaluator.evaluate(fullNodeDefinition);
          fullNodeDefinition = evaluatedDetachedRuleset;
          if (evaluatedDetachedRuleset.getType() != ASTCssNodeType.DETACHED_RULESET) {
            handleWrongDetachedRulesetReference(detachedRulesetReference, evaluatedDetachedRuleset, solvedMixinReferences);
          } else {
            DetachedRuleset detachedRuleset = (DetachedRuleset) evaluatedDetachedRuleset;
            IScope scope = detachedRuleset.getScope();
            GeneralBody replacement = mixinsSolver.buildDetachedRulesetReplacement(detachedRulesetReference, referenceScope, detachedRuleset, scope);
            AstLogic.validateLessBodyCompatibility(kid, replacement.getMembers(), problemsHandler);
            solvedMixinReferences.put(kid, replacement);
          }
        }

      }
View Full Code Here

    return solvedMixinReferences;
  }

  private void handleUnavailableDetachedRulesetReference(DetachedRulesetReference detachedRulesetReference, Map<ASTCssNode, GeneralBody> solvedReferences) {
    problemsHandler.detachedRulesetNotfound(detachedRulesetReference);
    GeneralBody errorBody = new GeneralBody(detachedRulesetReference.getUnderlyingStructure());
    errorBody.addMember(new FaultyNode(detachedRulesetReference));
    solvedReferences.put(detachedRulesetReference, errorBody);
  }
View Full Code Here

    solvedReferences.put(detachedRulesetReference, errorBody);
  }

  private void handleWrongDetachedRulesetReference(DetachedRulesetReference detachedRulesetReference, Expression value,  Map<ASTCssNode, GeneralBody> solvedReferences) {
    problemsHandler.wrongDetachedRulesetReference(detachedRulesetReference, value);
    GeneralBody errorBody = new GeneralBody(detachedRulesetReference.getUnderlyingStructure());
    errorBody.addMember(new FaultyNode(detachedRulesetReference));
    solvedReferences.put(detachedRulesetReference, errorBody);
  }
View Full Code Here

      StyleSheet result = new StyleSheet(underlyingStructure);
      Media media = new Media(underlyingStructure);
      result.addMember(media);
      media.setParent(result);
      media.setMediums(node.getMediums());
      GeneralBody mediaBody = new GeneralBody(underlyingStructure, importedAst.getMembers());
      media.setBody(mediaBody);
      media.configureParentToAllChilds();
      mediaBody.configureParentToAllChilds();
      return result;
    }
   
    return importedAst;
  }
View Full Code Here

  private List<FullMixinDefinition> buildAndFind(FullMixinDefinition fullMixin, final List<String> nameChain, final MixinReference reference) {

    final List<FullMixinDefinition> result = new ArrayList<FullMixinDefinition>();

    final ReusableStructure mixin = fullMixin.getMixin();
    final GeneralBody bodyClone = mixin.getBody().clone();
    final IScope scope = fullMixin.getScope();

    InScopeSnapshotRunner.runInLocalDataSnapshot(scope, new ITask() {

      @Override
View Full Code Here

    ArgumentsBuilder builder = new ArgumentsBuilder(reference, mixin.getMixin(), new ExpressionEvaluator(referenceScope, problemsHandler, configuration), problemsHandler);
    return builder.build();
  }

  public GeneralBody buildMixinReferenceReplacement(final MixinReference reference, final IScope callerScope, List<FullMixinDefinition> mixins) {
    GeneralBody result = new GeneralBody(reference.getUnderlyingStructure());
    if (mixins.isEmpty())
      return result;

    //candidate mixins with information about their default() function use are stored here
    final List<BodyCompilationResult> compiledMixins = new ArrayList<BodyCompilationResult>();

    for (final FullMixinDefinition fullMixin : mixins) {
      final ReusableStructure mixin = fullMixin.getMixin();
      final IScope mixinScope = fullMixin.getScope();

      // the following needs to run in snapshot because calculateMixinsWorkingScope modifies that scope
      InScopeSnapshotRunner.runInLocalDataSnapshot(mixinScope.getParent(), new ITask() {

        @Override
        public void run() {
          // add arguments
          IScope mixinArguments = buildMixinsArguments(reference, callerScope, fullMixin);
          mixinScope.getParent().add(mixinArguments);
          IScope mixinWorkingScope = scopeManipulation.joinIfIndependent(callerScope, mixinScope);

          MixinsGuardsValidator guardsValidator = new MixinsGuardsValidator(mixinWorkingScope, problemsHandler, configuration);
          GuardValue guardValue = guardsValidator.evaluateGuards(mixin);

          if (guardValue != GuardValue.DO_NOT_USE) {
            //OPTIMIZATION POSSIBLE: there is no need to compile mixins at this point, some of them are not going to be
            //used and create snapshot operation is cheap now. It should be done later on.
            BodyCompilationResult compiled = resolveCalledBody(callerScope, fullMixin.getMixin(), mixinWorkingScope, ReturnMode.MIXINS_AND_VARIABLES);
            //mark the mixin according to its default() function use
            compiled.setGuardValue(guardValue);
            //store the mixin as candidate
            compiledMixins.add(compiled);
          }
        }
      });
    }

    // filter out mixins we do not want to use 
    List<BodyCompilationResult> mixinsToBeUsed = defaultGuardHelper.chooseMixinsToBeUsed(compiledMixins, reference);

    // update mixin replacements and update scope with imported variables and mixins
    for (BodyCompilationResult compiled : mixinsToBeUsed) {
      result.addMembers(compiled.getReplacement());
      callerScope.addToDataPlaceholder(compiled.getReturnValues());
    }

    callerScope.closeDataPlaceholder();
    resolveImportance(reference, result);
View Full Code Here

  }

  public GeneralBody buildDetachedRulesetReplacement(DetachedRulesetReference reference, IScope callerScope, DetachedRuleset detachedRuleset, IScope detachedRulesetScope) {
    IScope mixinWorkingScope = scopeManipulation.joinIfIndependent(callerScope, detachedRulesetScope);
    BodyCompilationResult compiled = resolveCalledBody(callerScope, detachedRuleset, mixinWorkingScope, ReturnMode.MIXINS);
    GeneralBody result = new GeneralBody(reference.getUnderlyingStructure());

    result.addMembers(compiled.getReplacement());
    callerScope.addToDataPlaceholder(compiled.getReturnValues());
    callerScope.closeDataPlaceholder();

    //resolveImportance(reference, result);
    shiftComments(reference, result);
View Full Code Here

TOP

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

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.