@Override public boolean value(PsiElement element) { if (element instanceof LightMethod) { PsiClass containingClass = ((LightMethod)element).getContainingClass(); if (containingClass != null && containingClass.isEnum()) return true; } if (element instanceof PsiReceiverParameter) { return true; } return element instanceof PsiJavaFile && !FileTypeUtils.isInServerPageFile(element) && !JavaProjectRootsUtil.isOutsideJavaSourceRoot((PsiFile)element) && ((PsiJavaFile) element).getClasses().length > 0; }
@Nullable public PsiMethod getValuesMethod() { PsiMethod method = myValuesMethod; if (method == null && isEnum() && getName() != null) { PsiElementFactory elementFactory = JavaPsiFacade.getInstance(getProject()).getElementFactory(); final PsiMethod valuesMethod = elementFactory.createMethodFromText("public static " + getName() + "[] values() {}", this); myValuesMethod = method = new LightMethod(getManager(), valuesMethod, this); } return method; }
@Nullable public PsiMethod getValueOfMethod() { PsiMethod method = myValueOfMethod; if (method == null && isEnum() && getName() != null) { PsiElementFactory elementFactory = JavaPsiFacade.getInstance(getProject()).getElementFactory(); final PsiMethod valuesMethod = elementFactory.createMethodFromText("public static " + getName() + " valueOf(String name) throws IllegalArgumentException {}", this); myValueOfMethod = method = new LightMethod(getManager(), valuesMethod, this); } return method; }
private PsiMethod getSyntheticMethod(String text) { PsiElementFactory factory = JavaPsiFacade.getInstance(myClass.getProject()).getElementFactory(); PsiMethod method = factory.createMethodFromText(text, myClass); return new LightMethod(myClass.getManager(), method, myClass); }