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


Java TreePathHandle.resolve方法代码示例

本文整理汇总了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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ConvertToARM.java

示例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);
                
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:Imports.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ImportClass.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:PushDownRefactoringUI.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:PullUpRefactoringUI.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:56,代码来源:WhereUsedQueryUI.java

示例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});
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:48,代码来源:SafeDeleteUI.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:44,代码来源:IntroduceMethodFix.java


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