/** * Returns path to the deepest tree of the given kind containing the given * starting tree. * @param kind requested tree kind * @param path path to the starting tree * @return requested path or null if no tree of the given kind encloses * the given starting tree * * @since 0.136 */ public TreePath getPathElementOfKind(Tree.Kind kind, TreePath path) { return getPathElementOfKind(EnumSet.of(kind), path); }
&& env.getController().getTreeUtilities().getPathElementOfKind(Tree.Kind.INTERFACE, env.getPath()) != null && !modifiers.contains(STATIC) && !modifiers.contains(ABSTRACT) && !modifiers.contains(DEFAULT)) { kws.add(DEFAULT_KEYWORD);
private static boolean withinAnonymousOrLocalClass(TreeUtilities tu, TreePath path) { do { path = tu.getPathElementOfKind(TreeUtilities.CLASS_TREE_KINDS, path); if (path == null) { return false; } path = path.getParentPath(); if (path.getLeaf().getKind() != Tree.Kind.COMPILATION_UNIT && !TreeUtilities.CLASS_TREE_KINDS.contains(path.getLeaf().getKind())) { return true; } } while (true); }
private void insideCatch(Env env) throws IOException { TreePath path = env.getPath(); CatchTree ct = (CatchTree) path.getLeaf(); CompilationController controller = env.getController(); TokenSequence<JavaTokenId> last = findLastNonWhitespaceToken(env, ct, env.getOffset()); if (last != null && last.token().id() == JavaTokenId.LPAREN) { addKeyword(env, FINAL_KEYWORD, SPACE, false); if (!options.contains(Options.ALL_COMPLETION)) { TreeUtilities tu = controller.getTreeUtilities(); TreePath tryPath = tu.getPathElementOfKind(Tree.Kind.TRY, path); Set<TypeMirror> exs = tu.getUncaughtExceptions(tryPath != null ? tryPath : path.getParentPath()); Elements elements = controller.getElements(); for (TypeMirror ex : exs) { if (ex.getKind() == TypeKind.DECLARED && startsWith(env, ((DeclaredType) ex).asElement().getSimpleName().toString()) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(((DeclaredType) ex).asElement())) && !Utilities.isExcluded(((TypeElement)((DeclaredType) ex).asElement()).getQualifiedName())) { env.addToExcludes(((DeclaredType) ex).asElement()); results.add(itemFactory.createTypeItem(env.getController(), (TypeElement) ((DeclaredType) ex).asElement(), (DeclaredType) ex, anchorOffset, env.getReferencesCount(), elements.isDeprecated(((DeclaredType) ex).asElement()), false, false, false, true, false)); } } } TypeElement te = controller.getElements().getTypeElement("java.lang.Throwable"); //NOI18N if (te != null) { addTypes(env, EnumSet.of(CLASS, INTERFACE, TYPE_PARAMETER), controller.getTypes().getDeclaredType(te)); } } }
if (!options.contains(Options.ALL_COMPLETION)) { TreeUtilities tu = controller.getTreeUtilities(); TreePath tryPath = tu.getPathElementOfKind(Tree.Kind.TRY, path); Set<TypeMirror> exs = tu.getUncaughtExceptions(tryPath); if (!exs.isEmpty()) {
private void addKeywordsForClassBody(Env env) { String prefix = env.getPrefix(); for (String kw : CLASS_BODY_KEYWORDS) { if (Utilities.startsWith(kw, prefix)) { results.add(itemFactory.createKeywordItem(kw, SPACE, anchorOffset, false)); } } if (env.getController().getSourceVersion().compareTo(SourceVersion.RELEASE_8) >= 0 && Utilities.startsWith(DEFAULT_KEYWORD, prefix) && env.getController().getTreeUtilities().getPathElementOfKind(Tree.Kind.INTERFACE, env.getPath()) != null) { results.add(itemFactory.createKeywordItem(DEFAULT_KEYWORD, SPACE, anchorOffset, false)); } addPrimitiveTypeKeywords(env); }
controller.toPhase(Phase.ELEMENTS_RESOLVED); final TreeUtilities tu = controller.getTreeUtilities(); final TreePath clsPath = tu.getPathElementOfKind(TreeUtilities.CLASS_TREE_KINDS, env.getPath()); if (clsPath == null) { return;
TreePath tp = env.getController().getTreeUtilities().getPathElementOfKind(EnumSet.of(Tree.Kind.METHOD, Tree.Kind.LAMBDA_EXPRESSION), env.getPath()); String postfix = SPACE; if (tp != null) {
if (!options.contains(Options.ALL_COMPLETION)) { TreeUtilities tu = controller.getTreeUtilities(); TreePath tryPath = tu.getPathElementOfKind(Tree.Kind.TRY, path); Set<TypeMirror> exs = tu.getUncaughtExceptions(tryPath); Elements elements = controller.getElements();
TreePath tp = env.getController().getTreeUtilities().getPathElementOfKind(EnumSet.of(Tree.Kind.METHOD, Tree.Kind.LAMBDA_EXPRESSION), env.getPath()); String postfix = SPACE; if (tp != null) {
TreePath methodOrLambdaPath = tu.getPathElementOfKind(EnumSet.of(Tree.Kind.METHOD, Tree.Kind.LAMBDA_EXPRESSION), path); if (methodOrLambdaPath == null) { return null; TreePath methodPath = tu.getPathElementOfKind(Tree.Kind.METHOD, path); if (methodPath == null) { return null;
TreePath tryPath = tu.getPathElementOfKind(Kind.TRY, typePath); if (tryPath != null) { return med.process(info, doc, ((TryTree)tryPath.getLeaf()).getBlock(), Collections.singletonList(typePath.getLeaf()));
path = tu.getPathElementOfKind(Tree.Kind.LAMBDA_EXPRESSION, tu.pathFor(new TreePath(blockPath.getParentPath(), block), offset, sourcePositions)); lambdaBody = ((LambdaExpressionTree) path.getLeaf()).getBody(); bodyPos = (int) sourcePositions.getStartPosition(root, lambdaBody);