本文整理汇总了Java中org.netbeans.api.java.source.TreePathHandle.getFileObject方法的典型用法代码示例。如果您正苦于以下问题:Java TreePathHandle.getFileObject方法的具体用法?Java TreePathHandle.getFileObject怎么用?Java TreePathHandle.getFileObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.java.source.TreePathHandle
的用法示例。
在下文中一共展示了TreePathHandle.getFileObject方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
private void initialize() {
final TreePathHandle sourceType = refactoring.getSourceType();
if (sourceType == null) {
return;
}
FileObject fo = sourceType.getFileObject();
JavaSource js = JavaSource.forFileObject(fo);
try {
js.runUserActionTask(new CancellableTask<CompilationController>() {
@Override
public void cancel() {
}
@Override
public void run(CompilationController javac) throws Exception {
javac.toPhase(JavaSource.Phase.RESOLVED);
initializeInTransaction(javac, sourceType);
}
}, true);
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
示例2: canFindUsages
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
@Override
public boolean canFindUsages(Lookup lookup) {
Collection<? extends Node> nodes = new HashSet<Node>(lookup.lookupAll(Node.class));
if (nodes.size() != 1) {
return false;
}
Node n = nodes.iterator().next();
TreePathHandle handle;
if ((handle = n.getLookup().lookup(TreePathHandle.class)) != null && handle.getFileObject() != null) {
return true;
}
DataObject dob = n.getLookup().lookup(DataObject.class);
if ((dob!=null) && RefactoringUtils.isJavaFile(dob.getPrimaryFile()) && !"package-info".equals(dob.getName())) { //NOI18N
return true;
}
return false;
}
示例3: prepareMethodRefactoring
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
private Problem prepareMethodRefactoring(RefactoringElementsBag refactoringElements, final TreePathHandle treePathHandle) {
FileObject fo = treePathHandle.getFileObject();
try {
RenamedProperty prop = null;
JavaSource js = JavaSource.forFileObject(fo);
if (js != null) {
prop = SpringRefactorings.getRenamedProperty(treePathHandle, js, refactoring.getNewName());
}
SpringScope scope = SpringScope.getSpringScope(fo);
if (scope == null) {
return null;
}
if (prop != null) {
String newName = prop.getNewName();
String oldName = prop.getOldName();
if (newName != null && oldName != null) {
Modifications mods = new Modifications();
for (Occurrence occurrence : Occurrences.getPropertyOccurrences(prop, js, scope)) {
refactoringElements.add(refactoring,
SpringRefactoringElement.createPropertyRefModification(occurrence, mods, prop.getOldName(), prop.getNewName()));
}
refactoringElements.registerTransaction(new RefactoringCommit(Collections.singleton(mods)));
}
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
return null;
}
示例4: prepareClassRefactoring
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
private Problem prepareClassRefactoring(RefactoringElementsBag refactoringElementsBag, final TreePathHandle treePathHandle) {
FileObject fo = treePathHandle.getFileObject();
SpringScope scope = SpringScope.getSpringScope(fo);
if (scope == null) {
return null;
}
try {
JavaSource source = JavaSource.forFileObject(fo);
// #253033
if (source == null) {
return null;
}
final String[] className = new String[] { null };
source.runUserActionTask(new Task<CompilationController>() {
public void run(CompilationController compilationController) throws Exception {
compilationController.toPhase(JavaSource.Phase.RESOLVED);
TypeElement type = (TypeElement) treePathHandle.resolveElement(compilationController);
if (type != null) {
className[0] = ElementUtilities.getBinaryName(type);
}
}
}, true);
if (className[0] != null) {
for (Occurrences.Occurrence item : Occurrences.getJavaClassOccurrences(className[0], scope)) {
refactoringElementsBag.add(refactoring, SpringRefactoringElement.create(item));
}
}
} catch (IOException e) {
Exceptions.printStackTrace(e);
}
return null;
}
示例5: prepareMethodRefactoring
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
private Problem prepareMethodRefactoring(RefactoringElementsBag refactoringElements, final TreePathHandle treePathHandle) {
FileObject fo = treePathHandle.getFileObject();
try {
RenamedProperty prop = null;
JavaSource js = JavaSource.forFileObject(fo);
if (js != null) {
prop = SpringRefactorings.getRenamedProperty(treePathHandle, js, null);
}
SpringScope scope = SpringScope.getSpringScope(fo);
if (scope == null) {
return null;
}
if (prop != null) {
String oldName = prop.getOldName();
if (oldName != null) {
for (Occurrence occurrence : Occurrences.getPropertyOccurrences(prop, js, scope)) {
refactoringElements.add(refactoring, SpringRefactoringElement.create(occurrence));
}
}
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
return null;
}
示例6: createInstance
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
@Override public RefactoringPlugin createInstance(AbstractRefactoring refactoring) {
if (!(refactoring instanceof WhereUsedQuery)) {
return null;
}
TreePathHandle handle = refactoring.getRefactoringSource().lookup(TreePathHandle.class);
if (handle == null) {
return null;
}
Tree.Kind kind = handle.getKind();
if (TreeUtilities.CLASS_TREE_KINDS.contains(kind) || kind == Tree.Kind.IDENTIFIER || kind == Tree.Kind.MEMBER_SELECT) {
FileObject fo = handle.getFileObject();
Project p = FileOwnerQuery.getOwner(fo);
if (p == null) {
FileObject root = FileUtil.getArchiveFile(fo);
if (root != null && root.getNameExt().endsWith("-sources.jar")) {
LOG.log(Level.FINE, "considering usages from {0} in a Maven binary artifact", fo.toURI());
return new MavenRefactoringPlugin((WhereUsedQuery) refactoring, handle);
} else {
LOG.log(Level.FINE, "binary file of no particular interest: {0}", fo.toURI());
return null;
}
} else if (p.getLookup().lookup(NbMavenProject.class) != null) {
LOG.log(Level.FINE, "considering usages from {0} in a Maven project", fo.toURI());
return new MavenRefactoringPlugin((WhereUsedQuery) refactoring, handle);
} else {
LOG.log(Level.FINE, "not in a Maven project: {0}", fo.toURI());
return null;
}
} else {
LOG.log(Level.FINE, "ignoring {0} of kind {1}", new Object[] {handle, kind});
return null;
}
}
示例7: createInstance
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
/** Creates and returns a new instance of the refactoring plugin or returns
* null if the plugin is not suitable for the passed refactoring.
* @param refactoring Refactoring, the plugin shimport org.openide.ErrorManager;
ould operate on.
* @return Instance of RefactoringPlugin or null if the plugin is not applicable to
* the passed refactoring.
*/
public RefactoringPlugin createInstance(AbstractRefactoring refactoring) {
Lookup look = refactoring.getRefactoringSource();
FileObject file = look.lookup(FileObject.class);
NonRecursiveFolder folder = look.lookup(NonRecursiveFolder.class);
TreePathHandle handle = look.lookup(TreePathHandle.class);
FileObject prjFile = file;
//#114235
if (prjFile == null && folder != null) {
prjFile = folder.getFolder();
}
if (prjFile == null && handle != null) {
prjFile = handle.getFileObject();
}
if (prjFile != null) {
//#107638
Project project = FileOwnerQuery.getOwner(prjFile);
if (project == null || project.getLookup().lookup(NbModuleProvider.class) == null) {
// take just netbeans module development into account..
return null;
}
}
if (refactoring instanceof WhereUsedQuery) {
if (handle != null) {
return new NbWhereUsedRefactoringPlugin(refactoring);
}
}
if (refactoring instanceof RenameRefactoring) {
if (handle!=null || ((file!=null) && RetoucheUtils.isJavaFile(file))) {
//rename java file, class, method etc..
return new NbRenameRefactoringPlugin((RenameRefactoring)refactoring);
} else if (file!=null && RetoucheUtils.isOnSourceClasspath(file) && file.isFolder()) {
//rename folder
return new NbMoveRefactoringPlugin((RenameRefactoring)refactoring);
} else if (folder!=null && RetoucheUtils.isOnSourceClasspath(folder.getFolder())) {
//rename package
return new NbMoveRefactoringPlugin((RenameRefactoring)refactoring);
} else if (folder!=null && !RetoucheUtils.isOnSourceClasspath(folder.getFolder())) {
//rename resource
return new NbMoveRefactoringPlugin((RenameRefactoring)refactoring);
}
}
if (refactoring instanceof MoveRefactoring) {
//TODO return new NbMoveRefactoringPlugin((MoveRefactoring)refactoring);
}
if (refactoring instanceof SafeDeleteRefactoring) {
if (handle != null) {
return new NbSafeDeleteRefactoringPlugin(refactoring);
}
}
return null;
}
示例8: 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);
}
示例9: getJavaSource
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
@Override
protected JavaSource getJavaSource(Phase p) {
TreePathHandle selectedField = refactoring.getSelectedObject();
FileObject fo = selectedField.getFileObject();
return JavaSource.forFileObject(fo);
}
示例10: prepare
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
public Problem prepare(RefactoringElementsBag refactoringElements) {
final TreePathHandle treePathHandle = refactoring.getRefactoringSource().lookup(TreePathHandle.class);
FileObject fo = null;
if (treePathHandle != null &&
(TreeUtilities.CLASS_TREE_KINDS.contains(treePathHandle.getKind()) ||
treePathHandle.getKind() == Kind.VARIABLE ||
treePathHandle.getKind() == Kind.MEMBER_SELECT ||
treePathHandle.getKind() == Kind.IDENTIFIER)) {
fo = treePathHandle.getFileObject();
}
if (fo == null) {
fo = refactoring.getRefactoringSource().lookup(FileObject.class);
}
boolean recursive = true;
if (fo == null) {
NonRecursiveFolder folder = refactoring.getRefactoringSource().lookup(NonRecursiveFolder.class);
if (folder != null) {
recursive = false;
fo = folder.getFolder();
}
}
if (fo == null) {
return null;
}
// Find the mapping files in this project
Project proj = org.netbeans.api.project.FileOwnerQuery.getOwner(fo);
if(proj == null){
//file is not part of any project
return null;
}
HibernateEnvironment env = proj.getLookup().lookup(HibernateEnvironment.class);
if (env == null) {
// The project does not support Hibernate framework
return null;
}
mFileObjs = env.getAllHibernateMappingFileObjects();
if (mFileObjs == null || mFileObjs.size() == 0) {
// OK, no mapping files at all.
return null;
}
try {
if (treePathHandle != null) {
if (TreeUtilities.CLASS_TREE_KINDS.contains(treePathHandle.getKind())) {
// A Java class is being renamed
renameJavaClass(refactoringElements, treePathHandle, fo);
} else if (treePathHandle.getKind() == Kind.VARIABLE ||
treePathHandle.getKind() == Kind.MEMBER_SELECT ||
treePathHandle.getKind() == Kind.IDENTIFIER) {
// A Java field is being renamed
renameJavaField(refactoringElements, treePathHandle, fo);
}
} else if (fo.isFolder()) {
// A Java package is being renamed
renameJavaPackage(refactoringElements, treePathHandle, fo, recursive);
}
} catch (IOException ex) {
ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, ex);
}
return null;
}
示例11: prepare
import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
public Problem prepare(RefactoringElementsBag refactoringElements) {
if (query.getBooleanValue(WhereUsedQuery.FIND_REFERENCES)) {
final TreePathHandle treePathHandle = query.getRefactoringSource().lookup(TreePathHandle.class);
FileObject fo = null;
if (treePathHandle != null &&
(TreeUtilities.CLASS_TREE_KINDS.contains(treePathHandle.getKind()) ||
treePathHandle.getKind() == Kind.VARIABLE ||
treePathHandle.getKind() == Kind.MEMBER_SELECT ||
treePathHandle.getKind() == Kind.IDENTIFIER)) {
fo = treePathHandle.getFileObject();
}
if (fo == null) {
// TODO: return a Problem
return null;
}
// Find the mapping files in this project
Project proj = org.netbeans.api.project.FileOwnerQuery.getOwner(fo);
if(proj == null) {
// See issue 141117
return null;
}
HibernateEnvironment env = proj.getLookup().lookup(HibernateEnvironment.class);
if(env == null) {
// The project does not have Hibernate framework support
return null;
}
mappingFileObjs = env.getAllHibernateMappingFileObjects();
if (mappingFileObjs == null || mappingFileObjs.size() == 0) {
// OK, no mapping files at all.
return null;
}
try {
if (treePathHandle != null) {
if (TreeUtilities.CLASS_TREE_KINDS.contains(treePathHandle.getKind())) {
findJavaClassUsage(treePathHandle, refactoringElements, fo);
} else /*if (treePathHandle.getKind() == Kind.VARIABLE ||
treePathHandle.getKind() == Kind.MEMBER_SELECT ||
treePathHandle.getKind() == Kind.IDENTIFIER)*/ {
findJavaClassFieldUsage(treePathHandle, refactoringElements, fo);
}
}
} catch (IOException ex) {
ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, ex);
}
}
return null;
}