/** * judge field exists * * @param part * @return */ private boolean fieldExist(ViewPart part) { PsiField[] fields = mClass.getAllFields(); for (PsiField field : fields) { if (field.getName().equals(part.getName())) { return true; } } return false; }
private boolean existsFieldWithName(String name) { final PsiField[] allFields = sourceClass.getAllFields(); for (PsiField field : allFields) { if (name.equals(field.getName()) && !fields.contains(field)) { return true; } } return false; }
@Nullable public static PsiField findPropertyField( Project project, PsiClass aClass, String propertyName, boolean isStatic) { PsiField[] fields = aClass.getAllFields(); for (PsiField field : fields) { if (field.hasModifierProperty(PsiModifier.STATIC) != isStatic) continue; if (propertyName.equals(suggestPropertyName(project, field))) return field; } return null; }
private static void addFieldsUsages( final PsiClass aClass, final Processor<UsageInfo> results, final JavaClassFindUsagesOptions options) { if (options.isIncludeInherited) { final PsiManager manager = aClass.getManager(); PsiField[] fields = aClass.getAllFields(); FieldsLoop: for (int i = 0; i < fields.length; i++) { final PsiField field = fields[i]; // filter hidden fields for (int j = 0; j < i; j++) { if (Comparing.strEqual(field.getName(), fields[j].getName())) continue FieldsLoop; } final PsiClass fieldClass = field.getContainingClass(); if (manager.areElementsEquivalent(fieldClass, aClass)) { addElementUsages(fields[i], results, options); } else { ReferencesSearch.search( new ReferencesSearch.SearchParameters( field, options.searchScope, false, options.fastTrack)) .forEach( new ReadActionProcessor<PsiReference>() { @Override public boolean processInReadAction(final PsiReference reference) { addResultFromReference( reference, fieldClass, manager, aClass, results, options); return true; } }); } } } else { PsiField[] fields = ApplicationManager.getApplication() .runReadAction( new Computable<PsiField[]>() { @Override public PsiField[] compute() { return aClass.getFields(); } }); for (PsiField field : fields) { addElementUsages(field, results, options); } } }
public void visitClass(PsiClass aClass) { super.visitClass(aClass); if (isConcreteClass(aClass)) { final PsiField[] allFields = aClass.getAllFields(); int numInheritedFields = 0; for (final PsiField field : allFields) { final PsiClass containingClass = field.getContainingClass(); if (containingClass != null && !containingClass.equals(aClass) && !field.hasModifierProperty(PsiModifier.STATIC)) { numInheritedFields++; } } postMetric(aClass, numInheritedFields); } }
/** * spring bean reference annotator * * @param psiElement psi element * @param holder annotation holder */ public void annotate(PsiElement psiElement, AnnotationHolder holder) { if (!(psiElement instanceof PsiJavaFile)) { return; } // Get java classes for (PsiClass javaClass : ((PsiJavaFile) psiElement).getClasses()) { PsiClass superClass = javaClass.getSuperClass(); PsiField[] superClassFields = superClass != null ? superClass.getAllFields() : new PsiField[] {}; for (PsiField field : javaClass.getAllFields()) { // We don't need scan super class fields if (isContain(superClassFields, field)) { continue; } PsiModifierList modifierList = field.getModifierList(); if (modifierList == null) { continue; } for (PsiAnnotation psiAnnotation : modifierList.getAnnotations()) { String qcName = psiAnnotation.getQualifiedName(); if (qcName == null || !qcName.startsWith("org.unitils.spring.annotation.")) { continue; } SpringManager springManager = SpringManager.getInstance(psiElement.getProject()); SpringModel springModel = springManager.getCombinedModel(ModuleUtil.findModuleForPsiElement(psiElement)); if (springModel == null) { continue; } // by type if (qcName.endsWith("SpringBeanByType")) { final PsiType type = field.getType(); if (!(type instanceof PsiClassType)) { continue; } final PsiClass typeClass = ((PsiClassType) type).resolve(); if (typeClass == null) { continue; } List<SpringBaseBeanPointer> springBaseBeanPointerList = springModel.findBeansByPsiClass(typeClass); if (springBaseBeanPointerList.size() > 0) { List<PsiElement> elements = new ArrayList<PsiElement>(); for (SpringBaseBeanPointer springBaseBeanPointer : springBaseBeanPointerList) { elements.add(springBaseBeanPointer.getPsiElement()); } NavigationGutterIconBuilder.create(SpringIcons.SPRING_BEAN_ICON) .setTooltipText("Navigate to the spring bean declaration(s)") .setTargets(elements) .install(holder, field.getNameIdentifier()); } } // by name else { String beanName = field.getName(); if (qcName.endsWith("SpringBean")) { PsiAnnotationMemberValue attributeValue = psiAnnotation.findAttributeValue("value"); if (attributeValue != null && attributeValue.getText() != null) { beanName = attributeValue.getText().replace("\"", ""); } } if (beanName != null && StringUtil.isNotEmpty(beanName)) { SpringBeanPointer springBeanPointer = springModel.findBeanByName(beanName); if (springBeanPointer != null) { NavigationGutterIconBuilder.create(SpringIcons.SPRING_BEAN_ICON) .setTooltipText("Navigate to the spring bean declaration(s)") .setTarget(springBeanPointer.getPsiElement()) .install(holder, field.getNameIdentifier()); } } } } } } }