本文整理汇总了Java中org.netbeans.api.java.source.TreePathHandle.resolve方法的典型用法代码示例。如果您正苦于以下问题:Java TreePathHandle.resolve方法的具体用法?Java TreePathHandle.resolve怎么用?Java TreePathHandle.resolve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.java.source.TreePathHandle
的用法示例。
在下文中一共展示了TreePathHandle.resolve方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unwrap
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
private static Collection<? extends TreePath> unwrap(CompilationInfo info, Collection<? extends TreePathHandle> paths) {
if (paths == null) return null;
Collection<TreePath> result = new ArrayList<TreePath>(paths.size());
for (TreePathHandle tph : paths) {
TreePath tp = tph.resolve(info);
if (tp == null) {
LOG.log(Level.FINE, "Cannot resolve TreePathHandle: {0}", tp.toString());
return UNRESOLVABLE_MARKER;
}
result.add(tp);
}
return result;
}
示例2: performRewrite
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) {
WorkingCopy copy = ctx.getWorkingCopy();
TreePath tp = ctx.getPath();
CompilationUnitTree cut = copy.getCompilationUnit();
TreeMaker make = copy.getTreeMaker();
CompilationUnitTree newCut = cut;
for (TreePathHandle tph : tphList) {
TreePath path = tph.resolve(copy);
if ( path != null && path.getLeaf() instanceof ImportTree) {
newCut = make.removeCompUnitImport(newCut, (ImportTree)path.getLeaf());
}
}
copy.rewrite(cut, newCut);
}
示例3: perform
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
@Override
protected boolean perform() {
TreePath replacePath = replacePathHandle.resolve(copy);
if (replacePath == null) {
Logger.getAnonymousLogger().warning(String.format("Attempt to change import for FQN: %s, but the import cannot be resolved in the current context", fqn));
return false;
}
Element el = toImport.resolve(copy);
if (el == null) {
return false;
}
CharSequence elFQN = copy.getElementUtilities().getElementName(el, true);
IdentifierTree id = copy.getTreeMaker().Identifier(elFQN);
copy.rewrite(replacePath.getLeaf(), id);
for (TreePathHandle tph : additionalLocations) {
replacePath = tph.resolve(copy);
if (replacePath == null) {
continue;
}
copy.rewrite(replacePath.getLeaf(), id);
}
return false;
}
示例4: resolveSelection
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
static TreePathHandle resolveSelection(TreePathHandle source, CompilationInfo javac) {
TreePath resolvedPath = source.resolve(javac);
TreePath path = resolvedPath;
Element resolvedElement = source.resolveElement(javac);
while (path != null && resolvedElement == null) {
path = path.getParentPath();
if (path == null) {
return null;
}
resolvedElement = javac.getTrees().getElement(path);
}
return path == resolvedPath ? source : TreePathHandle.create(path, javac);
}
示例5: findSelectedClassMemberDeclaration
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
static TreePathHandle findSelectedClassMemberDeclaration(TreePathHandle path, final CompilationInfo info) {
TreePath resolved = path.resolve(info);
TreePath selected = findSelectedClassMemberDeclaration(resolved ,info);
if (selected == null) {
path = null;
} else if (selected != resolved) {
path = TreePathHandle.create(selected, info);
}
return path;
}
示例6: create
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
@Override
public RefactoringUI create(CompilationInfo info, TreePathHandle[] handles, FileObject[] files, NonRecursiveFolder[] packages) {
if(handles.length < 1 || handles[0] == null) {
return null;
}
TreePathHandle handle = handles[0];
Element el = handle.resolveElement(info);
if (el == null) {
return null;
}
TreePath path = handle.resolve(info);
// Re-create the handle, the old handle can be without a fileobject
if(handle.getFileObject() == null) {
if(path != null) {
handle = TreePathHandle.create(path, info);
} else {
handle = TreePathHandle.create(el, info);
}
}
if(el.getKind() == ElementKind.CLASS) {
if(path != null && path.getParentPath() != null) {
TreePath parentPath = path.getParentPath();
if(parentPath.getLeaf().getKind() == Tree.Kind.NEW_CLASS) {
Element newClass = info.getTrees().getElement(parentPath);
if(newClass != null) {
handle = TreePathHandle.create(parentPath, info);
el = newClass;
}
}
}
}
final List<Pair<Pair<String, Icon>, TreePathHandle>> classes;
if(RefactoringUtils.isExecutableElement(el)) {
ExecutableElement method = (ExecutableElement) el;
classes = new LinkedList<Pair<Pair<String, Icon>, TreePathHandle>>();
Element enclosingElement = method.getEnclosingElement();
String methodDeclaringClass = enclosingElement.getSimpleName().toString();
Icon icon = ElementIcons.getElementIcon(enclosingElement.getKind(), enclosingElement.getModifiers());
classes.add(Pair.of(Pair.of(methodDeclaringClass, icon), handle));
Collection<ExecutableElement> overridens = JavaRefactoringUtils.getOverriddenMethods(method, info);
for (ExecutableElement executableElement : overridens) {
Element enclosingTypeElement = executableElement.getEnclosingElement();
String elName = enclosingTypeElement.getSimpleName().toString();
TreePathHandle tph = TreePathHandle.create(executableElement, info);
Icon typeIcon = ElementIcons.getElementIcon(enclosingTypeElement.getKind(), enclosingTypeElement.getModifiers());
classes.add(Pair.of(Pair.of(elName, typeIcon), tph));
}
} else if (el.getKind() == ElementKind.PACKAGE) { // Remove for #94325
return null;
} else {
classes = null;
}
return new WhereUsedQueryUI(handle, el, classes);
}
示例7: create
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
@Override
public RefactoringUI create(CompilationInfo info, TreePathHandle[] handles, FileObject[] files, NonRecursiveFolder[] packages) {
final boolean b = lookup.lookup(ExplorerContext.class)!=null;
if (packages != null && packages.length == 1) {
return new SafeDeleteUI(packages[0], b);
}
if (handles != null && handles.length == 0 || (files!=null && files.length > 1)) {
return new SafeDeleteUI(files, Arrays.asList(handles), b);
}
if (b && files!=null && files.length == 1) {
return new SafeDeleteUI(files, Arrays.asList(handles), b);
}
if (info == null) {
return new SafeDeleteUI(handles);
}
TreePathHandle selectedElement = handles[0];
Element selected = selectedElement.resolveElement(info);
TreePath selectedTree = selectedElement.resolve(info);
if (selected == null || selectedTree == null) {
return null;
}
if (selected.getKind() == ElementKind.PACKAGE || selected.getEnclosingElement().getKind() == ElementKind.PACKAGE) {
ElementHandle<Element> handle = ElementHandle.create(selected);
FileObject file = SourceUtils.getFile(handle, info.getClasspathInfo());
if (file == null) {
return null;
}
if (file.getName().equals(selected.getSimpleName().toString())) {
return new SafeDeleteUI(new FileObject[]{file}, Collections.singleton(selectedElement), b);
}
}
if(!TreeUtilities.CLASS_TREE_KINDS.contains(selectedTree.getParentPath().getLeaf().getKind())
&& selectedTree.getParentPath().getLeaf().getKind() != Tree.Kind.COMPILATION_UNIT
&& selectedTree.getLeaf().getKind() == Tree.Kind.VARIABLE) {
switch (selectedTree.getParentPath().getLeaf().getKind()) {
case BLOCK:
case METHOD:
break;
default:
return null;
}
}
return new SafeDeleteUI(new TreePathHandle[]{selectedElement});
}
示例8: resolveAndInitialize
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
/**
* Resolves the handles, returns false if some handle does not resolve.
*/
private boolean resolveAndInitialize() {
firstStatement = handle.resolve(copy);
returnType = IntroduceMethodFix.this.returnType.resolve(copy);
if (firstStatement == null || returnType == null) {
return false;
}
parameters = IntroduceHint.resolveVariables(copy, IntroduceMethodFix.this.parameters);
if (IntroduceMethodFix.this.returnAssignTo != null) {
outcomeVariable = (VariableElement) IntroduceMethodFix.this.returnAssignTo.resolveElement(copy);
if (outcomeVariable == null) {
return false;
}
}
if (exits != null && !exits.isEmpty()) {
branchExit = exits.iterator().next().resolve(copy);
if (branchExit == null) {
return false;
}
resolvedExits = new ArrayList<TreePath>(exits.size());
for (TreePathHandle h : exits) {
TreePath resolved = h.resolve(copy);
if (resolved == null) {
return false;
}
if (resolvedExits.isEmpty()) {
branchExit = resolved;
}
resolvedExits.add(resolved);
}
returnSingleValue = exitsFromAllBranches && branchExit.getLeaf().getKind() == Tree.Kind.RETURN && outcomeVariable == null && returnType.getKind() != TypeKind.VOID;
}
// initialization
make = copy.getTreeMaker();
returnTypeTree = make.Type(returnType);
statementPaths = Utilities.getStatementPaths(firstStatement);
statements = IntroduceHint.getStatements(firstStatement);
GeneratorUtilities.get(copy).importComments(firstStatement.getParentPath().getLeaf(), copy.getCompilationUnit());
return true;
}