@Override public boolean execute(@NotNull final SuperMethodsSearch.SearchParameters queryParameters, @NotNull final Processor<MethodSignatureBackedByPsiMethod> consumer) { final PsiClass parentClass = queryParameters.getPsiClass(); final PsiMethod method = queryParameters.getMethod(); return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() { @Override public Boolean compute() { HierarchicalMethodSignature signature = method.getHierarchicalMethodSignature(); final boolean checkBases = queryParameters.isCheckBases(); final boolean allowStaticMethod = queryParameters.isAllowStaticMethod(); final List<HierarchicalMethodSignature> supers = signature.getSuperSignatures(); for (HierarchicalMethodSignature superSignature : supers) { if (MethodSignatureUtil.isSubsignature(superSignature, signature)) { if (!addSuperMethods(superSignature, method, parentClass, allowStaticMethod, checkBases, consumer)) return false; } } return true; } }); }
public PsiMethodPattern definedInClass(final ElementPattern<? extends PsiClass> pattern) { return with(new PatternConditionPlus<PsiMethod, PsiClass>("definedInClass", pattern) { @Override public boolean processValues(PsiMethod t, final ProcessingContext context, final PairProcessor<PsiClass, ProcessingContext> processor) { if (!processor.process(t.getContainingClass(), context)) return false; final Ref<Boolean> result = Ref.create(Boolean.TRUE); SuperMethodsSearch.search(t, null, true, false).forEach(new Processor<MethodSignatureBackedByPsiMethod>() { @Override public boolean process(final MethodSignatureBackedByPsiMethod signature) { if (!processor.process(signature.getMethod().getContainingClass(), context)) { result.set(Boolean.FALSE); return false; } return true; } }); return result.get(); } }); }
@Override public void visitMethod(@NotNull PsiMethod method) { final PsiParameterList parameterList = method.getParameterList(); if (parameterList.getParametersCount() == 0) { return; } final Query<MethodSignatureBackedByPsiMethod> query = SuperMethodsSearch.search( method, method.getContainingClass(), true, false); final MethodSignatureBackedByPsiMethod methodSignature = query.findFirst(); if (methodSignature == null) { return; } final PsiMethod superMethod = methodSignature.getMethod(); final PsiParameter[] parameters = parameterList.getParameters(); checkParameters(superMethod, parameters); }
@Override public boolean execute(@NotNull final SuperMethodsSearch.SearchParameters queryParameters, @NotNull final Processor<MethodSignatureBackedByPsiMethod> consumer) { final PsiClass parentClass = queryParameters.getPsiClass(); final PsiMethod method = queryParameters.getMethod(); HierarchicalMethodSignature signature = method.getHierarchicalMethodSignature(); final boolean checkBases = queryParameters.isCheckBases(); final boolean allowStaticMethod = queryParameters.isAllowStaticMethod(); final List<HierarchicalMethodSignature> supers = signature.getSuperSignatures(); for (HierarchicalMethodSignature superSignature : supers) { if (MethodSignatureUtil.isSubsignature(superSignature, signature)) { if (!addSuperMethods(superSignature, method, parentClass, allowStaticMethod, checkBases, consumer)) return false; } } return true; }
@Override public void visitMethod(PsiMethod method) { ArrangementSettingsToken type = method.isConstructor() ? CONSTRUCTOR : METHOD; JavaElementArrangementEntry entry = createNewEntry(method, method.getTextRange(), type, method.getName(), true); if (entry == null) { return; } processEntry(entry, method, method.getBody()); parseProperties(method, entry); myInfo.onMethodEntryCreated(method, entry); MethodSignatureBackedByPsiMethod overridden = SuperMethodsSearch.search(method, null, true, false).findFirst(); if (overridden != null) { myInfo.onOverriddenMethod(overridden.getMethod(), method); } boolean reset = myMethodBodyProcessor.setBaseMethod(method); try { method.accept(myMethodBodyProcessor); } finally { if (reset) { myMethodBodyProcessor.setBaseMethod(null); } } }
@Override public String getLocationString() { if (!Registry.is("show.method.base.class.in.java.file.structure")) return null; final PsiMethod method = getElement(); if (myLocation == null && method != null && !DumbService.isDumb(method.getProject())) { if (isInherited()) { return super.getLocationString(); } else { try { final MethodSignatureBackedByPsiMethod baseMethod = SuperMethodsSearch.search(method, null, true, false).findFirst(); if (baseMethod != null && !method.isEquivalentTo(baseMethod.getMethod())) { PsiMethod base = baseMethod.getMethod(); PsiClass baseClass = base.getContainingClass(); if (baseClass != null /*&& !CommonClassNames.JAVA_LANG_OBJECT.equals(baseClass.getQualifiedName())*/) { if (baseClass.getMethods().length > 1) { myLocation = baseClass.getName(); } } } } catch (IndexNotReadyException e) { //some searchers (EJB) require indices. What shall we do? } if (StringUtil.isEmpty(myLocation)) { myLocation = ""; } else { char upArrow = '\u2191'; myLocation = UIUtil.getLabelFont().canDisplay(upArrow) ? upArrow + myLocation : myLocation; } } } return StringUtil.isEmpty(myLocation) ? null : myLocation; }
@Override public void visitMethod(PsiMethod method) { boolean isSectionCommentsDetected = registerSectionComments(method); final TextRange range = isSectionCommentsDetected ? getElementRangeWithoutComments(method) : method.getTextRange(); ArrangementSettingsToken type = method.isConstructor() ? CONSTRUCTOR : METHOD; JavaElementArrangementEntry entry = createNewEntry(method, range, type, method.getName(), true); if (entry == null) { return; } processEntry(entry, method, method.getBody()); parseProperties(method, entry); myInfo.onMethodEntryCreated(method, entry); MethodSignatureBackedByPsiMethod overridden = SuperMethodsSearch.search(method, null, true, false).findFirst(); if (overridden != null) { entry.addModifier(OVERRIDDEN); myInfo.onOverriddenMethod(overridden.getMethod(), method); } boolean reset = myMethodBodyProcessor.setBaseMethod(method); try { method.accept(myMethodBodyProcessor); } finally { if (reset) { myMethodBodyProcessor.setBaseMethod(null); } } }
@Override public void visitMethod(PsiMethod method) { super.visitMethod(method); final PsiCodeBlock body = method.getBody(); if (body == null) { return; } if (method.getNameIdentifier() == null) { return; } final Query<MethodSignatureBackedByPsiMethod> superMethodQuery = SuperMethodsSearch.search(method, null, true, false); final MethodSignatureBackedByPsiMethod signature = superMethodQuery.findFirst(); if (signature == null) { return; } final PsiMethod superMethod = signature.getMethod(); final PsiCodeBlock superBody = superMethod.getBody(); if (superBody == null) { return; } if (!modifierListsAreEquivalent(method.getModifierList(), superMethod.getModifierList())) { return; } final PsiType superReturnType = superMethod.getReturnType(); if (superReturnType == null || !superReturnType.equals(method.getReturnType())) { return; } if (!EquivalenceChecker.codeBlocksAreEquivalent(body, superBody)) { return; } registerMethodError(method); }
@Override public void visitMethod(@NotNull PsiMethod method) { if (!CloneUtils.isClone(method)) { return; } if (method.hasModifierProperty(PsiModifier.FINAL)) { return; } if (onlyWarnOnProtectedClone && method.hasModifierProperty(PsiModifier.PUBLIC)) { return; } final PsiClass containingClass = method.getContainingClass(); if (containingClass == null) { return; } if (containingClass.hasModifierProperty(PsiModifier.FINAL)) { return; } if (MethodUtils.hasInThrows(method, "java.lang.CloneNotSupportedException")) { return; } final MethodSignatureBackedByPsiMethod signature = SuperMethodsSearch.search(method, null, true, false).findFirst(); if (signature == null) { return; } final PsiMethod superMethod = signature.getMethod(); if (!MethodUtils.hasInThrows(superMethod, "java.lang.CloneNotSupportedException")) { return; } registerMethodError(method); }
private boolean checkMethod(final GrMethod method) { if (method.hasModifierProperty(PsiModifier.STATIC)) return false; if (method.hasModifierProperty(PsiModifier.SYNCHRONIZED)) return false; if (method.isConstructor()) return false; if (method.getContainingClass() instanceof GroovyScriptClass) return false; if (SuperMethodsSearch.search(method, null, true, false).findFirst() != null) return false; if (OverridingMethodsSearch.search(method).findFirst() != null) return false; if (ignoreMethod(method)) return false; if (myOnlyPrivateOrFinal) { if (!(method.hasModifierProperty(PsiModifier.FINAL) || method.hasModifierProperty(PsiModifier.PRIVATE))) return false; } GrOpenBlock block = method.getBlock(); if (block == null) return false; if (myIgnoreEmptyMethods && block.getStatements().length == 0) return false; PsiClass containingClass = method.getContainingClass(); if (containingClass == null) return false; if (containingClass.getContainingClass() != null && !containingClass.hasModifierProperty(PsiModifier.STATIC)) { return false; } final Condition<PsiElement>[] addins = InspectionManager.CANT_BE_STATIC_EXTENSION.getExtensions(); for (Condition<PsiElement> addin : addins) { if (addin.value(method)) { return false; } } MethodMayBeStaticVisitor visitor = new MethodMayBeStaticVisitor(); method.accept(visitor); return !visitor.haveInstanceRefsOutsideClosures(); }
private static void checkOverrideAnnotation(AnnotationHolder holder, GrModifierList list, GrMethod method) { final PsiAnnotation overrideAnnotation = list.findAnnotation("java.lang.Override"); if (overrideAnnotation == null) { return; } try { MethodSignatureBackedByPsiMethod superMethod = SuperMethodsSearch.search(method, null, true, false).findFirst(); if (superMethod == null) { holder.createWarningAnnotation(overrideAnnotation, GroovyBundle.message("method.doesnot.override.super")); } } catch (IndexNotReadyException ignored) { //nothing to do } }
private static boolean hasSuperMethods(@NotNull GrMethod method) { final GrReflectedMethod[] reflectedMethods = method.getReflectedMethods(); if (reflectedMethods.length > 0) { for (GrReflectedMethod reflectedMethod : reflectedMethods) { final MethodSignatureBackedByPsiMethod first = SuperMethodsSearch.search(reflectedMethod, null, true, false).findFirst(); if (first != null) return true; } return false; } else { return SuperMethodsSearch.search(method, null, true, false).findFirst() != null; } }
@NotNull private static List<MethodSignatureBackedByPsiMethod> findSuperMethodSignatures(PsiMethod method, PsiClass parentClass, boolean allowStaticMethod) { return new ArrayList<MethodSignatureBackedByPsiMethod>(SuperMethodsSearch.search(method, parentClass, true, allowStaticMethod).findAll()); }
@Override public String getLocationString() { if (!Registry.is("show.method.base.class.in.java.file.structure")) return null; final PsiMethod method = getElement(); if (myLocation == null) { if (isInherited()) { return super.getLocationString(); } else { try { final MethodSignatureBackedByPsiMethod baseMethod = SuperMethodsSearch.search(method, null, true, false).findFirst(); if (baseMethod != null && !method.isEquivalentTo(baseMethod.getMethod())) { PsiMethod base = baseMethod.getMethod(); PsiClass baseClass = base.getContainingClass(); if (baseClass != null /*&& !CommonClassNames.JAVA_LANG_OBJECT.equals(baseClass.getQualifiedName())*/) { if (baseClass.getMethods().length > 1) { myLocation = baseClass.getName(); } } } } catch (IndexNotReadyException e) { //some searchers (EJB) require indices. What shall we do? } if (StringUtil.isEmpty(myLocation)) { myLocation = ""; } else { char upArrow = '\u2191'; myLocation = UIUtil.getLabelFont().canDisplay(upArrow) ? upArrow + myLocation : myLocation; } } } return StringUtil.isEmpty(myLocation) ? null : myLocation; }
@Override public void visitMethod(PsiMethod method) { if (!PsiUtil.isLanguageLevel5OrHigher(method)) { return; } super.visitMethod(method); final PsiParameterList parameterList = method.getParameterList(); if (parameterList.getParametersCount() == 0) { return; } final PsiParameter[] parameters = parameterList.getParameters(); final PsiParameter lastParameter = parameters[parameters.length - 1]; final PsiType type = lastParameter.getType(); if (!(type instanceof PsiArrayType)) { return; } if (type instanceof PsiEllipsisType) { return; } final PsiArrayType arrayType = (PsiArrayType)type; final PsiType componentType = arrayType.getComponentType(); if (componentType instanceof PsiArrayType) { // don't report when it is multidimensional array return; } if (ignoreByteAndShortArrayParameters) { if (PsiType.BYTE.equals(componentType) || PsiType.SHORT.equals(componentType)) { return; } } if (LibraryUtil.isOverrideOfLibraryMethod(method)) { return; } if (ignoreOverridingMethods && SuperMethodsSearch.search(method, null, true, false).findFirst() != null) { return; } registerMethodError(method); }
@Override public void visitMethod(@NotNull PsiMethod method) { if (!CloneUtils.isClone(method)) { return; } if (method.hasModifierProperty(PsiModifier.FINAL)) { return; } final PsiClass containingClass = method.getContainingClass(); if (containingClass == null) { return; } if (containingClass.hasModifierProperty(PsiModifier.FINAL)) { return; } if (MethodUtils.hasInThrows(method, "java.lang.CloneNotSupportedException")) { return; } final MethodSignatureBackedByPsiMethod signature = SuperMethodsSearch.search(method, null, true, false).findFirst(); if (signature == null) { return; } final PsiMethod superMethod = signature.getMethod(); if (!MethodUtils.hasInThrows(superMethod, "java.lang.CloneNotSupportedException")) { return; } registerMethodError(method); }
private static boolean hasSuperMethods(GrMethod method) { final GrReflectedMethod[] reflectedMethods = method.getReflectedMethods(); for (GrReflectedMethod reflectedMethod : reflectedMethods) { final MethodSignatureBackedByPsiMethod first = SuperMethodsSearch.search(reflectedMethod, null, true, false).findFirst(); if (first != null) return true; } return false; }
public boolean checkAndAddMethod(PsiMethod method, PsiSubstitutor substitutor) { PropertyAccessorMatchLevel matchLevel = getPropertyAccessorMatchLevel(method); if(matchLevel == PropertyAccessorMatchLevel.NotAccessor) { return false; } final MethodSignature signature = method.getSignature(substitutor); final PsiMethod alreadyStoredMethod = myMethods.get(signature); if(alreadyStoredMethod != null) { for(final MethodSignatureBackedByPsiMethod methodSignature : SuperMethodsSearch.search(alreadyStoredMethod, alreadyStoredMethod.getContainingClass(), true, false).findAll()) { if(methodSignature.equals(signature)) { return true; } } } if(matchLevel.compareTo(myMatchLevel) > 0) { myMethods.clear(); myMethods.put(signature, method); myMatchLevel = matchLevel; } else if(matchLevel == myMatchLevel) { myMethods.put(signature, method); } return true; }
@Override public boolean execute(@NotNull final SuperMethodsSearch.SearchParameters queryParameters, @NotNull final Processor<MethodSignatureBackedByPsiMethod> consumer) { final PsiClass parentClass = queryParameters.getPsiClass(); final PsiMethod method = queryParameters.getMethod(); return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() { @Override public Boolean compute() { HierarchicalMethodSignature signature = method.getHierarchicalMethodSignature(); final boolean checkBases = queryParameters.isCheckBases(); final boolean allowStaticMethod = queryParameters.isAllowStaticMethod(); final List<HierarchicalMethodSignature> supers = signature.getSuperSignatures(); for(HierarchicalMethodSignature superSignature : supers) { if(MethodSignatureUtil.isSubsignature(superSignature, signature)) { if(!addSuperMethods(superSignature, method, parentClass, allowStaticMethod, checkBases, consumer)) { return false; } } } return true; } }); }
@Nullable @Override protected Boolean create(PsiMethod method) { boolean overrides = SuperMethodsSearch.search(method, null, true, false).findFirst() != null; return overrides || OverridingMethodsSearch.search(method).findFirst() != null; }
@Nullable public static MethodSignatureBackedByPsiMethod getSuperMethodSignature(@NotNull PsiMethod method) { if(method.isConstructor() || method.hasModifierProperty(PsiModifier.STATIC) || method.hasModifierProperty(PsiModifier.PRIVATE)) { return null; } return SuperMethodsSearch.search(method, null, true, false).findFirst(); }
@Override public void visitMethod(PsiMethod method) { boolean isSectionCommentsDetected = registerSectionComments(method); final TextRange range = isSectionCommentsDetected ? getElementRangeWithoutComments(method) : method.getTextRange(); ArrangementSettingsToken type = method.isConstructor() ? CONSTRUCTOR : METHOD; JavaElementArrangementEntry entry = createNewEntry(method, range, type, method.getName(), true); if(entry == null) { return; } processEntry(entry, method, method.getBody()); parseProperties(method, entry); myInfo.onMethodEntryCreated(method, entry); MethodSignatureBackedByPsiMethod overridden = SuperMethodsSearch.search(method, null, true, false).findFirst(); if(overridden != null) { myInfo.onOverriddenMethod(overridden.getMethod(), method); } boolean reset = myMethodBodyProcessor.setBaseMethod(method); try { method.accept(myMethodBodyProcessor); } finally { if(reset) { myMethodBodyProcessor.setBaseMethod(null); } } }
@Override public String getLocationString() { final PsiMethod method = getElement(); if (myLocation == null) { if (isInherited()) { return super.getLocationString(); } else { try { final MethodSignatureBackedByPsiMethod baseMethod = SuperMethodsSearch.search(method, null, true, false).findFirst(); if (baseMethod != null && !method.isEquivalentTo(baseMethod.getMethod())) { PsiMethod base = baseMethod.getMethod(); PsiClass baseClass = base.getContainingClass(); if (baseClass != null /*&& !CommonClassNames.JAVA_LANG_OBJECT.equals(baseClass.getQualifiedName())*/) { if (baseClass.getMethods().length > 1) { myLocation = baseClass.getName(); } } } } catch (IndexNotReadyException e) { //some searchers (EJB) require indices. What shall we do? } if (StringUtil.isEmpty(myLocation)) { myLocation = ""; } else { char upArrow = '\u2191'; myLocation = UIUtil.getLabelFont().canDisplay(upArrow) ? upArrow + myLocation : myLocation; } } } return StringUtil.isEmpty(myLocation) ? null : myLocation; }
@NotNull private static List<MethodSignatureBackedByPsiMethod> findSuperMethodSignatures(@NotNull PsiMethod method, PsiClass parentClass, boolean allowStaticMethod) { return new ArrayList<MethodSignatureBackedByPsiMethod>(SuperMethodsSearch.search(method, parentClass, true, allowStaticMethod).findAll()); }
public JavaCoreApplicationEnvironment(@NotNull Disposable parentDisposable) { super(parentDisposable); registerFileType(JavaClassFileType.INSTANCE, "class"); registerFileType(JavaFileType.INSTANCE, "java"); registerFileType(ArchiveFileType.INSTANCE, "jar;zip"); registerFileType(PlainTextFileType.INSTANCE, "txt;sh;bat;cmd;policy;log;cgi;MF;jad;jam;htaccess"); addExplicitExtension(LanguageASTFactory.INSTANCE, PlainTextLanguage.INSTANCE, new PlainTextASTFactory()); addExplicitExtension(LanguageParserDefinitions.INSTANCE, PlainTextLanguage.INSTANCE, new PlainTextParserDefinition()); addExplicitExtension(FileTypeFileViewProviders.INSTANCE, JavaClassFileType.INSTANCE, new ClassFileViewProviderFactory()); addExplicitExtension(BinaryFileStubBuilders.INSTANCE, JavaClassFileType.INSTANCE, new ClassFileStubBuilder()); addExplicitExtension(LanguageASTFactory.INSTANCE, JavaLanguage.INSTANCE, new CoreJavaASTFactory()); addExplicitExtension(LanguageParserDefinitions.INSTANCE, JavaLanguage.INSTANCE, new JavaParserDefinition()); addExplicitExtension(LanguageConstantExpressionEvaluator.INSTANCE, JavaLanguage.INSTANCE, new PsiExpressionEvaluator()); addExtension(ContainerProvider.EP_NAME, new JavaContainerProvider()); myApplication.registerService(PsiPackageImplementationHelper.class, new CorePsiPackageImplementationHelper()); myApplication.registerService(EmptySubstitutor.class, new EmptySubstitutorImpl()); myApplication.registerService(JavaDirectoryService.class, createJavaDirectoryService()); myApplication.registerService(JavaVersionService.class, new JavaVersionService()); addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiPackage.class, new PackagePresentationProvider()); addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiClass.class, new ClassPresentationProvider()); addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiMethod.class, new MethodPresentationProvider()); addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiField.class, new FieldPresentationProvider()); addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiLocalVariable.class, new VariablePresentationProvider()); addExplicitExtension(ItemPresentationProviders.INSTANCE, PsiParameter.class, new VariablePresentationProvider()); registerApplicationService(JavaCodeFoldingSettings.class, new JavaCodeFoldingSettingsBase()); addExplicitExtension(LanguageFolding.INSTANCE, JavaLanguage.INSTANCE, new JavaFoldingBuilderBase() { @Override protected boolean shouldShowExplicitLambdaType(PsiAnonymousClass anonymousClass, PsiNewExpression expression) { return false; } @Override protected boolean isBelowRightMargin(Project project, int lineLength) { return false; } }); registerApplicationExtensionPoint(SuperMethodsSearch.EP_NAME, QueryExecutor.class); addExtension(SuperMethodsSearch.EP_NAME, new MethodSuperSearcher()); }
private static boolean isOverrides(PsiMethod method) { return SuperMethodsSearch.search(method, null, true, false).findFirst() != null; }
@Override @Nullable public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) { PsiElement parent; if (element instanceof PsiIdentifier && (parent = element.getParent()) instanceof PsiMethod) { PsiMethod method = (PsiMethod)parent; MethodSignatureBackedByPsiMethod superSignature = SuperMethodsSearch.search(method, null, true, false).findFirst(); if (superSignature != null) { boolean overrides = method.hasModifierProperty(PsiModifier.ABSTRACT) == superSignature.getMethod().hasModifierProperty(PsiModifier.ABSTRACT); final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod; return createSuperMethodLineMarkerInfo(element, icon, Pass.UPDATE_ALL); } } final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(element); final PsiElement firstChild = element.getFirstChild(); if (interfaceMethod != null && firstChild != null) { return createSuperMethodLineMarkerInfo(firstChild, AllIcons.Gutter.ImplementingFunctional, Pass.UPDATE_ALL); } if (myDaemonSettings.SHOW_METHOD_SEPARATORS && firstChild == null) { PsiElement element1 = element; boolean isMember = false; while (element1 != null && !(element1 instanceof PsiFile) && element1.getPrevSibling() == null) { element1 = element1.getParent(); if (element1 instanceof PsiMember) { isMember = true; break; } } if (isMember && !(element1 instanceof PsiAnonymousClass || element1.getParent() instanceof PsiAnonymousClass)) { PsiFile file = element1.getContainingFile(); Document document = file == null ? null : PsiDocumentManager.getInstance(file.getProject()).getLastCommittedDocument(file); boolean drawSeparator = false; if (document != null) { CharSequence documentChars = document.getCharsSequence(); int category = getCategory(element1, documentChars); for (PsiElement child = element1.getPrevSibling(); child != null; child = child.getPrevSibling()) { int category1 = getCategory(child, documentChars); if (category1 == 0) continue; drawSeparator = category != 1 || category1 != 1; break; } } if (drawSeparator) { LineMarkerInfo info = new LineMarkerInfo<PsiElement>(element, element.getTextRange(), null, Pass.UPDATE_ALL, FunctionUtil.<Object, String>nullConstant(), null, GutterIconRenderer.Alignment.RIGHT); EditorColorsScheme scheme = myColorsManager.getGlobalScheme(); info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR); info.separatorPlacement = SeparatorPlacement.TOP; return info; } } } return null; }
@Override public void visitInlineDocTag(PsiInlineDocTag tag) { @NonNls final String name = tag.getName(); if (!"inheritDoc".equals(name)) { return; } final PsiDocComment docComment = tag.getContainingComment(); if (docComment == null) { return; } final PsiDocCommentOwner owner = docComment.getOwner(); if (owner instanceof PsiField) { registerError(tag, WarningType.FIELD); return; } else if (owner instanceof PsiClass) { registerError(tag, WarningType.CLASS); return; } else if (owner instanceof PsiMethod) { final PsiMethod method = (PsiMethod)owner; if (method.isConstructor()) { registerError(tag, WarningType.CONSTRUCTOR); return; } final MethodSignatureBackedByPsiMethod superMethod = SuperMethodsSearch.search(method, method.getContainingClass(), true, false).findFirst(); if (superMethod == null) { registerError(tag, WarningType.NO_SUPER); return; } } else { return; } final PsiElement parent = tag.getParent(); if (parent instanceof PsiDocTag) { final PsiDocTag docTag = (PsiDocTag)parent; final String docTagName = docTag.getName(); if ((docTagName.equals("throws") || docTagName.equals("exception")) && !isCheckExceptionAndPresentInThrowsList((PsiMethod)owner, docTag)) { return; } } final PsiDocToken[] docTokens = PsiTreeUtil.getChildrenOfType(parent, PsiDocToken.class); if (docTokens == null) { return; } for (PsiDocToken docToken : docTokens) { final IElementType tokenType = docToken.getTokenType(); if (!JavaDocTokenType.DOC_COMMENT_DATA.equals(tokenType)) { continue; } if (!StringUtil.isEmptyOrSpaces(docToken.getText())) { return; } } registerError(tag, WarningType.EMPTY); }
public static boolean hasSuper(@NotNull PsiMethod method) { if (method.isConstructor() || method.hasModifierProperty(PsiModifier.STATIC) || method.hasModifierProperty(PsiModifier.PRIVATE)) { return false; } return SuperMethodsSearch.search(method, null, true, false).findFirst() != null; }
private static boolean isOverriddenOrOverrides(PsiMethod method) { boolean overrides = SuperMethodsSearch.search(method, null, true, false).findFirst() != null; return overrides || OverridingMethodsSearch.search(method).findFirst() != null; }