All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.sommeri.less4j.core.compiler.scopes.view.ScopesTreeView Maven / Gradle / Ivy

Go to download

Less language is an extension of css and less4j compiles it into regular css. It adds several dynamic features into css: variables, expressions, nested rules. Less4j is a port. The original compiler was written in JavaScript and is called less.js. The less language is mostly defined in less.js documentation/issues and by what less.js actually do. Links to less.js: * home page: http://lesscss.org/ * source code & issues: https://github.com/cloudhead/less.js

There is a newer version: 1.17.2
Show newest version
package com.github.sommeri.less4j.core.compiler.scopes.view;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.github.sommeri.less4j.core.compiler.scopes.AbstractScopesTree;
import com.github.sommeri.less4j.core.compiler.scopes.IScope;
import com.github.sommeri.less4j.core.compiler.scopes.IScopesTree;
import com.github.sommeri.less4j.core.compiler.scopes.ScopeFactory;

public class ScopesTreeView extends AbstractScopesTree {

  protected ScopeView scope;

  private IScope joinToParentTree;
  private final IScopesTree originalStructure;
  
  private ScopeView publicParent;
  private List publicChilds = null;
  private Map fakeChildsMap = new HashMap();

  public ScopesTreeView(IScopesTree originalStructure, IScope joinToParentTree, ScopeView publicParent, ScopeView publicChild) {
    super();
    this.originalStructure = originalStructure;
    this.joinToParentTree = joinToParentTree;
    this.publicParent = publicParent;

    if (publicChild!=null)
      this.fakeChildsMap.put(publicChild.getUnderlying(), publicChild);
  }

  public void setScope(ScopeView scope) {
    this.scope = scope;
  }

  @Override
  public void addChild(IScope child) {
    throw new IllegalStateException("Scopes view does not accept new childs.");
  }

  @Override
  public void setParent(IScope parent) {
    throw new IllegalStateException("Scopes view does not accept new parents.");
  }

  @Override
  public ScopeView getParent() {
    if (publicParent != null)
      return publicParent;

    publicParent = createPublicParent();
    return publicParent;
  }

  @Override
  public List getChilds() {
    if (publicChilds != null)
      return publicChilds;

    publicChilds = createPublicChilds();
    return publicChilds;
  }

  public List createPublicChilds() {
    List realChilds = originalStructure.getChilds();
    if (realChilds == null)
      return null;

    List result = new ArrayList();
    for (IScope childScope : realChilds) {
      if (fakeChildsMap.containsKey(childScope)) {
        result.add(fakeChildsMap.get(childScope));
      } else {
        result.add(ScopeFactory.createChildScopeView(childScope, scope, joinToParentTree));
      }
    }
    
    return result;

  }

  protected ScopeView createPublicParent() {
    IScope realParent = originalStructure.getParent();
    if (realParent != null)
      return ScopeFactory.createParentScopeView(realParent, scope, joinToParentTree);

    if (joinToParentTree == null)
      return null;

    return ScopeFactory.createScopeViewJoint(joinToParentTree, scope);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy