private boolean isContain(PsiField[] array, PsiField element) { for (PsiField t : array) { if (t != null && (t.equals(element) || t.getNameIdentifier().getText().equals(element.getNameIdentifier().getText()))) { return true; } } return false; }
private static void docheckClass(final PsiClass aClass, ProblemsHolder holder) { if (aClass.isInterface()) return; final PsiField[] fields = aClass.getFields(); final Set<PsiField> candidates = new LinkedHashSet<PsiField>(); for (PsiField field : fields) { if (field.hasModifierProperty(PsiModifier.PRIVATE) && !(field.hasModifierProperty(PsiModifier.STATIC) && field.hasModifierProperty(PsiModifier.FINAL))) { candidates.add(field); } } removeFieldsReferencedFromInitializers(aClass, candidates); if (candidates.isEmpty()) return; final Set<PsiField> usedFields = new THashSet<PsiField>(); removeReadFields(aClass, candidates, usedFields); if (candidates.isEmpty()) return; final ImplicitUsageProvider[] implicitUsageProviders = Extensions.getExtensions(ImplicitUsageProvider.EP_NAME); for (PsiField field : candidates) { if (usedFields.contains(field) && !hasImplicitReadOrWriteUsage(field, implicitUsageProviders)) { final String message = InspectionsBundle.message("inspection.field.can.be.local.problem.descriptor"); holder.registerProblem(field.getNameIdentifier(), message, new MyQuickFix(field)); } } }
private static void process( PsiField psiField, Collection<? super RelatedItemLineMarkerInfo> result) { if (!isExtensionPointNameDeclarationField(psiField)) return; final PsiClass epClass = resolveExtensionPointClass(psiField); if (epClass == null) return; final String epName = resolveEpName(psiField); if (epName == null) return; ExtensionPointLocator locator = new ExtensionPointLocator(epClass); List<ExtensionPointCandidate> targets = ContainerUtil.filter( locator.findDirectCandidates(), new Condition<ExtensionPointCandidate>() { @Override public boolean value(ExtensionPointCandidate candidate) { return epName.equals(candidate.epName); } }); final RelatedItemLineMarkerInfo<PsiElement> info = NavigationGutterIconBuilder.create(AllIcons.Nodes.Plugin, CONVERTER, RELATED_ITEM_PROVIDER) .setTargets(targets) .setPopupTitle("Choose Extension Point") .setTooltipText("Extension Point Declaration") .setAlignment(GutterIconRenderer.Alignment.RIGHT) .createLineMarkerInfo(psiField.getNameIdentifier()); result.add(info); }
@Nullable public FieldBreakpoint addFieldBreakpoint(@NotNull Document document, int offset) { PsiField field = FieldBreakpoint.findField(myProject, document, offset); if (field == null) { return null; } int line = document.getLineNumber(offset); if (document.getLineNumber(field.getNameIdentifier().getTextOffset()) < line) { return null; } return addFieldBreakpoint(document, line, field.getName()); }
/** * 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()); } } } } } } }
protected final void registerFieldError(@NotNull PsiField field, Object... infos) { final PsiElement nameIdentifier = field.getNameIdentifier(); registerError(nameIdentifier, infos); }