mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-83355 Deprecated objects do not show as strikethrough in groovy code.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
This inspection reports usages of deprecated code in Groovy
|
||||
</body>
|
||||
</html>
|
||||
@@ -599,6 +599,9 @@
|
||||
<localInspection language="Groovy" groupPath="Groovy" shortName="ClashingGetters" bundle="org.jetbrains.plugins.groovy.codeInspection.GroovyInspectionBundle"
|
||||
key="clashing.getters" groupName="Potentially confusing code constructs" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="org.jetbrains.plugins.groovy.codeInspection.confusing.ClashingGettersInspection"/>
|
||||
<localInspection language="Groovy" groupPath="Groovy" shortName="GrDeprecatedAPIUsage" bundle="org.jetbrains.plugins.groovy.codeInspection.GroovyInspectionBundle"
|
||||
key="gr.deprecated.api.usage" groupName="Potentially confusing code constructs" enabledByDefault="true" level="WARNING"
|
||||
implementationClass="org.jetbrains.plugins.groovy.codeInspection.confusing.GrDeprecatedAPIUsageInspection"/>
|
||||
<localInspection language="Groovy" groupPath="Groovy" shortName="GroovyNestedConditional" displayName="Nested conditional expression"
|
||||
groupName="Potentially confusing code constructs" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="org.jetbrains.plugins.groovy.codeInspection.confusing.GroovyNestedConditionalInspection"/>
|
||||
|
||||
@@ -304,3 +304,4 @@ primitive.bound.types.are.not.allowed=Primitive bound types are not allowed
|
||||
ellipsis.type.is.not.allowed.here=Ellipsis type is not allowed here
|
||||
method.0.is.too.complex.too.analyze=Method ''{0}'' is too complex to analyze.\nTypes of local variables are not inferred.
|
||||
closure.is.too.complex.to.analyze=Closure is complex to analyze.\nTypes of local variables are not inferred.
|
||||
0.is.deprecated=''{0}'' is deprecated
|
||||
|
||||
+1
@@ -83,3 +83,4 @@ unused.0=Unused {0}
|
||||
remove.0=Remove {0}
|
||||
replace.postfix.0.with.prefix.0=Replace postfix {0} with prefix {0}
|
||||
replace.0.with.1=Replace {0} with binary {1}
|
||||
gr.deprecated.api.usage=Deprecated API inspection
|
||||
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.codeInspection.confusing;
|
||||
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemHighlightType;
|
||||
import com.intellij.psi.PsiDocCommentOwner;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import com.intellij.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.GroovyBundle;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.BaseInspection;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.GroovyInspectionBundle;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class GrDeprecatedAPIUsageInspection extends BaseInspection {
|
||||
@Override
|
||||
public boolean isEnabledByDefault() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
public String getGroupDisplayName() {
|
||||
return CONFUSING_CODE_CONSTRUCTS;
|
||||
}
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return GroovyInspectionBundle.message("gr.deprecated.api.usage");
|
||||
}
|
||||
|
||||
@NonNls
|
||||
@NotNull
|
||||
public String getShortName() {
|
||||
return "GrDeprecatedAPIUsage";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BaseInspectionVisitor buildVisitor() {
|
||||
return new BaseInspectionVisitor() {
|
||||
@Override
|
||||
public void visitReferenceExpression(GrReferenceExpression ref) {
|
||||
super.visitReferenceExpression(ref);
|
||||
checkRef(ref);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitCodeReferenceElement(GrCodeReferenceElement ref) {
|
||||
super.visitCodeReferenceElement(ref);
|
||||
checkRef(ref);
|
||||
}
|
||||
|
||||
private void checkRef(GrReferenceElement ref) {
|
||||
PsiElement resolved = ref.resolve();
|
||||
if (isDeprecated(resolved)) {
|
||||
PsiElement toHighlight = getElementToHighlight(ref);
|
||||
registerError(toHighlight, GroovyBundle.message("0.is.deprecated", ref.getReferenceName()), LocalQuickFix.EMPTY_ARRAY,
|
||||
ProblemHighlightType.LIKE_DEPRECATED);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PsiElement getElementToHighlight(@NotNull GrReferenceElement refElement) {
|
||||
final PsiElement refNameElement = refElement.getReferenceNameElement();
|
||||
return refNameElement != null ? refNameElement : refElement;
|
||||
}
|
||||
|
||||
|
||||
private boolean isDeprecated(PsiElement resolved) {
|
||||
if (resolved instanceof PsiDocCommentOwner && PsiImplUtil.isDeprecatedByDocTag((PsiDocCommentOwner)resolved)) {
|
||||
return true;
|
||||
}
|
||||
if (resolved instanceof PsiModifierListOwner && PsiImplUtil.isDeprecatedByAnnotation((PsiModifierListOwner)resolved)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+19
-4
@@ -36,10 +36,6 @@ import org.jetbrains.plugins.groovy.codeInspection.GroovyUnusedDeclarationInspec
|
||||
import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyResultOfAssignmentUsedInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyUncheckedAssignmentOfMemberOfRawTypeInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.confusing.ClashingGettersInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.confusing.GrUnusedIncDecInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.confusing.GroovyOctalIntegerInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.confusing.GroovyResultOfIncrementOrDecrementUsedInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.control.GroovyTrivialConditionalInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.control.GroovyTrivialIfInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.control.GroovyUnnecessaryReturnInspection
|
||||
@@ -50,6 +46,7 @@ import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.Groov
|
||||
import org.jetbrains.plugins.groovy.codeInspection.unusedDef.UnusedDefInspection
|
||||
import org.jetbrains.plugins.groovy.util.TestUtils
|
||||
import org.jetbrains.plugins.groovy.codeInspection.bugs.*
|
||||
import org.jetbrains.plugins.groovy.codeInspection.confusing.*
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -710,4 +707,22 @@ public class CorrectImplementor implements ActionListener {
|
||||
public void testReassignedHighlighting() {
|
||||
myFixture.testHighlighting(true, true, true, getTestName(false) + ".groovy");
|
||||
}
|
||||
|
||||
public void testDeprecated() {
|
||||
myFixture.configureByText('_a.groovy', '''\
|
||||
/**
|
||||
@deprecated
|
||||
*/
|
||||
class X {
|
||||
@Deprecated
|
||||
def foo(){}
|
||||
|
||||
public static void main() {
|
||||
new <warning descr="'X' is deprecated">X</warning>().<warning descr="'foo' is deprecated">foo</warning>()
|
||||
}
|
||||
}''')
|
||||
|
||||
myFixture.enableInspections(GrDeprecatedAPIUsageInspection)
|
||||
myFixture.testHighlighting(true, false, false)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user