Package com.github.sommeri.less4j.core.compiler.scopes

Examples of com.github.sommeri.less4j.core.compiler.scopes.IScope


    semiCompiledNodes.push(node);

    try {
      List<ASTCssNode> childs = new ArrayList<ASTCssNode>(node.getChilds());
      if (!childs.isEmpty()) {
        IScope scope = iteratedScope.getScope();

        // solve all detached ruleset/mixin references and store solutions
        Map<ASTCssNode, GeneralBody> solvedReferences = solveCalls(childs, scope);

        // solve whatever is not a mixin/detached ruleset reference
View Full Code Here


          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

  public IScope extractScope(ASTCssNode node) {
    currentScope = null;
    importsPlaceholders = new LinkedList<PlaceholderScope>();

    IScope result = buildScope(node);
    return result;
  }
View Full Code Here

      } else if (kid.getType() == ASTCssNodeType.VARIABLE_DECLARATION) {
        currentScope.registerVariable((VariableDeclaration) kid);
        manipulator.removeFromBody(kid);
      } else if (kid.getType() == ASTCssNodeType.REUSABLE_STRUCTURE) {
        ReusableStructure mixin = (ReusableStructure) kid;
        IScope bodyScope = currentScope.childByOwners(mixin, mixin.getBody());
        currentScope.registerMixin(mixin, bodyScope);
        bodyScope.removedFromAst();
        if (bodyScope.hasParent())
          bodyScope.getParent().removedFromAst(); // remove also arguments scope from tree
        manipulator.removeFromBody(kid);
      } else if (kid.getType() == ASTCssNodeType.DETACHED_RULESET) {
        DetachedRuleset detached = (DetachedRuleset) kid;
        IScope bodyScope = currentScope.childByOwners(detached, detached.getBody());
        if (bodyScope.hasParent())
          bodyScope.getParent().removedFromAst(); // remove also arguments scope from tree
        bodyScope.removedFromAst();
        detached.setScope(bodyScope);
      } else if (kid.getType() == ASTCssNodeType.RULE_SET) {
        RuleSet ruleSet = (RuleSet) kid;
        if (ruleSet.isUsableAsReusableStructure()) {
          IScope bodyScope = currentScope.childByOwners(ruleSet, ruleSet.getBody());
          currentScope.registerMixin(ruleSet.convertToReusableStructure(), bodyScope);
        }
      } else if (kid.getType() == ASTCssNodeType.MIXIN_REFERENCE) {
        currentScope.createDataPlaceholder();
      } else if (kid.getType() == ASTCssNodeType.DETACHED_RULESET_REFERENCE) {
        currentScope.createDataPlaceholder();
      } else if (AstLogic.isExpression(kid)) {
        Expression value = (Expression) kid;
        value.setScope(currentScope);
      }
    }

    IScope result = currentScope;
    if (hasOwnScope)
      decreaseScope();

    return result;
  }
View Full Code Here

   *
   */
  public List<FullMixinDefinition> getNearestMixins(IScope scope, MixinReference reference) {
    foundNamespace = false;
    List<String> nameChain = reference.getNameChainAsStrings();
    IScope space = scope;

    List<FullMixinDefinition> result = findInMatchingNamespace(scope, nameChain, reference);
    while (result.isEmpty() && space.hasParent()) {
      space = space.getParent();
      result = findInMatchingNamespace(space, nameChain, reference);
    }
    return result;
  }
View Full Code Here

    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
      public void run() {
View Full Code Here

  }

  private BodyCompilationResult resolveCalledBody(final IScope callerScope, final BodyOwner<?> bodyOwner, final IScope bodyWorkingScope, final ReturnMode returnMode) {
    final ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator(bodyWorkingScope, problemsHandler, configuration);

    final IScope referencedMixinScope = bodyWorkingScope;
    // ... and I'm starting to see the point of closures ...
    return InScopeSnapshotRunner.runInOriginalDataSnapshot(referencedMixinScope, new IFunction<BodyCompilationResult>() {

      @Override
      public BodyCompilationResult run() {
        // compile referenced mixin - keep the original copy unchanged
        List<ASTCssNode> replacement = compileBody(bodyOwner.getBody(), referencedMixinScope);

        // collect variables and mixins to be imported
        IScope returnValues = ScopeFactory.createDummyScope();
        if (returnMode==ReturnMode.MIXINS_AND_VARIABLES) {
          returnValues.addFilteredVariables(new ImportedScopeFilter(expressionEvaluator, callerScope), referencedMixinScope);
        }
        List<FullMixinDefinition> unmodifiedMixinsToImport = referencedMixinScope.getAllMixins();
       
        List<FullMixinDefinition> allMixinsToImport = scopeManipulation.mixinsToImport(callerScope, referencedMixinScope, unmodifiedMixinsToImport);
        returnValues.addAllMixins(allMixinsToImport);

        return new BodyCompilationResult((ASTCssNode) bodyOwner, replacement, returnValues);
      }

    });
View Full Code Here

    //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) {
View Full Code Here

    return result;
  }

  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());
View Full Code Here

      this.importTargetScope = importTargetScope;
    }

    public Expression apply(Expression input) {
      Expression result = expressionEvaluator.evaluate(input);
      IScope newScope = apply(result.getScope());
      result.setScope(newScope);
      return result;
    }
View Full Code Here

TOP

Related Classes of com.github.sommeri.less4j.core.compiler.scopes.IScope

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.