@NotNull public Collection<StructureViewTreeElement> getChildrenBase() { final ArrayList<StructureViewTreeElement> result = new ArrayList<StructureViewTreeElement>(); final PsiMethod element = getElement(); if (element == null || element instanceof JspHolderMethod) return result; final TextRange range = element.getTextRange(); if (range == null) return result; final PsiFile psiFile = element.getContainingFile(); if (psiFile == null || psiFile instanceof PsiCompiledElement) return result; final String fileText = psiFile.getText(); if (fileText == null) return result; if (!range.substring(fileText).contains(PsiKeyword.CLASS)) return result; element.accept(new JavaRecursiveElementWalkingVisitor(){ @Override public void visitClass(PsiClass aClass) { if (!(aClass instanceof PsiAnonymousClass) && !(aClass instanceof PsiTypeParameter)) { result.add(new JavaClassTreeElement(aClass, isInherited(), new HashSet<PsiClass>(Arrays.asList(aClass.getSupers())))); } } }); return result; }
@NotNull @RequiredReadAction private List<PsiField> buildImplicitFields() { List<PsiField> fields = new ArrayList<>(); addField(fields, JspHolderMethod.OUT_VAR_NAME, PrintWriter.class.getName()); addField(fields, JspHolderMethod.RESPONSE_VAR_NAME, ServletApiClassNames.HttpServletResponse); addField(fields, JspHolderMethod.REQUEST_VAR_NAME, ServletApiClassNames.HttpServletRequest); addField(fields, JspHolderMethod.SESSION_VAR_NAME, ServletApiClassNames.HttpSession); addField(fields, JspHolderMethod.PAGE_VAR_NAME, Object.class.getName()); addField(fields, JspHolderMethod.APPLICATION_VAR_NAME, ServletApiClassNames.ServletContext); addField(fields, JspHolderMethod.CONFIG_VAR_NAME, ServletApiClassNames.ServletConfig); addField(fields, JspHolderMethod.CONTEXT_VAR_NAME, ServletApiClassNames.PageContext); JspFile jspxFile = getJspxFile(); if(jspxFile.isErrorPage()) { addField(fields, JspHolderMethod.EXCEPTION_VAR_NAME, Throwable.class.getName()); } return fields; }
private static boolean isInJspHolderMethod(PsiExpression expr) { final PsiElement parent1 = expr.getParent(); if (parent1 == null) { return false; } final PsiElement parent2 = parent1.getParent(); if (!(parent2 instanceof JspCodeBlock)) return false; final PsiElement parent3 = parent2.getParent(); return parent3 instanceof JspHolderMethod; }
public static TextRange getMethodDeclarationTextRange(@NotNull PsiMethod method) { if (method instanceof JspHolderMethod) return TextRange.EMPTY_RANGE; int start = stripAnnotationsFromModifierList(method.getModifierList()); final TextRange throwsRange = method.getThrowsList().getTextRange(); LOG.assertTrue(throwsRange != null, method); int end = throwsRange.getEndOffset(); return new TextRange(start, end); }
@Nullable private static HighlightInfoType getUnhandledExceptionHighlightType(final PsiElement element) { if (!JspPsiUtil.isInJspFile(element)) { return HighlightInfoType.UNHANDLED_EXCEPTION; } PsiMethod targetMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class); if (!(targetMethod instanceof JspHolderMethod)) return HighlightInfoType.UNHANDLED_EXCEPTION; // ignore JSP top level errors - it handled by UnhandledExceptionInJSP inspection return null; }
@Nullable @Override public TextRange getRangeToFold(PsiElement element) { if (element instanceof JspHolderMethod) return null; return super.getRangeToFold(element); //To change body of overridden methods use File | Settings | File Templates. }
private static boolean isFieldOrStaticMethod(final PsiElement element) { if (element instanceof PsiField) return true; if (element instanceof PsiMethod) { if (element instanceof JspHolderMethod) return false; return ((PsiMethod) element).hasModifierProperty(PsiModifier.STATIC); } return false; }
public boolean canMove(final PsiElement[] elements, @Nullable final PsiElement targetContainer) { if (elements.length != 1) return false; PsiElement element = elements [0]; if (!(element instanceof PsiMethod)) return false; if (element instanceof JspHolderMethod) return false; PsiMethod method = (PsiMethod) element; if (method.hasModifierProperty(PsiModifier.STATIC)) return false; return super.canMove(elements, targetContainer); }
@Override @NotNull public JspHolderMethod getHolderMethod() { return findNotNullChildByClass(JspHolderMethod.class); }