本文整理汇总了Java中org.netbeans.api.java.source.TreePathHandle类的典型用法代码示例。如果您正苦于以下问题:Java TreePathHandle类的具体用法?Java TreePathHandle怎么用?Java TreePathHandle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TreePathHandle类属于org.netbeans.api.java.source包,在下文中一共展示了TreePathHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: checkMove
import org.netbeans.api.java.source.TreePathHandle; //导入依赖的package包/类
private boolean checkMove(Lookup refactoringSource) {
for (FileObject f:refactoringSource.lookupAll(FileObject.class)) {
if (RefactoringUtils.isJavaFile(f)) {
return true;
}
if (f.isFolder()) {
return true;
}
}
Collection<? extends TreePathHandle> tphs = refactoringSource.lookupAll(TreePathHandle.class);
if(tphs.size() == 1) {
ElementHandle elementHandle = tphs.iterator().next().getElementHandle();
if(elementHandle != null &&
(elementHandle.getKind().isClass() ||
elementHandle.getKind().isInterface())) {
return true;
}
}
return false;
}
示例3: directive
import org.netbeans.api.java.source.TreePathHandle; //导入依赖的package包/类
@NonNull
static Description directive(
@NonNull final ClassMemberPanelUI ui,
@NonNull final String name,
@NonNull final TreePathHandle treePathHandle,
@NonNull final ModuleElement.DirectiveKind kind,
@NonNull final ClasspathInfo cpInfo,
final long pos,
@NonNull final Openable openable) {
return new Description(
ui,
name,
Union2.<ElementHandle<?>,TreePathHandle>createSecond(treePathHandle),
ElementKind.OTHER,
directivePosInKind(kind),
cpInfo,
EnumSet.of(Modifier.PUBLIC),
pos,
false,
false,
()->ElementIcons.getModuleDirectiveIcon(kind),
openable);
}
示例4: checkSystemOut
import org.netbeans.api.java.source.TreePathHandle; //导入依赖的package包/类
@TriggerPatterns ({
@TriggerPattern (value="System.out"),
@TriggerPattern (value="System.err")
})
public static ErrorDescription checkSystemOut (HintContext ctx) {
TreePath treePath = ctx.getPath ();
CompilationInfo compilationInfo = ctx.getInfo ();
return ErrorDescriptionFactory.forName (
ctx,
treePath,
NbBundle.getMessage (SystemOut.class, "MSG_SystemOut"),
new FixImpl (
NbBundle.getMessage (
LoggerNotStaticFinal.class,
"MSG_SystemOut_fix"
),
TreePathHandle.create (treePath, compilationInfo)
).toEditorFix()
);
}
示例5: openable
import org.netbeans.api.java.source.TreePathHandle; //导入依赖的package包/类
@NonNull
public static Openable openable(
@NonNull final ModuleElement module,
@NonNull final ModuleElement.Directive directive,
@NonNull final ClasspathInfo cpInfo) {
final String displayName = module.getQualifiedName().toString();
final ElementHandle<ModuleElement> moduleHandle = ElementHandle.create(module);
final Object[] directiveHandle = createDirectiveHandle(directive);
return () -> {
final FileObject source = SourceUtils.getFile(moduleHandle, cpInfo);
if (source == null) {
noSource(displayName);
}
TreePathHandle path = resolveDirectiveHandle(source, directiveHandle);
if (path == null) {
noSource(displayName);
}
if (!ElementOpen.open(source, path)) {
noSource(displayName);
}
};
}
示例6: performMove
import org.netbeans.api.java.source.TreePathHandle; //导入依赖的package包/类
void performMove(FileObject source, final int position, final URL target, Problem... expectedProblems) throws IOException, IllegalArgumentException, InterruptedException {
final MoveRefactoring[] r = new MoveRefactoring[1];
JavaSource.forFileObject(source).runUserActionTask(new Task<CompilationController>() {
@Override
public void run(CompilationController info) throws Exception {
info.toPhase(JavaSource.Phase.RESOLVED);
CompilationUnitTree cut = info.getCompilationUnit();
ClassTree classTree = (ClassTree) cut.getTypeDecls().get(position);
TreePath classPath = info.getTrees().getPath(cut, classTree);
r[0] = new MoveRefactoring(Lookups.singleton(TreePathHandle.create(classPath, info)));
r[0].setTarget(Lookups.singleton(target));
}
}, true);
RefactoringSession rs = RefactoringSession.create("Session");
List<Problem> problems = new LinkedList<Problem>();
addAllProblems(problems, r[0].preCheck());
if (!problemIsFatal(problems)) {
addAllProblems(problems, r[0].prepare(rs));
}
if (!problemIsFatal(problems)) {
addAllProblems(problems, rs.doRefactoring(true));
}
assertProblems(Arrays.asList(expectedProblems), problems);
}
示例7: valueOfBoxed
import org.netbeans.api.java.source.TreePathHandle; //导入依赖的package包/类
@TriggerPatterns({
@TriggerPattern(value = "java.lang.Byte.valueOf($v)", constraints = @ConstraintVariableType(variable = "$v", type = "java.lang.Byte")),
@TriggerPattern(value = "java.lang.Character.valueOf($v)", constraints = @ConstraintVariableType(variable = "$v", type = "java.lang.Character")),
@TriggerPattern(value = "java.lang.Double.valueOf($v)", constraints = @ConstraintVariableType(variable = "$v", type = "java.lang.Double")),
@TriggerPattern(value = "java.lang.Float.valueOf($v)", constraints = @ConstraintVariableType(variable = "$v", type = "java.lang.Float")),
@TriggerPattern(value = "java.lang.Integer.valueOf($v)", constraints = @ConstraintVariableType(variable = "$v", type = "java.lang.Integer")),
@TriggerPattern(value = "java.lang.Long.valueOf($v)", constraints = @ConstraintVariableType(variable = "$v", type = "java.lang.Long")),
@TriggerPattern(value = "java.lang.Short.valueOf($v)", constraints = @ConstraintVariableType(variable = "$v", type = "java.lang.Short")),
@TriggerPattern(value = "java.lang.Boolean.valueOf($v)", constraints = @ConstraintVariableType(variable = "$v", type = "java.lang.Boolean"))
})
public static ErrorDescription valueOfBoxed(HintContext ctx) {
TreePath p = ctx.getVariables().get("$v"); // NOI18N
return ErrorDescriptionFactory.forTree(ctx, ctx.getPath(), Bundle.TEXT_BoxingOfBoxedValue(),
new RemoveBoxingFix(TreePathHandle.create(ctx.getPath(), ctx.getInfo()),
TreePathHandle.create(p, ctx.getInfo())).toEditorFix());
}
示例8: constructor
import org.netbeans.api.java.source.TreePathHandle; //导入依赖的package包/类
@Hint(id="org.netbeans.modules.java.hints.UtilityClass_2", displayName="#MSG_PublicConstructor", description="#HINT_PublicConstructor", category="api", enabled=false, severity=Severity.HINT, suppressWarnings="UtilityClassWithPublicConstructor")
@TriggerTreeKind(Kind.METHOD)
public static ErrorDescription constructor(HintContext ctx) {
CompilationInfo compilationInfo = ctx.getInfo();
TreePath treePath = ctx.getPath();
Element e = compilationInfo.getTrees().getElement(treePath);
if (e == null) {
return null;
}
if ( e.getKind() != ElementKind.CONSTRUCTOR
|| compilationInfo.getElementUtilities().isSynthetic(e)
|| (!e.getModifiers().contains(Modifier.PROTECTED) && !e.getModifiers().contains(Modifier.PUBLIC))) {
return null;
}
if (!isUtilityClass(compilationInfo, e.getEnclosingElement())) return null;
return ErrorDescriptionFactory.forName(ctx,
treePath,
NbBundle.getMessage(UtilityClass.class, "MSG_PublicConstructor"),
new FixImpl(false,
TreePathHandle.create(e, compilationInfo)
).toEditorFix());
}
示例9: ConvertToARMFix
import org.netbeans.api.java.source.TreePathHandle; //导入依赖的package包/类
private ConvertToARMFix(
final CompilationInfo info,
final String bundleKey,
final TreePath owner,
final NestingKind nestignKind,
final TreePath var,
final TreePath init,
final Collection<? extends TreePath> armPaths,
final Collection<? extends TreePath> statements,
final Collection<? extends TreePath> catches,
final Collection<? extends TreePath> finStatementsPath,
final Collection<? extends TreePath> tail,
final Collection<? extends TreePath> cleanUpStms) {
super(info, owner);
this.bundleKey = bundleKey;
this.nestingKind = nestignKind;
this.varHandle = var != null ? TreePathHandle.create(var, info) : null;
this.initHandle = init != null ? TreePathHandle.create(init, info) : null;
this.armPathHandles = wrap(info, armPaths);
this.statementsPathHandles = wrap(info, statements);
this.catchesPathHandles = wrap(info, catches);
this.finStatementsPathHandles = wrap(info, finStatementsPath);
this.tailHandle = wrap(info, tail);
this.cleanUpStmsHandle = wrap(info, cleanUpStms);
}
示例10: checkLoggerDeclaration
import org.netbeans.api.java.source.TreePathHandle; //导入依赖的package包/类
@TriggerPatterns({
@TriggerPattern(value="$mods$ java.util.logging.Logger $LOG;"), //NOI18N
@TriggerPattern(value="$mods$ java.util.logging.Logger $LOG = $init;") //NOI18N
})
public static ErrorDescription checkLoggerDeclaration(HintContext ctx) {
Element e = ctx.getInfo().getTrees().getElement(ctx.getPath());
if (e != null && e.getEnclosingElement().getKind() == ElementKind.CLASS &&
(!e.getModifiers().contains(Modifier.STATIC) || !e.getModifiers().contains(Modifier.FINAL)) &&
ctx.getInfo().getElementUtilities().outermostTypeElement(e) == e.getEnclosingElement()
) {
return ErrorDescriptionFactory.forName(
ctx,
ctx.getPath(),
NbBundle.getMessage(LoggerNotStaticFinal.class, "MSG_LoggerNotStaticFinal_checkLoggerDeclaration", e), //NOI18N
new LoggerNotStaticFinalFix(NbBundle.getMessage(LoggerNotStaticFinal.class, "MSG_LoggerNotStaticFinal_checkLoggerDeclaration_fix", e), TreePathHandle.create(e, ctx.getInfo())).toEditorFix() //NOI18N
);
} else {
return null;
}
}
示例11: createInlineTempRefactoring
import org.netbeans.api.java.source.TreePathHandle; //导入依赖的package包/类
private void createInlineTempRefactoring(FileObject source, final int position, final InlineRefactoring[] r) throws IllegalArgumentException, IOException {
JavaSource.forFileObject(source).runUserActionTask(new Task<CompilationController>() {
@Override
public void run(CompilationController parameter) throws Exception {
parameter.toPhase(JavaSource.Phase.RESOLVED);
CompilationUnitTree cut = parameter.getCompilationUnit();
MethodTree testMethod = (MethodTree) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(1);
VariableTree variable = (VariableTree) testMethod.getBody().getStatements().get(position);
TreePath tp = TreePath.getPath(cut, variable);
r[0] = new InlineRefactoring(TreePathHandle.create(tp, parameter), InlineRefactoring.Type.TEMP);
}
}, true);
}
示例12: 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;
}
示例13: 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);
}
示例14: create
import org.netbeans.api.java.source.TreePathHandle; //导入依赖的package包/类
public static TargetDescription create(CompilationInfo info, TypeElement type, TreePath path, boolean allowForDuplicates, boolean iface) {
boolean canStatic = true;
if (iface) {
// interface cannot have static methods
canStatic = false;
} else {
if (type.getNestingKind() == NestingKind.ANONYMOUS ||
type.getNestingKind() == NestingKind.LOCAL ||
(type.getNestingKind() != NestingKind.TOP_LEVEL && !type.getModifiers().contains(Modifier.STATIC))) {
canStatic = false;
}
}
return new TargetDescription(Utilities.target2String(type),
ElementHandle.create(type),
TreePathHandle.create(path, info),
allowForDuplicates,
type.getSimpleName().length() == 0, iface, canStatic);
}
示例15: Description
import org.netbeans.api.java.source.TreePathHandle; //导入依赖的package包/类
private Description(@NonNull ClassMemberPanelUI ui,
@NonNull final String name,
@NonNull final ElementHandle<? extends Element> elementHandle,
final int posInKind,
@NonNull final ClasspathInfo cpInfo,
@NonNull final Set<Modifier> modifiers,
final long pos,
final boolean inherited,
final boolean topLevel) {
Parameters.notNull("ui", ui); //NOI18N
Parameters.notNull("name", name); //NOI18N
Parameters.notNull("elementHandle", elementHandle); //NOI18N
this.ui = ui;
this.name = name;
this.handle = Union2.<ElementHandle<?>,TreePathHandle>createFirst(elementHandle);
this.kind = elementHandle.getKind();
this.posInKind = posInKind;
this.cpInfo = cpInfo;
this.modifiers = modifiers;
this.pos = pos;
this.isInherited = inherited;
this.isTopLevel = topLevel;
this.icon = () -> ElementIcons.getElementIcon(this.kind, this.modifiers);
this.openable = () -> {OpenAction.openable(elementHandle, getFileObject(), name).open();};
}