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


Java ImportTree.isStatic方法代码示例

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


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

示例1: visitImport

import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
@Override
public Void visitImport(ImportTree node, Stack<Tree> p) {
    if (node.isStatic() && toFind.getModifiers().contains(Modifier.STATIC)) {
        Tree qualIdent = node.getQualifiedIdentifier();
        if (qualIdent.getKind() == Kind.MEMBER_SELECT) {
            MemberSelectTree mst = (MemberSelectTree) qualIdent;
            if (toFind.getSimpleName().contentEquals(mst.getIdentifier())) {
                Element el = info.getTrees().getElement(new TreePath(getCurrentPath(), mst.getExpression()));
                if (el != null && el.equals(toFind.getEnclosingElement())) {
                    Token<JavaTokenId> t = Utilities.getToken(info, doc, new TreePath(getCurrentPath(), mst));
                    if (t != null)
                        usages.add(t);
                }
            }
        }
    }
    return super.visitImport(node, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:FindLocalUsagesQuery.java

示例2: handleUnresolvableImports

import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
private void handleUnresolvableImports(Element decl,
        boolean methodInvocation, boolean removeStarImports) {
    Name simpleName = decl.getSimpleName();
    if (simpleName != null) {
        Collection<ImportTree> imps = simpleName2UnresolvableImports.get(simpleName.toString());

        if (imps != null) {
            for (ImportTree imp : imps) {
                if (!methodInvocation || imp.isStatic()) {
                    import2Highlight.remove(imp);
                }
            }
        } else {
            if (removeStarImports) {
                //TODO: explain
                for (ImportTree unresolvable : unresolvablePackageImports) {
                    if (!methodInvocation || unresolvable.isStatic()) {
                        import2Highlight.remove(unresolvable);
                    }
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:UnusedImports.java

示例3: visitImport

import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
@Override
public Void visitImport(ImportTree node, Void p) {
    if (node.isStatic() && toFind.getModifiers().contains(Modifier.STATIC)) {
        Tree qualIdent = node.getQualifiedIdentifier();
        if (qualIdent.getKind() == Kind.MEMBER_SELECT) {
            MemberSelectTree mst = (MemberSelectTree) qualIdent;
            if (toFind.getSimpleName().contentEquals(mst.getIdentifier())) {
                Element el = info.getTrees().getElement(new TreePath(getCurrentPath(), mst.getExpression()));
                if (el != null && el.equals(toFind.getEnclosingElement())) {
                    try {
                        int[] span = treeUtils.findNameSpan(mst);
                        if(span != null) {
                            MutablePositionRegion region = createRegion(doc, span[0], span[1]);
                            usages.add(region);
                        }
                    } catch (BadLocationException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
            }
        }
    }
    return super.visitImport(node, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:FindLocalUsagesQuery.java

示例4: exlucded

import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
@Hint(displayName = "#DN_Imports_EXCLUDED", description = "#DESC_Imports_EXCLUDED", category="imports", id="Imports_EXCLUDED", options=Options.QUERY)
@TriggerTreeKind(Kind.IMPORT)
public static ErrorDescription exlucded(HintContext ctx) throws IOException {
    ImportTree it = (ImportTree) ctx.getPath().getLeaf();

    if (it.isStatic() || !(it.getQualifiedIdentifier() instanceof MemberSelectTree)) {
        return null; // XXX
    }

    MemberSelectTree ms = (MemberSelectTree) it.getQualifiedIdentifier();
    String pkg = ms.getExpression().toString();
    String klass = ms.getIdentifier().toString();
    String exp = pkg + "." + (!klass.equals("*") ? klass : ""); //NOI18N
    if (Utilities.isExcluded(exp)) {
        return ErrorDescriptionFactory.forTree(ctx, ctx.getPath(), NbBundle.getMessage(Imports.class, "DN_Imports_EXCLUDED"));
    }

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

示例5: tryCreate

import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
/**
 * Returns a {@link StaticImports} if the given import is a static single-type import. Returns
 * {@code null} otherwise, e.g. because the import is non-static, or an on-demand import, or
 * statically imports a field or method.
 */
@Nullable
public static StaticImportInfo tryCreate(ImportTree tree, VisitorState state) {
  if (!tree.isStatic()) {
    return null;
  }
  if (!(tree.getQualifiedIdentifier() instanceof JCTree.JCFieldAccess)) {
    return null;
  }
  JCTree.JCFieldAccess access = (JCTree.JCFieldAccess) tree.getQualifiedIdentifier();
  String importedName = access.toString();
  Type result = state.getTypeFromString(importedName);
  if (result == null) {
    // If the full imported name isn't a type, it might be a field or
    // method:
    return tryAsStaticMember(access, state);
  }
  String canonicalName = state.getTypes().erasure(result).toString();
  if (canonicalName == null) {
    return null;
  }
  return StaticImportInfo.create(importedName, canonicalName);
}
 
开发者ID:google,项目名称:error-prone,代码行数:28,代码来源:StaticImports.java

示例6: starImport

import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
@Hint(displayName = "#DN_Imports_STAR", description = "#DESC_Imports_STAR", category="imports", id="Imports_STAR", enabled=false, options=Options.QUERY, suppressWarnings={"", "OnDemandImport"})
@TriggerTreeKind(Kind.IMPORT)
public static ErrorDescription starImport(HintContext ctx) {
    ImportTree it = (ImportTree) ctx.getPath().getLeaf();

    if (it.isStatic() || !(it.getQualifiedIdentifier() instanceof MemberSelectTree)) {
        return null; // XXX
    }

    MemberSelectTree ms = (MemberSelectTree) it.getQualifiedIdentifier();

    if (!"*".equals(ms.getIdentifier().toString())) return null;

    return ErrorDescriptionFactory.forTree(ctx, ctx.getPath(), NbBundle.getMessage(Imports.class, "DN_Imports_STAR"));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:Imports.java

示例7: getAllImportsOfKind

import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
private static List<TreePathHandle> getAllImportsOfKind(CompilationInfo ci, ImportHintKind kind) {
    //allow only default and samepackage
    assert (kind == ImportHintKind.DEFAULT_PACKAGE || kind == ImportHintKind.SAME_PACKAGE);

    CompilationUnitTree cut = ci.getCompilationUnit();
    TreePath topLevel = new TreePath(cut);
    List<TreePathHandle> result = new ArrayList<TreePathHandle>(3);

    List<? extends ImportTree> imports = cut.getImports();
    for (ImportTree it : imports) {
        if (it.isStatic()) {
            continue; // XXX
        }
        if (it.getQualifiedIdentifier() instanceof MemberSelectTree) {
            MemberSelectTree ms = (MemberSelectTree) it.getQualifiedIdentifier();
            if (kind == ImportHintKind.DEFAULT_PACKAGE) {
                if (ms.getExpression().toString().equals(DEFAULT_PACKAGE)) {
                    result.add(TreePathHandle.create(new TreePath(topLevel, it), ci));
                }
            }
            if (kind == ImportHintKind.SAME_PACKAGE) {
                ExpressionTree packageName = cut.getPackageName();
                if (packageName != null &&
                    ms.getExpression().toString().equals(packageName.toString())) {
                    result.add(TreePathHandle.create(new TreePath(topLevel, it), ci));
                }
            }
        }
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:Imports.java

示例8: hasStaticImportSimpleNameClash

import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
/**
 * @param info
 * @param simpleName of static method.
 * @return true if a static import exists with the same simple name.
 * Caveat, expect false positives on protected and default visibility methods from wildcard static imports.
 */
private static boolean hasStaticImportSimpleNameClash(CompilationInfo info, String simpleName) {
    for (ImportTree i : info.getCompilationUnit().getImports()) {
        if (!i.isStatic()) {
            continue;
        }
        String q = i.getQualifiedIdentifier().toString();
        if (q.endsWith(".*")) { //NOI18N
            TypeElement ie = info.getElements().getTypeElement(q.substring(0, q.length() - 2));
            if (ie == null) {
                continue;
            }
            for (Element enclosed : ie.getEnclosedElements()) {
                Set<Modifier> modifiers = enclosed.getModifiers();
                if (enclosed.getKind() != ElementKind.METHOD || !modifiers.contains(Modifier.STATIC) || modifiers.contains(Modifier.PRIVATE)) {
                    continue;
                }
                String sn1 = enclosed.getSimpleName().toString();
                if (simpleName.equals(sn1)) {
                    return true;
                }
            }
        } else {
            int endIndex = q.lastIndexOf("."); //NOI18N
            if (endIndex == -1 || endIndex >= q.length() - 1) {
                continue;
            }
            if (q.substring(endIndex).equals(simpleName)) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:StaticImport.java

示例9: isStaticallyImported

import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
private static boolean isStaticallyImported(CompilationInfo info, String fqn) {
    for (ImportTree i : info.getCompilationUnit().getImports()) {
        if (!i.isStatic()) {
            continue;
        }
        String q = i.getQualifiedIdentifier().toString();
        if (q.endsWith(".*") && fqn.startsWith(q.substring(0, q.length() - 1))) { //NOI18N
            return true;
        }
        if (q.equals(fqn)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:StaticImport.java

示例10: visitImport

import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
@Override
public Void visitImport(ImportTree node, Void unused) {
    sync(node);
    token("import");
    builder.space();
    if (node.isStatic()) {
        token("static");
        builder.space();
    }
    visitName(node.getQualifiedIdentifier());
    token(";");
    // TODO(cushon): remove this if https://bugs.openjdk.java.net/browse/JDK-8027682 is fixed
    dropEmptyDeclarations();
    return null;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:16,代码来源:JavaInputAstVisitor.java

示例11: getImportedSymbols

import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
private static ImmutableSet<Symbol> getImportedSymbols(
    ImportTree importTree, VisitorState state) {
  if (importTree.isStatic()) {
    StaticImportInfo staticImportInfo = StaticImports.tryCreate(importTree, state);
    return staticImportInfo == null ? ImmutableSet.<Symbol>of() : staticImportInfo.members();
  } else {
    @Nullable Symbol importedSymbol = getSymbol(importTree.getQualifiedIdentifier());
    return importedSymbol == null ? ImmutableSet.<Symbol>of() : ImmutableSet.of(importedSymbol);
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:11,代码来源:RemoveUnusedImports.java

示例12: getImportNames

import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
/**
 * Returns the import statements in effect in the containing
 * compilation unit of {@code element}.
 */
@Requires({
  "processingEnv != null",
  "element != null"
})
@Ensures("result != null")
public static Set<String> getImportNames(ProcessingEnvironment processingEnv,
    Element element) {
  Trees treeUtils = Trees.instance(processingEnv);
  if (treeUtils == null) {
    return Collections.emptySet();
  }

  TreePath path = treeUtils.getPath(element);
  if (path == null) {
    return Collections.emptySet();
  }

  CompilationUnitTree unitTree = path.getCompilationUnit();

  HashSet<String> importNames = new HashSet<String>();
  for (ImportTree importTree : unitTree.getImports()) {
    StringBuilder buffer = new StringBuilder();
    if (importTree.isStatic()) {
      buffer.append("static ");
    }
    /* TODO(lenh): Roll our own toString()? */
    buffer.append(importTree.getQualifiedIdentifier().toString());
    importNames.add(buffer.toString());
  }

  return importNames;
}
 
开发者ID:konvergeio,项目名称:cofoja,代码行数:37,代码来源:JavacUtils.java

示例13: handleImport

import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
private static void handleImport(Trees trees, ImportsTracker imports, TreePath importTreePath) {
  ImportTree importTree = (ImportTree) importTreePath.getLeaf();
  MemberSelectTree importedExpression = (MemberSelectTree) importTree.getQualifiedIdentifier();
  TreePath importedExpressionPath = new TreePath(importTreePath, importedExpression);
  Name simpleName = importedExpression.getIdentifier();
  boolean isStarImport = simpleName.contentEquals("*");

  if (!isStarImport && !importTree.isStatic()) {
    TypeElement importedType = (TypeElement) trees.getElement(importedExpressionPath);
    imports.importType(importedType, importedExpressionPath);
  } else {
    ExpressionTree containingElementExpression = importedExpression.getExpression();
    TreePath containingElementExpressionPath =
        new TreePath(importedExpressionPath, containingElementExpression);
    QualifiedNameable containingElement =
        (QualifiedNameable) trees.getElement(containingElementExpressionPath);

    if (importTree.isStatic()) {
      TypeElement containingType = (TypeElement) containingElement;
      if (isStarImport) {
        imports.importStaticMembers((TypeElement) containingElement);
      } else {
        imports.importStatic(containingType, simpleName);
      }
    } else {
      // Normal star import
      imports.importMembers(containingElement, containingElementExpressionPath);
    }
  }
}
 
开发者ID:facebook,项目名称:buck,代码行数:31,代码来源:ImportsTrackerTestHelper.java

示例14: addImport

import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
private void addImport(ImportTree imp) {
    String fqn = getFQN(imp);

    if (!imp.isStatic()) {
        Element resolve = overlay.resolve(model, elements, fqn);

        if (resolve != null) {
            imported.add(resolve);
            simpleNames2Elements.put(resolve.getSimpleName().toString(), resolve);
        } else {
            //.*?:
            if (fqn.endsWith(".*")) {
                fqn = fqn.substring(0, fqn.length() - 2);

                List<TypeElement> classes = Collections.<TypeElement>emptyList();
                Element clazz = overlay.resolve(model, elements, fqn);

                if (clazz != null) {
                    classes = ElementFilter.typesIn(clazz.getEnclosedElements());
                }

                for (TypeElement te : classes) {
                    imported.add(te);
                    simpleNames2Elements.put(te.getSimpleName().toString(), te);
                }
            } else {
                //cannot resolve - the imports will probably not work correctly...
            }
        }
    } else {
        int dot = fqn.lastIndexOf('.');

        if (dot != (-1)) {
            String className = fqn.substring(0, dot);
            String memberName = fqn.substring(dot + 1);
            boolean isStarred = "*".equals(memberName);
            Element resolved = overlay.resolve(model, elements, className);

            if (resolved != null) {
                boolean added = false;
                for (Element e : resolved.getEnclosedElements()) {
                    if (!e.getModifiers().contains(Modifier.STATIC)) {
                        continue;
                    }
                    if (isStarred || memberName.contains(e.getSimpleName().toString())) {
                        imported.add(e);
                        simpleNames2Elements.put(e.getSimpleName().toString(), e);
                    }
                }
            } else {
                //cannot resolve - the imports will probably not work correctly...
            }
        } else {
            //no dot?
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:58,代码来源:ImportAnalysis2.java

示例15: performRewrite

import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
@Override protected void performRewrite(JavaFix.TransformationContext ctx) throws Exception {
    WorkingCopy wc = ctx.getWorkingCopy();
    TreePath treePath = ctx.getPath();
            TreeMaker make = wc.getTreeMaker();
            if (treePath.getLeaf().getKind() == Kind.METHOD_INVOCATION) {
                MethodInvocationTree mit = (MethodInvocationTree) treePath.getLeaf();
                CompilationUnitTree cut = wc.getCompilationUnit();
                boolean imported = false;
                String importBundleStar = cut.getPackageName() + ".Bundle.*";
                for (ImportTree it : cut.getImports()) {
                    if (it.isStatic() && it.getQualifiedIdentifier().toString().equals(importBundleStar)) {
                        imported = true;
                        break;
                    }
                }
                if (!imported) {
                    wc.rewrite(cut, make.addCompUnitImport(cut, make.Import(make.Identifier(importBundleStar), true)));
                }
                List<? extends ExpressionTree> args = mit.getArguments();
                List<? extends ExpressionTree> params;
                if (args.size() == 3 && args.get(2).getKind() == Kind.NEW_ARRAY) {
                    params = ((NewArrayTree) args.get(2)).getInitializers();
                } else {
                    params = args.subList(2, args.size());
                }
                wc.rewrite(mit, make.MethodInvocation(Collections.<ExpressionTree>emptyList(), make.Identifier(toIdentifier(key)), params));
            } // else annotation value, nothing to change
            if (!isAlreadyRegistered) {
                EditableProperties ep = new EditableProperties(true);
                InputStream is = ctx.getResourceContent(bundleProperties);
                try {
                    ep.load(is);
                } finally {
                    is.close();
                }
                List<ExpressionTree> lines = new ArrayList<ExpressionTree>();
                for (String comment : ep.getComment(key)) {
                    lines.add(make.Literal(comment));
                }
                lines.add(make.Literal(key + '=' + ep.remove(key)));
                TypeElement nbBundleMessages = wc.getElements().getTypeElement("org.openide.util.NbBundle.Messages");
                if (nbBundleMessages == null) {
                    throw new IllegalArgumentException("cannot resolve org.openide.util.NbBundle.Messages");
                }
                GeneratorUtilities gu = GeneratorUtilities.get(wc);
                Tree enclosing = findEnclosingElement(wc, treePath);
                Tree modifiers;
                Tree nueModifiers;
                ExpressionTree[] linesA = lines.toArray(new ExpressionTree[lines.size()]);
                switch (enclosing.getKind()) {
                case METHOD:
                    modifiers = wc.resolveRewriteTarget(((MethodTree) enclosing).getModifiers());
                    nueModifiers = gu.appendToAnnotationValue((ModifiersTree) modifiers, nbBundleMessages, "value", linesA);
                    break;
                case VARIABLE:
                    modifiers = wc.resolveRewriteTarget(((VariableTree) enclosing).getModifiers());
                    nueModifiers = gu.appendToAnnotationValue((ModifiersTree) modifiers, nbBundleMessages, "value", linesA);
                    break;
                case COMPILATION_UNIT:
                    modifiers = wc.resolveRewriteTarget(enclosing);
                    nueModifiers = gu.appendToAnnotationValue((CompilationUnitTree) modifiers, nbBundleMessages, "value", linesA);
                    break;
                default:
                    modifiers = wc.resolveRewriteTarget(((ClassTree) enclosing).getModifiers());
                    nueModifiers = gu.appendToAnnotationValue((ModifiersTree) modifiers, nbBundleMessages, "value", linesA);
                }
                wc.rewrite(modifiers, nueModifiers);
            // XXX remove NbBundle import if now unused
            OutputStream os = ctx.getResourceOutput(bundleProperties);
            try {
                ep.store(os);
            } finally {
                os.close();
            }
        }
    // XXX after JavaFix rewrite, Savable.save (on DataObject.find(src)) no longer works (JG13 again)
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:78,代码来源:UseNbBundleMessages.java


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