当前位置: 首页>>代码示例>>Java>>正文


Java IdentifierTree类代码示例

本文整理汇总了Java中com.sun.source.tree.IdentifierTree的典型用法代码示例。如果您正苦于以下问题:Java IdentifierTree类的具体用法?Java IdentifierTree怎么用?Java IdentifierTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IdentifierTree类属于com.sun.source.tree包,在下文中一共展示了IdentifierTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTypeMirror

import com.sun.source.tree.IdentifierTree; //导入依赖的package包/类
@Override
public TypeMirror getTypeMirror(TreePath arg0) {
    Tree tree = arg0.getLeaf();
    if (tree.getKind() == Tree.Kind.IDENTIFIER) {
        Map<String, ObjectVariable> map = null;
        try {
            // [TODO] add JPDADebuggerImpl.getAllLabels() to API
            Method method = debugger.getClass().getMethod("getAllLabels"); // NOI18N
            map = (Map<String, ObjectVariable>) method.invoke(debugger);
        } catch (Exception ex) {
            Exceptions.printStackTrace(ex);
        }
        if (map != null) {
            String name = ((IdentifierTree)tree).getName().toString();
            ObjectVariable var = map.get(name);
            if (var != null) {
                Elements elements = controller.getElements();
                TypeElement typeElem = elements.getTypeElement(var.getClassType().getName());
                if (typeElem != null) {
                    return typeElem.asType();
                }
            }
        }
    }
    return trees.getTypeMirror(arg0);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:WatchPanel.java

示例2: getUsedImplicitlyImportedClasses

import com.sun.source.tree.IdentifierTree; //导入依赖的package包/类
private Map<String, Element> getUsedImplicitlyImportedClasses() {
    if (usedImplicitlyImportedClassesCache != null) {
        return usedImplicitlyImportedClassesCache;
    }
    
    usedImplicitlyImportedClassesCache = new HashMap<String, Element>();
    
    new ErrorAwareTreeScanner<Void, Void>() {
        @Override
        public Void visitIdentifier(IdentifierTree node, Void p) {
            Element e = overlay.wrap(model, elements, model.getElement(node));

            //javaLang might be null for broken platforms
            if (e != null && ((javaLang != null && javaLang.equals(e.getEnclosingElement())) || (pack != null && pack.equals(e.getEnclosingElement())))) {
                usedImplicitlyImportedClassesCache.put(e.getSimpleName().toString(), e);
            }

            return null;
        }
    }.scan(cut, null);
    
    return usedImplicitlyImportedClassesCache;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:ImportAnalysis2.java

示例3: visitIdentifier

import com.sun.source.tree.IdentifierTree; //导入依赖的package包/类
public Boolean visitIdentifier(IdentifierTree node, TreePath p) {
    if (p == null)
        return super.visitIdentifier(node, p);

    switch (verifyElements(getCurrentPath(), p)) {
        case MATCH_CHECK_DEEPER:
            if (node.getKind() == p.getLeaf().getKind()) {
                return true;
            }

            return deepVerifyIdentifier2MemberSelect(getCurrentPath(), p);
        case MATCH:
            return true;
        default:
        case NO_MATCH:
        case NO_MATCH_CONTINUE:
            return false;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:CopyFinder.java

示例4: addSyntheticTrees

import com.sun.source.tree.IdentifierTree; //导入依赖的package包/类
private void addSyntheticTrees(DiffContext diffContext, Tree node) {
    if (node == null) return ;
    
    if (((JCTree) node).pos == (-1)) {
        diffContext.syntheticTrees.add(node);
        return ;
    }
    
    if (node.getKind() == Kind.EXPRESSION_STATEMENT) {
        ExpressionTree est = ((ExpressionStatementTree) node).getExpression();

        if (est.getKind() == Kind.METHOD_INVOCATION) {
            ExpressionTree select = ((MethodInvocationTree) est).getMethodSelect();

            if (select.getKind() == Kind.IDENTIFIER && ((IdentifierTree) select).getName().contentEquals("super")) {
                if (getTreeUtilities().isSynthetic(diffContext.origUnit, node)) {
                    diffContext.syntheticTrees.add(node);
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:WorkingCopy.java

示例5: createIdentifiers

import com.sun.source.tree.IdentifierTree; //导入依赖的package包/类
/**
 */
private List<IdentifierTree> createIdentifiers(
                                        TreeMaker maker,
                                        List<VariableTree> variables) {
    List<IdentifierTree> identifiers;
    if (variables == null) {
        identifiers = new ArrayList<IdentifierTree>(1);
        identifiers.add(maker.Identifier("null".toString()));
    } else if (variables.isEmpty()) {
        identifiers = Collections.<IdentifierTree>emptyList();
    } else {
        identifiers = new ArrayList<IdentifierTree>(variables.size());
        for (VariableTree var : variables) {
            identifiers.add(maker.Identifier(var.getName().toString()));
        }
    }
    return identifiers;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:AbstractTestGenerator.java

示例6: visitAssignment

import com.sun.source.tree.IdentifierTree; //导入依赖的package包/类
@Override
public Void visitAssignment(AssignmentTree tree, EnumSet<UseTypes> d) {
    handlePossibleIdentifier(new TreePath(getCurrentPath(), tree.getVariable()), EnumSet.of(UseTypes.WRITE));
    
    Tree expr = tree.getExpression();
    
    if (expr instanceof IdentifierTree) {
        TreePath tp = new TreePath(getCurrentPath(), expr);
        handlePossibleIdentifier(tp, EnumSet.of(UseTypes.READ));
    }
    
    scan(tree.getVariable(), EnumSet.of(UseTypes.WRITE));
    scan(tree.getExpression(), EnumSet.of(UseTypes.READ));
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:SemanticHighlighterBase.java

示例7: visitCompoundAssignment

import com.sun.source.tree.IdentifierTree; //导入依赖的package包/类
@Override
public Void visitCompoundAssignment(CompoundAssignmentTree tree, EnumSet<UseTypes> d) {
    Set<UseTypes> useTypes = EnumSet.of(UseTypes.WRITE);
    
    if (d != null) {
        useTypes.addAll(d);
    }
    
    handlePossibleIdentifier(new TreePath(getCurrentPath(), tree.getVariable()), useTypes);
    
    Tree expr = tree.getExpression();
    
    if (expr instanceof IdentifierTree) {
        TreePath tp = new TreePath(getCurrentPath(), expr);
        handlePossibleIdentifier(tp, EnumSet.of(UseTypes.READ));
    }
    
    scan(tree.getVariable(), EnumSet.of(UseTypes.WRITE));
    scan(tree.getExpression(), EnumSet.of(UseTypes.READ));
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:SemanticHighlighterBase.java

示例8: visitInstanceOf

import com.sun.source.tree.IdentifierTree; //导入依赖的package包/类
@Override
public Void visitInstanceOf(InstanceOfTree tree, EnumSet<UseTypes> d) {
    Tree expr = tree.getExpression();
    
    if (expr instanceof IdentifierTree) {
        handlePossibleIdentifier(new TreePath(getCurrentPath(), expr), EnumSet.of(UseTypes.READ));
    }
    
    TreePath tp = new TreePath(getCurrentPath(), tree.getType());
    handlePossibleIdentifier(tp, EnumSet.of(UseTypes.CLASS_USE));
    
    super.visitInstanceOf(tree, null);
    
    //TODO: should be considered
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:SemanticHighlighterBase.java

示例9: depth

import com.sun.source.tree.IdentifierTree; //导入依赖的package包/类
@SuppressWarnings("unused")
private int depth(ExpressionTree expression) {
  switch (expression.getKind()) {
    case MEMBER_SELECT:
      MemberSelectTree selectTree = (MemberSelectTree) expression;
      return 1 + depth(selectTree.getExpression());
    case METHOD_INVOCATION:
      MethodInvocationTree invTree = (MethodInvocationTree) expression;
      return depth(invTree.getMethodSelect());
    case IDENTIFIER:
      IdentifierTree varTree = (IdentifierTree) expression;
      Symbol symbol = ASTHelpers.getSymbol(varTree);
      return (symbol.getKind().equals(ElementKind.FIELD)) ? 2 : 1;
    default:
      return 0;
  }
}
 
开发者ID:uber,项目名称:NullAway,代码行数:18,代码来源:NullAway.java

示例10: findTokenWithText

import com.sun.source.tree.IdentifierTree; //导入依赖的package包/类
private static Token<JavaTokenId> findTokenWithText(CompilationInfo info, String text, int start, int end) {
    TokenHierarchy<?> th = info.getTokenHierarchy();
    TokenSequence<JavaTokenId> ts = th.tokenSequence(JavaTokenId.language()).subSequence(start, end);
    
    while (ts.moveNext()) {
        Token<JavaTokenId> t = ts.token();
        
        if (t.id() == JavaTokenId.IDENTIFIER) {
            boolean nameMatches;
            
            if (!(nameMatches = text.equals(info.getTreeUtilities().decodeIdentifier(t.text()).toString()))) {
                ExpressionTree expr = info.getTreeUtilities().parseExpression(t.text().toString(), new SourcePositions[1]);
                
                nameMatches = expr.getKind() == Kind.IDENTIFIER && text.contentEquals(((IdentifierTree) expr).getName());
            }
            
            if (nameMatches) {
                return t;
            }
        }
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:Utilities.java

示例11: findIdentifierSpanImpl

import com.sun.source.tree.IdentifierTree; //导入依赖的package包/类
private static Token<JavaTokenId> findIdentifierSpanImpl(CompilationInfo info, IdentifierTree tree, CompilationUnitTree cu, SourcePositions positions) {
    int start = (int)positions.getStartPosition(cu, tree);
    int endPosition = (int)positions.getEndPosition(cu, tree);
    
    if (start == (-1) || endPosition == (-1))
        return null;

    TokenHierarchy<?> th = info.getTokenHierarchy();
    TokenSequence<JavaTokenId> ts = th.tokenSequence(JavaTokenId.language());

    if (ts.move(start) == Integer.MAX_VALUE) {
        return null;
    }

    if (ts.moveNext()) {
        if (ts.offset() >= start) {
            Token<JavaTokenId> t = ts.token();
            return t;
        }
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:Utilities.java

示例12: findValue

import com.sun.source.tree.IdentifierTree; //导入依赖的package包/类
public static ExpressionTree findValue(AnnotationTree m, String name) {
    for (ExpressionTree et : m.getArguments()) {
        if (et.getKind() == Kind.ASSIGNMENT) {
            AssignmentTree at = (AssignmentTree) et;
            String varName = ((IdentifierTree) at.getVariable()).getName().toString();

            if (varName.equals(name)) {
                return at.getExpression();
            }
        }

        if (et instanceof LiteralTree/*XXX*/ && "value".equals(name)) {
            return et;
        }
    }

    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:Utilities.java

示例13: visitIdentifier

import com.sun.source.tree.IdentifierTree; //导入依赖的package包/类
@Override
public Number visitIdentifier(IdentifierTree node, Void p) {
    String name = node.getName().toString();
    Tree newNode = handleIdentifier(name, node);
    
    if (newNode != null) {
        rewrite(node, newNode);
        if (NUMBER_LITERAL_KINDS.contains(newNode.getKind())) {
            return (Number) ((LiteralTree) newNode).getValue();
        }
    }

    Element e = info.getTrees().getElement(getCurrentPath());

    if (e != null && isStaticElement(e) && !inImport) {
        rewrite(node, make.QualIdent(e));
    }

    return super.visitIdentifier(node, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:JavaFixUtilities.java

示例14: visitIdentifier

import com.sun.source.tree.IdentifierTree; //导入依赖的package包/类
@Override
public DocTree visitIdentifier(com.sun.source.doctree.IdentifierTree node, Element p) {
    DocTrees trees = info.getDocTrees();
    Element el = trees.getElement(getCurrentPath());
    if (el != null && el.equals(toFind)) {
        DocSourcePositions sp = trees.getSourcePositions();
        CompilationUnitTree cut = info.getCompilationUnit();
        DocCommentTree docComment = getCurrentPath().getDocComment();
        long start = sp.getStartPosition(cut, docComment, node);
        long end = sp.getEndPosition(cut, docComment, node);
        if(start != Diagnostic.NOPOS && end != Diagnostic.NOPOS) {
            try {
                MutablePositionRegion region = createRegion(doc, (int)start, (int)end);
                usages.add(region);
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
    return super.visitIdentifier(node, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:FindLocalUsagesQuery.java

示例15: dotExpressionUpToArgs

import com.sun.source.tree.IdentifierTree; //导入依赖的package包/类
private void dotExpressionUpToArgs(ExpressionTree expression, Optional<BreakTag> tyargTag) {
    expression = getArrayBase(expression);
    switch (expression.getKind()) {
        case MEMBER_SELECT:
            MemberSelectTree fieldAccess = (MemberSelectTree) expression;
            visit(fieldAccess.getIdentifier());
            break;
        case METHOD_INVOCATION:
            MethodInvocationTree methodInvocation = (MethodInvocationTree) expression;
            if (!methodInvocation.getTypeArguments().isEmpty()) {
                builder.open(plusFour);
                addTypeArguments(methodInvocation.getTypeArguments(), ZERO);
                // TODO(jdd): Should indent the name -4.
                builder.breakOp(Doc.FillMode.UNIFIED, "", ZERO, tyargTag);
                builder.close();
            }
            visit(getMethodName(methodInvocation));
            break;
        case IDENTIFIER:
            visit(((IdentifierTree) expression).getName());
            break;
        default:
            scan(expression, null);
            break;
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:27,代码来源:JavaInputAstVisitor.java


注:本文中的com.sun.source.tree.IdentifierTree类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。