本文整理汇总了Java中com.sun.source.tree.ImportTree.getQualifiedIdentifier方法的典型用法代码示例。如果您正苦于以下问题:Java ImportTree.getQualifiedIdentifier方法的具体用法?Java ImportTree.getQualifiedIdentifier怎么用?Java ImportTree.getQualifiedIdentifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.ImportTree
的用法示例。
在下文中一共展示了ImportTree.getQualifiedIdentifier方法的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);
}
示例2: 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);
}
示例3: 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;
}
示例4: 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);
}
示例5: getWildcardImports
import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
/** Collect all on demand imports. */
private static ImmutableList<ImportTree> getWildcardImports(List<? extends ImportTree> imports) {
ImmutableList.Builder<ImportTree> result = ImmutableList.builder();
for (ImportTree tree : imports) {
// javac represents on-demand imports as a member select where the selected name is '*'.
Tree ident = tree.getQualifiedIdentifier();
if (!(ident instanceof MemberSelectTree)) {
continue;
}
MemberSelectTree select = (MemberSelectTree) ident;
if (select.getIdentifier().contentEquals("*")) {
result.add(tree);
}
}
return result.build();
}
示例6: isStar
import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
private boolean isStar(ImportTree tree) {
Tree qualIdent = tree.getQualifiedIdentifier();
if (qualIdent == null || qualIdent.getKind() == Kind.IDENTIFIER) {
return false;
}
return ((MemberSelectTree) qualIdent).getIdentifier().contentEquals("*");
}
示例7: computeImport
import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
private static List<? extends TypeMirror> computeImport(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
ImportTree tree = (ImportTree) parent.getLeaf();
if (tree.getQualifiedIdentifier() == error) {
types.add(ElementKind.ANNOTATION_TYPE);
types.add(ElementKind.CLASS);
types.add(ElementKind.ENUM);
types.add(ElementKind.INTERFACE);
return Collections.singletonList(info.getElements().getTypeElement("java.lang.Object").asType());
}
return null;
}
示例8: 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"));
}
示例9: 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;
}
示例10: computeImport
import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
private static List<? extends TypeMirror> computeImport(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
ImportTree tree = (ImportTree) parent.getLeaf();
if (tree.getQualifiedIdentifier() == error) {
types.add(ElementKind.ANNOTATION_TYPE);
types.add(ElementKind.CLASS);
types.add(ElementKind.ENUM);
types.add(ElementKind.INTERFACE);
return typeMirrorCollectionOrNull(info, "java.lang.Object");
}
return null;
}
示例11: 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);
}
}
}
示例12: getImportNames
import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
private List<String> getImportNames() {
List<String> importNames = new LinkedList<String>();
for (ImportTree imp : imports) {
Tree identifier = imp.getQualifiedIdentifier();
importNames.add(identifier.toString());
}
return importNames;
}
示例13: isStarImport
import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
private boolean isStarImport(ImportTree imp) {
Tree qualIdent = imp.getQualifiedIdentifier();
boolean isStar = qualIdent.getKind() == Tree.Kind.MEMBER_SELECT && ((MemberSelectTree)qualIdent).getIdentifier().contentEquals("*"); // NOI18N
return isStar;
}
示例14: testRenameIdentifier
import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
public void testRenameIdentifier() throws Exception {
testFile = new File(getWorkDir(), "Test.java");
TestUtilities.copyStringToFile(testFile,
"import java.util.List;\n" +
"import java.util.ArrayList;\n" +
"\n" +
"import java.util.Collections; // test\n" +
"/** test */\n" +
"public class Test {\n" +
" public void taragui() {\n" +
" }\n" +
"}\n");
String golden =
"import java.util.List;\n" +
"import java.util.ArrayList;\n" +
"\n" +
"import java.util.Jitko; // test\n" +
"/** test */\n" +
"public class Test {\n" +
" public void taragui() {\n" +
" }\n" +
"}\n";
JavaSource src = getJavaSource(testFile);
Task<WorkingCopy> task = new Task<WorkingCopy>() {
public void run(WorkingCopy workingCopy) throws IOException {
workingCopy.toPhase(Phase.RESOLVED);
TreeMaker make = workingCopy.getTreeMaker();
CompilationUnitTree cut = workingCopy.getCompilationUnit();
ImportTree dovoz = cut.getImports().get(2);
MemberSelectTree mst = (MemberSelectTree) dovoz.getQualifiedIdentifier();
workingCopy.rewrite(mst, make.setLabel(mst, "Jitko"));
}
};
src.runModificationTask(task).commit();
String res = TestUtilities.copyFileToString(testFile);
System.err.println(res);
assertEquals(golden, res);
}
示例15: visitImport
import com.sun.source.tree.ImportTree; //导入方法依赖的package包/类
@Override
public Void visitImport(ImportTree tree, Void d) {
if (parseErrorInImport(tree)) {
return super.visitImport(tree, null);
}
if (tree.getQualifiedIdentifier() == null ||
tree.getQualifiedIdentifier().getKind() != Tree.Kind.MEMBER_SELECT) {
return super.visitImport(tree, null);
}
MemberSelectTree qualIdent = (MemberSelectTree) tree.getQualifiedIdentifier();
boolean assign = false;
// static imports and star imports only use the qualifier part
boolean star = isStar(tree);
TreePath tp = tree.isStatic() || star ?
new TreePath(new TreePath(getCurrentPath(), qualIdent), qualIdent.getExpression()) :
new TreePath(getCurrentPath(), tree.getQualifiedIdentifier());
Element decl = info.getTrees().getElement(tp);
import2Highlight.put(tree, getCurrentPath());
if (decl != null && !isErroneous(decl)) {
if (!tree.isStatic()) {
if (star) {
List<TypeElement> types = ElementFilter.typesIn(decl.getEnclosedElements());
for (TypeElement te : types) {
assign = true;
if (!element2Import.containsKey(te)) {
element2Import.put(te, tree);
}
}
} else {
element2Import.put(decl, tree);
importedBySingleImport.add(decl);
}
} else if (decl.getKind().isClass() || decl.getKind().isInterface()) {
Name simpleName = star ? null : qualIdent.getIdentifier();
for (Element e : info.getElements().getAllMembers((TypeElement) decl)) {
if (!e.getModifiers().contains(Modifier.STATIC)) continue;
if (simpleName != null && !e.getSimpleName().equals(simpleName)) {
continue;
}
if (!star || !element2Import.containsKey(e)) {
element2Import.put(e, tree);
}
assign = true;
}
}
}
if (!assign) {
if (!tree.isStatic() && star) {
unresolvablePackageImports.add(tree);
} else {
addUnresolvableImport(qualIdent.getIdentifier(), tree);
}
}
super.visitImport(tree, null);
return null;
}