Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 Martin Skurla
   *
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
   * the License. You may obtain a copy of the License at
   *
   *   http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
 package org.crazyjavahacking.astvisualizer.impl.javac;
 
 
 import java.util.Set;
 
 
 
Node model factory.

Author(s):
Martin
 
 final class NodeModelFactory {
 
     //-----------------------------------------------------------------------------------------------------------------
     // Constants.
     //-----------------------------------------------------------------------------------------------------------------
     private static final String NAME_TREE_KIND      = "Name";
     private static final String MODIFIER_TREE_KIND  = "Modifier";
     private static final String TYPE_KIND_TREE_KIND = "TypeKind";
 
 
     //-----------------------------------------------------------------------------------------------------------------
     // Constructors.
     //-----------------------------------------------------------------------------------------------------------------
     private NodeModelFactory() {}
 
 
     //-----------------------------------------------------------------------------------------------------------------
     // Public Methods.
     //-----------------------------------------------------------------------------------------------------------------
     
Creates NodeModel from com.sun.source.tree.Tree type. Tree could have properties and is never leaf.

Parameters:
depth node depth
order node order
textRepresentation textual representation
tree tree
sourcePosition source position
Returns:
NodeModel
 
     public static NodeModel fromComSourceSunTreeTree(int depthint orderString textRepresentationTree tree,
             PositionWithinSourceCode sourcePosition) {
 
         boolean isNotLeaf = false;
         String treeKind = tree.getKind().toString();
 
         Set<NodeModelPropertynodeModelProperties = JavacNodeModelPropertiesExtractor.extractFromTree(tree);
 
         return createNodeModel(depthorderisNotLeaftreeKindtextRepresentationsourcePositionnodeModelProperties);
     }

    
Creates NodeModel from javax.lang.model.element.Name type. Name does not have properties and is always leaf.

Parameters:
depth node depth
order node order
name name
sourcePosition source position
Returns:
NodeModel
See also:
javax.lang.model.element.Name
 
     public static NodeModel fromJavaxLangModelElementName(int depthint orderName name,
             PositionWithinSourceCode sourcePosition) {
 
         boolean isLeaf = true;
         String treeKind = ;
         String textualRepresentation = name.toString();
 
         Set<NodeModelPropertyemptyNodeModelProperties = Collections.emptySet();
 
         return createNodeModel(depthorderisLeaftreeKindtextualRepresentationsourcePosition,
                                                                                       emptyNodeModelProperties);
     }

    
Creates NodeModel from javax.lang.model.element.Modifier type. Modifier does not have properties and is always leaf.

Parameters:
depth node depth
order node order
modifier modifier
sourcePosition source position
Returns:
NodeModel
See also:
javax.lang.model.element.Modifier
    public static NodeModel fromJavaxLangModelElementModifier(int depthint orderModifier modifier,
            PositionWithinSourceCode sourcePosition) {
        boolean isLeaf = true;
        String treeKind = ;
        String textualRepresentation = modifier.toString();
        Set<NodeModelPropertyemptyNodeModelProperties = Collections.emptySet();
        return createNodeModel(depthorderisLeaftreeKindtextualRepresentationsourcePosition,
                                                                                      emptyNodeModelProperties);
    }

    
Creates NodeModel from javax.lang.model.type.TypeKind type. TypeKind does not have properties and is always leaf.

Parameters:
depth node depth
order node order
typeKind type kind
sourcePosition source position
Returns:
NodeModel
See also:
javax.lang.model.type.TypeKind
    public static NodeModel fromJavaxLangModelTypeTypeKind(int depthint orderTypeKind typeKind,
            PositionWithinSourceCode sourcePosition) {
        boolean isLeaf = true;
        String treeKind = ;
        String textualRepresentation = typeKind.toString().toLowerCase();
        Set<NodeModelPropertyemptyNodeModelProperties = Collections.emptySet();
        return createNodeModel(depthorderisLeaftreeKindtextualRepresentationsourcePosition,
                                                                                      emptyNodeModelProperties);
    }
    //-----------------------------------------------------------------------------------------------------------------
    // Private Helpers.
    //-----------------------------------------------------------------------------------------------------------------
    
Creates NodeModel according to given arguments.

Parameters:
depth depth
order order
isLeaf leaf flag
treeKind tree kind
textualRepresentation textual representation
positionWithinSourceCode position within source code
nodeModelProperties node model properties
Returns:
NodeModel
    private static NodeModel createNodeModel(int depthint orderboolean isLeafString treeKind,
            String textualRepresentationPositionWithinSourceCode positionWithinSourceCode,
            Set<NodeModelPropertynodeModelProperties) {
        return new NodeModel(depth,
                             order,
                             isLeaf,
                             treeKind,
                             textualRepresentation,
                             positionWithinSourceCode,
                             nodeModelProperties);
    }
New to GrepCode? Check out our FAQ X