private static boolean shouldSuggestModifiers(PsiElement element) { PsiElement parent = element.getParent(); while (parent != null && (parent instanceof PsiJavaCodeReferenceElement || parent instanceof PsiErrorElement || parent instanceof PsiTypeElement || parent instanceof PsiMethod || parent instanceof PsiVariable || parent instanceof PsiDeclarationStatement || parent instanceof PsiImportList || parent instanceof PsiDocComment || element.getText().equals(parent.getText()))) { parent = parent.getParent(); if (parent instanceof JspClassLevelDeclarationStatement) { parent = parent.getContext(); } } if (parent == null) return false; PsiElement prev = FilterPositionUtil.searchNonSpaceNonCommentBack(element); if (parent instanceof PsiJavaFile || parent instanceof PsiClass) { if (prev == null || JavaKeywordCompletion.END_OF_BLOCK.getValue().isAcceptable(element, prev.getParent())) { return true; } } return false; }
private static boolean statementCanBePlacedAlong(final PsiElement element) { if (element instanceof JspTemplateStatement) { PsiElement neighbour = element.getPrevSibling(); // we can place statement inside scriptlet only return neighbour != null && !(neighbour instanceof JspTemplateStatement); } if (element instanceof PsiBlockStatement) return false; final PsiElement parent = element.getParent(); if (parent instanceof JspClassLevelDeclarationStatement) return false; if (parent instanceof PsiCodeBlock) return true; if (parent instanceof PsiIfStatement && (element == ((PsiIfStatement)parent).getThenBranch() || element == ((PsiIfStatement)parent).getElseBranch())) { return true; } if (parent instanceof PsiWhileStatement && element == ((PsiWhileStatement)parent).getBody()) { return true; } if (parent instanceof PsiDoWhileStatement && element == ((PsiDoWhileStatement)parent).getBody()) { return true; } // know nothing about that return false; }
private static boolean shouldSuggestModifiers(PsiElement element) { PsiElement parent = element.getParent(); while (parent != null && (parent instanceof PsiJavaCodeReferenceElement || parent instanceof PsiErrorElement || parent instanceof PsiTypeElement || parent instanceof PsiMethod || parent instanceof PsiVariable || parent instanceof PsiDeclarationStatement || parent instanceof PsiImportList || parent instanceof PsiDocComment || element.getText().equals(parent.getText()))) { parent = parent.getParent(); if (parent instanceof JspClassLevelDeclarationStatement) { parent = parent.getContext(); } } if (parent == null) return false; PsiElement prev = FilterPositionUtil.searchNonSpaceNonCommentBack(element); if (parent instanceof PsiJavaFile || parent instanceof PsiClass) { if (prev == null || JavaCompletionData.END_OF_BLOCK.isAcceptable(element, prev.getParent())) { return true; } } return false; }
@NotNull @Override public List<PsiMethod> getOwnMethods() { List<PsiMethod> methods = new ArrayList<>(); PsiStatement[] statements = getHolderMethod().getBody().getStatements(); for(PsiStatement statement : statements) { if(statement instanceof JspClassLevelDeclarationStatement) { statement.acceptChildren(new JavaElementVisitor() { @Override public void visitMethod(PsiMethod method) { methods.add(method); } }); } } return methods; }
@NotNull @Override @RequiredReadAction public List<PsiField> getOwnFields() { List<PsiField> fields = buildImplicitFields(); PsiStatement[] statements = getHolderMethod().getBody().getStatements(); for(PsiStatement statement : statements) { if(statement instanceof JspClassLevelDeclarationStatement) { statement.acceptChildren(new JavaElementVisitor() { @Override public void visitField(PsiField field) { fields.add(field); } }); } } return fields; }
@NotNull @Override @RequiredReadAction public List<PsiClass> getOwnInnerClasses() { List<PsiClass> classes = new ArrayList<>(); PsiStatement[] statements = getHolderMethod().getBody().getStatements(); for(PsiStatement statement : statements) { if(statement instanceof JspClassLevelDeclarationStatement) { statement.acceptChildren(new JavaElementVisitor() { @Override public void visitClass(PsiClass aClass) { classes.add(aClass); } }); } } return classes; }
@NotNull @Override protected ElementFilter compute() { return new OrFilter( new AfterElementFilter(new TextFilter("{")), new ScopeFilter(new ClassFilter(JspClassLevelDeclarationStatement.class))); }
@Override public void visitStatement(PsiStatement statement) { if (myRole2 == ChildRole.CLOSING_SEMICOLON) { createSpaceInCode(false); } if (statement instanceof JspClassLevelDeclarationStatement) { processClassBody(); } }