mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: prevent warnings on broken/incomplete code (IDEA-176304)
This commit is contained in:
+39
-75
@@ -43,27 +43,21 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor {
|
||||
return onTheFly;
|
||||
}
|
||||
|
||||
protected final void registerNewExpressionError(
|
||||
@NotNull PsiNewExpression expression, Object... infos) {
|
||||
final PsiJavaCodeReferenceElement classReference =
|
||||
expression.getClassOrAnonymousClassReference();
|
||||
protected final void registerNewExpressionError(@NotNull PsiNewExpression expression, Object... infos) {
|
||||
final PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference();
|
||||
if (classReference == null) {
|
||||
registerError(expression, infos);
|
||||
}
|
||||
else {
|
||||
registerError(classReference, infos);
|
||||
return;
|
||||
}
|
||||
registerError(classReference, infos);
|
||||
}
|
||||
|
||||
protected final void registerMethodCallError(@NotNull PsiMethodCallExpression expression, @NonNls Object... infos) {
|
||||
final PsiReferenceExpression methodExpression = expression.getMethodExpression();
|
||||
final PsiElement nameToken = methodExpression.getReferenceNameElement();
|
||||
if (nameToken == null) {
|
||||
registerError(expression, infos);
|
||||
}
|
||||
else {
|
||||
registerError(nameToken, infos);
|
||||
return;
|
||||
}
|
||||
registerError(nameToken, infos);
|
||||
}
|
||||
|
||||
protected final void registerStatementError(@NotNull PsiStatement statement, Object... infos) {
|
||||
@@ -77,8 +71,7 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor {
|
||||
}
|
||||
|
||||
protected final void registerModuleError(@NotNull PsiJavaModule module, Object... infos) {
|
||||
final PsiJavaModuleReferenceElement identifier = module.getNameIdentifier();
|
||||
registerError(identifier, infos);
|
||||
registerError(module.getNameIdentifier(), infos);
|
||||
}
|
||||
|
||||
protected final void registerClassError(@NotNull PsiClass aClass, Object... infos) {
|
||||
@@ -96,67 +89,40 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor {
|
||||
nameIdentifier = aClass.getNameIdentifier();
|
||||
}
|
||||
if (nameIdentifier == null) {
|
||||
registerError(aClass.getContainingFile(), infos);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
registerError(nameIdentifier, infos);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void registerMethodError(@NotNull PsiMethod method,
|
||||
Object... infos) {
|
||||
final PsiElement nameIdentifier = method.getNameIdentifier();
|
||||
if (nameIdentifier == null) {
|
||||
final LocalQuickFix[] fixes = createAndInitFixes(infos);
|
||||
final String description = inspection.buildErrorString(infos);
|
||||
|
||||
final TextRange methodTextRange;
|
||||
PsiCodeBlock body = method.getBody();
|
||||
if (body != null) {
|
||||
methodTextRange = new TextRange(0, body.getStartOffsetInParent());
|
||||
}
|
||||
else {
|
||||
methodTextRange = new TextRange(0, method.getTextLength());
|
||||
}
|
||||
|
||||
holder.registerProblem(method, methodTextRange, description, fixes);
|
||||
}
|
||||
else {
|
||||
registerError(nameIdentifier, infos);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void registerVariableError(@NotNull PsiVariable variable,
|
||||
Object... infos) {
|
||||
final PsiElement nameIdentifier = variable.getNameIdentifier();
|
||||
if (nameIdentifier == null) {
|
||||
registerError(variable, infos);
|
||||
}
|
||||
else {
|
||||
registerError(nameIdentifier, infos);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void registerTypeParameterError(
|
||||
@NotNull PsiTypeParameter typeParameter, Object... infos) {
|
||||
final PsiElement nameIdentifier = typeParameter.getNameIdentifier();
|
||||
if (nameIdentifier == null) {
|
||||
registerError(typeParameter, infos);
|
||||
}
|
||||
else {
|
||||
registerError(nameIdentifier, infos);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void registerFieldError(@NotNull PsiField field,
|
||||
Object... infos) {
|
||||
final PsiElement nameIdentifier = field.getNameIdentifier();
|
||||
registerError(nameIdentifier, infos);
|
||||
}
|
||||
|
||||
protected final void registerModifierError(
|
||||
@NotNull String modifier, @NotNull PsiModifierListOwner parameter,
|
||||
Object... infos) {
|
||||
protected final void registerMethodError(@NotNull PsiMethod method, Object... infos) {
|
||||
final PsiElement nameIdentifier = method.getNameIdentifier();
|
||||
if (nameIdentifier == null) {
|
||||
return;
|
||||
}
|
||||
registerError(nameIdentifier, infos);
|
||||
}
|
||||
|
||||
protected final void registerVariableError(@NotNull PsiVariable variable, Object... infos) {
|
||||
final PsiElement nameIdentifier = variable.getNameIdentifier();
|
||||
if (nameIdentifier == null) {
|
||||
return;
|
||||
}
|
||||
registerError(nameIdentifier, infos);
|
||||
}
|
||||
|
||||
protected final void registerTypeParameterError(@NotNull PsiTypeParameter typeParameter, Object... infos) {
|
||||
final PsiElement nameIdentifier = typeParameter.getNameIdentifier();
|
||||
if (nameIdentifier == null) {
|
||||
return;
|
||||
}
|
||||
registerError(nameIdentifier, infos);
|
||||
}
|
||||
|
||||
protected final void registerFieldError(@NotNull PsiField field, Object... infos) {
|
||||
registerError(field.getNameIdentifier(), infos);
|
||||
}
|
||||
|
||||
protected final void registerModifierError(@NotNull String modifier, @NotNull PsiModifierListOwner parameter, Object... infos) {
|
||||
final PsiModifierList modifiers = parameter.getModifierList();
|
||||
if (modifiers == null) {
|
||||
return;
|
||||
@@ -170,8 +136,7 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
protected final void registerClassInitializerError(
|
||||
@NotNull PsiClassInitializer initializer, Object... infos) {
|
||||
protected final void registerClassInitializerError(@NotNull PsiClassInitializer initializer, Object... infos) {
|
||||
final PsiCodeBlock body = initializer.getBody();
|
||||
final PsiJavaToken lBrace = body.getLBrace();
|
||||
if (lBrace == null) {
|
||||
@@ -182,8 +147,7 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
protected final void registerError(@NotNull PsiElement location,
|
||||
Object... infos) {
|
||||
protected final void registerError(@NotNull PsiElement location, Object... infos) {
|
||||
registerError(location, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, infos);
|
||||
}
|
||||
|
||||
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package com.siyeh.igtest.classlayout;
|
||||
|
||||
public abstract class NonProtectedConstructorInAbstractClassInspection
|
||||
{
|
||||
public NonProtectedConstructorInAbstractClassInspection()
|
||||
{
|
||||
}
|
||||
private NonProtectedConstructorInAbstractClassInspection(int foo)
|
||||
{
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package com.siyeh.igtest.classlayout;
|
||||
|
||||
public abstract class NonProtectedConstructorInAbstractClassInspection2 {
|
||||
protected NonProtectedConstructorInAbstractClassInspection2() {
|
||||
this(2);
|
||||
}
|
||||
|
||||
private NonProtectedConstructorInAbstractClassInspection2(int foo) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.siyeh.igtest.classlayout;
|
||||
|
||||
public abstract class NonProtectedConstructorInAbstractClass
|
||||
{
|
||||
public <warning descr="Constructor 'NonProtectedConstructorInAbstractClass()' is not declared 'protected' in 'abstract' class">NonProtectedConstructorInAbstractClass</warning>()
|
||||
{
|
||||
}
|
||||
private NonProtectedConstructorInAbstractClass(int foo)
|
||||
{
|
||||
}
|
||||
|
||||
public <error descr="Illegal type: 'void'">void</error>();
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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 com.siyeh.ig.inheritance;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.siyeh.ig.LightInspectionTestCase;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
public class NonProtectedConstructorInAbstractClassInspectionTest extends LightInspectionTestCase {
|
||||
|
||||
public void testNonProtectedConstructorInAbstractClass() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected InspectionProfileEntry getInspection() {
|
||||
return new NonProtectedConstructorInAbstractClassInspection();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user