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


Java TreePathHandle.create方法代码示例

本文整理汇总了Java中org.netbeans.api.java.source.TreePathHandle.create方法的典型用法代码示例。如果您正苦于以下问题:Java TreePathHandle.create方法的具体用法?Java TreePathHandle.create怎么用?Java TreePathHandle.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.netbeans.api.java.source.TreePathHandle的用法示例。


在下文中一共展示了TreePathHandle.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareTypeVars

import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
static void prepareTypeVars(TreePath method, CompilationInfo info, Map<TypeMirror, TreePathHandle> typeVar2Def, List<TreePathHandle> typeVars) throws IllegalArgumentException {
    if (method.getLeaf().getKind() == Kind.METHOD) {
        MethodTree mt = (MethodTree) method.getLeaf();

        for (TypeParameterTree tv : mt.getTypeParameters()) {
            TreePath def = new TreePath(method, tv);
            TypeMirror type = info.getTrees().getTypeMirror(def);

            if (type != null && type.getKind() == TypeKind.TYPEVAR) {
                TreePathHandle tph = TreePathHandle.create(def, info);

                typeVar2Def.put(type, tph);
                typeVars.add(tph);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:IntroduceHint.java

示例2: run

import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
@Override
public List<Fix> run(CompilationInfo compilationInfo, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
    if (treePath.getLeaf().getKind() == Kind.METHOD) {
        MethodTree mt = (MethodTree) treePath.getLeaf();
        TreePath parentPath = treePath.getParentPath();
        ClassTree ct = (ClassTree) parentPath.getLeaf();
        Trees trees = compilationInfo.getTrees();
        Types types = compilationInfo.getTypes();
        TreeUtilities tu = compilationInfo.getTreeUtilities();
        TypeMirror type = types.erasure(trees.getTypeMirror(treePath));
        if (!Utilities.isValidType(type)) {
            return null;
        }
        for (Tree member : ct.getMembers()) {
            TreePath memberPath = new TreePath(parentPath, member);
            if (member.getKind() == Kind.METHOD && "<init>".contentEquals(((MethodTree)member).getName()) //NOI18N
                    && !tu.isSynthetic(memberPath) && types.isSameType(types.erasure(trees.getTypeMirror(memberPath)), type)) {
                return null;
            }
        }
        RenameConstructorFix fix = new RenameConstructorFix(compilationInfo.getSnapshot().getSource(), TreePathHandle.create(treePath, compilationInfo), offset, mt.getName(), ct.getSimpleName());
        return Collections.<Fix>singletonList(fix);
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:RenameConstructor.java

示例3: create

import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
public static MemberInfo<TreePathHandle> create(TreePath tpath, CompilationInfo c) {
    String format = ElementHeaders.NAME;
    Group g = null;
    Element el = c.getTrees().getElement(tpath);
    if (el == null) {
        return null;
    }
    if (el.getKind() == ElementKind.FIELD) {
        format += " : " + ElementHeaders.TYPE; // NOI18N
        g=Group.FIELD;
    } else if (el.getKind() == ElementKind.METHOD) {
        format += ElementHeaders.PARAMETERS + " : " + ElementHeaders.TYPE; // NOI18N
        g=Group.METHOD;
    } else if (el.getKind().isInterface()) {
        g=Group.IMPLEMENTS;
        format = "implements " + format; // NOI18N
    }

    MemberInfo<TreePathHandle> mi = new MemberInfo<TreePathHandle>(TreePathHandle.create(tpath, c), el.getSimpleName().toString(), ElementHeaders.getHeader(el, c, format), ElementIcons.getElementIcon(el.getKind(), el.getModifiers()));
    mi.modifiers = el.getModifiers();
    mi.group = g;
    return mi;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:MemberInfo.java

示例4: createConstant

import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
/**
 * Creates an 'introduce constant' fix.
 *
 * Note: the fix will not reference CompilationInfo and will remember only handles to TreePaths.
 *
 * @param resolved the path for expression or variable declaration to convert
 * @param info compilation context
 * @param value the actual expression or a variable initializer.
 * @param guessedName proposed name
 * @param numDuplicates number of other duplicates
 * @param offset offset for the hint
 * @param variableRewrite if variable name should be changed (?)
 * @param cancel cancel flag
 * @return
 */
static IntroduceFieldFix createConstant(TreePath resolved, CompilationInfo info, TreePath value, String guessedName, int numDuplicates, int offset, boolean variableRewrite, AtomicBoolean cancel) {
    CodeStyle cs = CodeStyle.getDefault(info.getFileObject());
    boolean isConstant = checkConstantExpression(info, value);
    TreePath constantTarget = isConstant ? findAcceptableConstantTarget(info, resolved) : null;
    if (!isConstant || constantTarget == null || cancel.get()) {
        return null;
    }
    TreePathHandle h = TreePathHandle.create(resolved, info);
    String varName;
    if (variableRewrite) {
        varName = guessedName;
    } else {
        String proposed = Utilities.toConstantName(guessedName);
        varName = Utilities.makeNameUnique(info, info.getTrees().getScope(constantTarget), proposed, cs.getStaticFieldNamePrefix(), cs.getStaticFieldNameSuffix());
    }
    ClassTree clazz = (ClassTree)constantTarget.getLeaf();
    Element el = info.getTrees().getElement(constantTarget);
    if (el == null || !(el.getKind().isClass() || el.getKind().isInterface())) {
        return null;
    }
    IntroduceConstantFix fix = new IntroduceConstantFix(h, info.getJavaSource(), varName, numDuplicates, offset, TreePathHandle.create(constantTarget, info));
    fix.setTargetIsInterface(clazz.getKind() == Tree.Kind.INTERFACE);
    return fix;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:IntroduceConstantFix.java

示例5: AddParameterOrLocalFix

import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
public AddParameterOrLocalFix(CompilationInfo info,
                              TypeMirror type, String name,
                              ElementKind kind,
                              int /*!!!Position*/ unresolvedVariable) {
    this.file = info.getFileObject();
    if (type.getKind() == TypeKind.NULL || type.getKind() == TypeKind.NONE) {
        TypeElement te = info.getElements().getTypeElement("java.lang.Object"); // NOI18N
        if (te != null) {
            type = te.asType();
            this.type = TypeMirrorHandle.create(type);
        } else {
            this.type = null;
        }
    } else {
        this.type = TypeMirrorHandle.create(type);
    }
    this.name = name;
    this.kind = kind;

    TreePath treePath = info.getTreeUtilities().pathFor(unresolvedVariable + 1);
    tpHandle = new TreePathHandle[1];
    tpHandle[0] = TreePathHandle.create(treePath, info);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:AddParameterOrLocalFix.java

示例6: compute

import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
private static ErrorDescription compute(HintContext ctx, String methodName) {
    TreePath message = ctx.getVariables().get("$message");
    List<List<TreePath>> sorted = Utilities.splitStringConcatenationToElements(ctx.getInfo(), message);

    if (sorted.size() <= 1) {
        return null;
    }

    //check for erroneous trees:
    for (List<TreePath> tps : sorted)
        for (TreePath tp : tps)
            if (tp.getLeaf().getKind() == Kind.ERRONEOUS) return null;

    FixImpl fix = new FixImpl(NbBundle.getMessage(LoggerStringConcat.class, "MSG_LoggerStringConcat_fix"), methodName, TreePathHandle.create(ctx.getPath(), ctx.getInfo()), TreePathHandle.create(message, ctx.getInfo()));

    return ErrorDescriptionFactory.forTree(ctx, message, NbBundle.getMessage(LoggerStringConcat.class, "MSG_LoggerStringConcat"), fix.toEditorFix());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:LoggerStringConcat.java

示例7: AddCastFix

import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
public AddCastFix(CompilationInfo info, TreePath expression, TreePath idealTypeTree, TypeMirror targetType) {
    super(info, expression);
    this.idealTypeTree = idealTypeTree != null ? TreePathHandle.create(idealTypeTree, info) : null;
    this.targetType = TypeMirrorHandle.create(targetType);
    this.treeName = Utilities.shortDisplayName(info, (ExpressionTree) expression.getLeaf());
    this.type = org.netbeans.modules.editor.java.Utilities.getTypeName(info, targetType, false).toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:AddCastFix.java

示例8: ReplaceIndexedForEachLoop

import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
public ReplaceIndexedForEachLoop(CompilationInfo info, TreePath tp, TreePath arr, List<TreePath> toReplace, Set<String> definedVariables) {
    super(info, tp);
    this.arrHandle = arr == null ? null : TreePathHandle.create(arr, info);
    this.toReplace = new ArrayList<>();
    
    for (TreePath tr : toReplace) {
        this.toReplace.add(TreePathHandle.create(tr, info));
    }
    this.definedVariables = definedVariables;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:IteratorToFor.java

示例9: createFix

import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
public JavaFix createFix(String fixLabel, boolean alwaysDefault) {
    TreePathHandle nHandle = nullBranch == null ? null : TreePathHandle.create(nullBranch, ctx.getInfo());
    ConvertToSwitch fix = new ConvertToSwitch(ctx.getInfo(),
                             ctx.getPath(),
                             TreePathHandle.create(variable, ctx.getInfo()),
                             nHandle,
                             literal2Statement,
                             isControlNotNull(), fixLabel);
    if (alwaysDefault) {
        fix.addDefaultAlways();
    }
    return fix;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:IfToSwitchSupport.java

示例10: 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,代码来源:ExtractSuperclassRefactoringUI.java

示例11: ExtractInterfaceRefactoringUI

import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
private ExtractInterfaceRefactoringUI(TreePath path, CompilationInfo info) {
    // compute source type
    this.name = ElementHeaders.getHeader(path, info, ElementHeaders.NAME);
    this.sourceType = TreePathHandle.create(path, info);
    // create an instance of pull up refactoring object
    refactoring = new ExtractInterfaceRefactoring(sourceType);
    refactoring.getContext().add(info.getClasspathInfo());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ExtractInterfaceRefactoringUI.java

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

示例13: isUsed

import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
private boolean isUsed(Tree memberTree, ModifiersTree mods) {
    if (!mods.getFlags().contains(Modifier.PRIVATE)) {
        // I don't want to search the world, better to ignore
        return true;
    }
    TreePath t = new TreePath(getControllerPath(), memberTree);
    TreePathHandle hnd = TreePathHandle.create(t, wcopy);
    WhereUsedQuery a = new WhereUsedQuery(Lookups.fixed(hnd));
    RefactoringSession session = RefactoringSession.create("Find usages");
    a.prepare(session);
    boolean used = !session.getRefactoringElements().isEmpty();
    session.finished();
    
    return used;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:ControllerGenerator.java

示例14: testLookup

import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
public void testLookup() throws Exception {
    prepareTest("test/Test.java", "package test; public class Test {}");

    TreePath tp = new TreePath(new TreePath(info.getCompilationUnit()), info.getCompilationUnit().getTypeDecls().get(0));
    TreePathHandle tph = TreePathHandle.create(tp, info);
    Element el = info.getTrees().getElement(tp);

    assertNotNull(el);

    final AtomicInteger counter = new AtomicInteger();
    
    Description d = Description.element(new ClassMemberPanelUI() {
        @Override public FileObject getFileObject() {
            counter.incrementAndGet();
            return info.getFileObject();
        }
    }, "test", ElementHandle.create(el), info.getClasspathInfo(), Collections.emptySet(), -1, false,
        el.getEnclosingElement().getKind() == ElementKind.PACKAGE);
    
    Node n = new ElementNode(d);

    assertEquals("#164874: should not compute FileObject eagerly", 0, counter.get());
    
    assertEquals(info.getFileObject(), n.getLookup().lookup(FileObject.class));
    assertEquals(1, counter.get());

    assertEquals(tph.resolve(info).getLeaf(), n.getLookup().lookup(TreePathHandle.class).resolve(info).getLeaf());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:ElementNodeTest.java

示例15: compileToClass

import org.netbeans.api.java.source.TreePathHandle; //导入方法依赖的package包/类
static ClassToInvoke compileToClass(CompilationInfo ci, String code, int codeOffset,
                                    JavaSource js, FileObject fo, int line,
                                    TreePath treePath, Tree tree,
                                    boolean staticContext) throws InvalidExpressionException {
    TreePathHandle tph = TreePathHandle.create(treePath, ci);
    String className = INVOCATION_CLASS_NAME + LAST_CLASS_ID.incrementAndGet();
    IntroduceClass introClass = new IntroduceClass(code, codeOffset, staticContext);
    boolean success = introClass.computeIntroduceMethod(tph, ci, treePath, tree);
    if (!success) {
        return null;
    }
    String methodInvoke = introClass.getMethodInvoke();
    String fullCode;
    Map<String, byte[]> compiledClass;
    try {
        fullCode = introClass.computeIntroduceClass(className, fo);
        DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
        compiledClass = CodeCompiler.compile(fo, js, fullCode, diagnostics);
        if (compiledClass == null) {
            return null;
        }
        for (Diagnostic<? extends JavaFileObject> diag : diagnostics.getDiagnostics()) {
            if (Diagnostic.Kind.ERROR.equals(diag.getKind()) &&
                diag.getSource().isNameCompatible(className, JavaFileObject.Kind.CLASS)) {
                
                throw new InvalidExpressionException(diag.getMessage(null));
            }
        }
    } catch (IOException ioe) {
        throw new InvalidExpressionException(ioe);
    }
    String classFQN = null;
    Map<String, byte[]> innerClasses = null;
    for (String ccName : compiledClass.keySet()) {
        if (ccName.endsWith(className)) {
            classFQN = ccName;
        } else if (ccName.contains(className)) {
            // A sub-class
            if (innerClasses == null) {
                innerClasses = new LinkedHashMap<>();
            }
            innerClasses.put(ccName, compiledClass.get(ccName));
        }
    }
    if (classFQN == null) {
        return null;
    }
    return new ClassToInvoke(classFQN,
                             compiledClass.get(classFQN),
                             "new "+className+"()."+methodInvoke,
                             innerClasses);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:53,代码来源:CodeSnippetCompiler.java


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