本文整理汇总了Java中org.netbeans.api.java.source.TreePathHandle.resolveElement方法的典型用法代码示例。如果您正苦于以下问题:Java TreePathHandle.resolveElement方法的具体用法?Java TreePathHandle.resolveElement怎么用?Java TreePathHandle.resolveElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.java.source.TreePathHandle
的用法示例。
在下文中一共展示了TreePathHandle.resolveElement方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: InnerToOuterRefactoringUI
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
/** Creates a new instance of InnerToOuterRefactoringUI
* @param selectedElements Elements the refactoring action was invoked on.
*/
private InnerToOuterRefactoringUI(TreePathHandle sourceType, CompilationInfo info) {
refactoring = new InnerToOuterRefactoring(sourceType);
refactoring.setReferenceName("outer"); //NOI18N
Element temp = sourceType.resolveElement(info);
className = temp.getSimpleName().toString();
disableDeclareFields = temp.getModifiers().contains(Modifier.STATIC) || temp.getKind() !=ElementKind.CLASS;
}
示例2: ReplaceConstructorWithBuilderUI
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
private ReplaceConstructorWithBuilderUI(TreePathHandle constructor, CompilationInfo info) {
this.refactoring = new ReplaceConstructorWithBuilderRefactoring(constructor);
ExecutableElement contructorElement = (ExecutableElement) constructor.resolveElement(info);
this.name = contructorElement.getSimpleName().toString();
MethodTree constTree = (MethodTree) constructor.resolve(info).getLeaf();
paramaterNames = new ArrayList<String>();
parameterTypes = new ArrayList<String>();
parameterTypeVars = new ArrayList<Boolean>();
boolean varargs = contructorElement.isVarArgs();
List<? extends VariableElement> parameterElements = contructorElement.getParameters();
List<? extends VariableTree> parameters = constTree.getParameters();
for (int i = 0; i < parameters.size(); i++) {
VariableTree var = parameters.get(i);
paramaterNames.add(var.getName().toString());
String type = contructorElement.getParameters().get(i).asType().toString();
if(varargs && i+1 == parameters.size()) {
if(var.getType().getKind() == Tree.Kind.ARRAY_TYPE) {
ArrayTypeTree att = (ArrayTypeTree) var.getType();
type = att.getType().toString();
type += "..."; //NOI18N
}
}
parameterTypes.add(type);
parameterTypeVars.add(parameterElements.get(i).asType().getKind() == TypeKind.TYPEVAR);
}
TypeElement typeEl = (TypeElement) contructorElement.getEnclosingElement();
if(typeEl.getNestingKind() != NestingKind.TOP_LEVEL) {
PackageElement packageOf = info.getElements().getPackageOf(typeEl);
builderFQN = packageOf.toString() + "." + typeEl.getSimpleName().toString();
} else {
builderFQN = typeEl.getQualifiedName().toString();
}
buildMethodName = "create" + typeEl.getSimpleName();
}
示例3: PushDownRefactoringUI
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
/** Creates a new instance of PushDownRefactoringUI
* @param selectedElements Elements the refactoring action was invoked on.
*/
private PushDownRefactoringUI(TreePathHandle selectedElements, CompilationInfo info) {
initialMembers = new HashSet();
TreePathHandle selectedPath = resolveSelection(selectedElements, info);
if (selectedPath != null) {
Element selected = selectedPath.resolveElement(info);
initialMembers.add(MemberInfo.create(selected, info));
// compute source type and members that should be pre-selected from the
// set of elements the action was invoked on
// create an instance of push down refactoring object
if (!(selected instanceof TypeElement)) {
selected = info.getElementUtilities().enclosingTypeElement(selected);
}
TreePath tp = info.getTrees().getPath(selected);
if(tp != null) {
TreePathHandle sourceType = TreePathHandle.create(tp, info);
description = ElementHeaders.getHeader(tp, info, ElementHeaders.NAME);
refactoring = new PushDownRefactoring(sourceType);
refactoring.getContext().add(RefactoringUtils.getClasspathInfoFor(sourceType));
} else {
// put the unresolvable selection to refactoring,
// user notification is provided by PushDownRefactoringPlugin.preCheck
refactoring = new PushDownRefactoring(selectedElements);
}
} else {
// put the unresolvable selection to refactoring,
// user notification is provided by PushDownRefactoringPlugin.preCheck
refactoring = new PushDownRefactoring(selectedElements);
}
}
示例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: PullUpRefactoringUI
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
/** Creates a new instance of PullUpRefactoringUI
* @param selectedElements Elements the refactoring action was invoked on.
*/
public PullUpRefactoringUI(TreePathHandle selectedElements, CompilationInfo info) {
initialMembers = new HashSet();
TreePathHandle selectedPath = PushDownRefactoringUI.resolveSelection(selectedElements, info);
if (selectedPath != null) {
Element selected = selectedPath.resolveElement(info);
sourceKind = selected.getKind();
initialMembers.add(MemberInfo.create(selected, info));
// compute source type and members that should be pre-selected from the
// set of elements the action was invoked on
// create an instance of pull up refactoring object
if (!(selected instanceof TypeElement)) {
selected = info.getElementUtilities().enclosingTypeElement(selected);
}
TreePath tp = info.getTrees().getPath(selected);
TreePathHandle sourceType = TreePathHandle.create(tp, info);
description = ElementHeaders.getHeader(tp, info, ElementHeaders.NAME);
refactoring = new PullUpRefactoring(sourceType);
refactoring.getContext().add(info.getClasspathInfo());
} else {
// put the unresolvable selection to refactoring,
// user notification is provided by PullUpRefactoringPlugin.preCheck
refactoring = new PullUpRefactoring(selectedElements);
}
}
示例6: invokeEqualsHashCode
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
public static void invokeEqualsHashCode(final TreePathHandle handle, final JTextComponent component) {
JavaSource js = JavaSource.forDocument(component.getDocument());
if (js != null) {
class FillIn implements Task<CompilationController> {
EqualsHashCodeGenerator gen;
@Override
public void run(CompilationController cc) throws Exception {
cc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
Element e = handle.resolveElement(cc);
gen = createEqualsHashCodeGenerator(component, cc, e);
}
public void invoke() {
if (gen != null) {
gen.invoke();
}
}
}
FillIn fillIn = new FillIn();
try {
js.runUserActionTask(fillIn, true);
fillIn.invoke();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
示例7: 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);
}
示例8: create
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
public static IntroduceLocalExtensionUI create(TreePathHandle type, CompilationInfo javac) {
TypeElement typeElement = (TypeElement) type.resolveElement(javac);
Icon icon = ElementIcons.getElementIcon(typeElement.getKind(), typeElement.getModifiers());
String startPackage = getPackageName(type.getFileObject().getParent());
return new IntroduceLocalExtensionUI(type, typeElement.getSimpleName().toString(), icon, typeElement.getSimpleName().toString(), startPackage);
}
示例9: 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});
}