moved inspections to groovy-psi

This commit is contained in:
Alexey Kudravtsev
2014-05-23 17:13:33 +04:00
parent 7c078e9b94
commit 76c0e946d2
130 changed files with 2163 additions and 1574 deletions
@@ -16,6 +16,7 @@
package com.intellij.codeInsight.intention;
import com.intellij.codeInsight.daemon.QuickFixActionRegistrar;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
import com.intellij.codeInspection.LocalQuickFixOnPsiElement;
import com.intellij.openapi.components.ServiceManager;
@@ -146,8 +147,8 @@ public abstract class QuickFixFactory {
@NotNull public abstract IntentionAction createRenameFileFix(@NotNull String newName);
@NotNull public abstract IntentionAction createRenameElementFix(@NotNull PsiNamedElement element);
@NotNull public abstract IntentionAction createRenameElementFix(@NotNull PsiNamedElement element, @NotNull String newName);
@NotNull public abstract LocalQuickFixAndIntentionActionOnPsiElement createRenameElementFix(@NotNull PsiNamedElement element);
@NotNull public abstract LocalQuickFixAndIntentionActionOnPsiElement createRenameElementFix(@NotNull PsiNamedElement element, @NotNull String newName);
@NotNull public abstract IntentionAction createChangeExtendsToImplementsFix(@NotNull PsiClass aClass, @NotNull PsiClassType classToExtendFrom);
@@ -246,4 +247,8 @@ public abstract class QuickFixFactory {
@NotNull
public abstract IntentionAction createSafeDeleteFix(@NotNull PsiElement element);
@Nullable
public abstract List<LocalQuickFix> registerOrderEntryFixes(@NotNull QuickFixActionRegistrar registrar,
@NotNull PsiReference reference);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -79,7 +79,7 @@ public abstract class OrderEntryFix implements IntentionAction, LocalQuickFix {
}
@Nullable
public static List<LocalQuickFix> registerFixes(@NotNull QuickFixActionRegistrar registrar, final PsiReference reference) {
public static List<LocalQuickFix> registerFixes(@NotNull QuickFixActionRegistrar registrar, @NotNull final PsiReference reference) {
final PsiElement psiElement = reference.getElement();
@NonNls final String referenceName = reference.getRangeInElement().substring(psiElement.getText());
@@ -121,13 +121,13 @@ public abstract class OrderEntryFix implements IntentionAction, LocalQuickFix {
@Override
public void invoke(@NotNull Project project, @Nullable Editor editor, PsiFile file) {
if (isJunit4) {
final VirtualFile location = PsiUtilCore.getVirtualFile(reference != null ? reference.getElement() : null);
final VirtualFile location = PsiUtilCore.getVirtualFile(reference.getElement());
boolean inTests = location != null && ModuleRootManager.getInstance(currentModule).getFileIndex().isInTestSourceContent(location);
try {
addJUnit4Library(inTests, currentModule);
final GlobalSearchScope scope = GlobalSearchScope.moduleWithLibrariesScope(currentModule);
final PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(className, scope);
if (aClass != null && editor != null && reference != null) {
if (aClass != null && editor != null) {
new AddImportAction(project, reference, editor, aClass).execute();
}
}
@@ -381,13 +381,13 @@ public class QuickFixFactoryImpl extends QuickFixFactory {
@NotNull
@Override
public IntentionAction createRenameElementFix(@NotNull PsiNamedElement element) {
public LocalQuickFixAndIntentionActionOnPsiElement createRenameElementFix(@NotNull PsiNamedElement element) {
return new RenameElementFix(element);
}
@NotNull
@Override
public IntentionAction createRenameElementFix(@NotNull PsiNamedElement element, @NotNull String newName) {
public LocalQuickFixAndIntentionActionOnPsiElement createRenameElementFix(@NotNull PsiNamedElement element, @NotNull String newName) {
return new RenameElementFix(element, newName);
}
@@ -707,6 +707,12 @@ public class QuickFixFactoryImpl extends QuickFixFactory {
return new SafeDeleteFix(element);
}
@Nullable
@Override
public List<LocalQuickFix> registerOrderEntryFixes(@NotNull QuickFixActionRegistrar registrar, @NotNull PsiReference reference) {
return OrderEntryFix.registerFixes(registrar, reference);
}
public static void invokeOnTheFlyImportOptimizer(@NotNull final Runnable runnable,
@NotNull final PsiFile file,
@NotNull final Editor editor) {
@@ -739,7 +745,7 @@ public class QuickFixFactoryImpl extends QuickFixFactory {
DaemonCodeAnalyzerEx codeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(file.getProject());
// dont optimize out imports in JSP since it can be included in other JSP
if (file == null || !codeAnalyzer.isHighlightingAvailable(file) || !(file instanceof PsiJavaFile) || file instanceof ServerPageFile) return false;
if (!codeAnalyzer.isHighlightingAvailable(file) || !(file instanceof PsiJavaFile) || file instanceof ServerPageFile) return false;
if (!codeAnalyzer.isErrorAnalyzingFinished(file)) return false;
boolean errors = containsErrorsPreventingOptimize(file);
@@ -19,10 +19,10 @@ import com.intellij.codeInsight.completion.JavaClassNameCompletionContributor;
import com.intellij.codeInsight.completion.JavaLookupElementBuilder;
import com.intellij.codeInsight.completion.scope.JavaCompletionProcessor;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.quickfix.OrderEntryFix;
import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction;
import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixActionRegistrarImpl;
import com.intellij.codeInsight.daemon.quickFix.CreateClassOrPackageFix;
import com.intellij.codeInsight.intention.QuickFixFactory;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.codeInspection.LocalQuickFix;
@@ -476,7 +476,7 @@ public class JavaClassReference extends GenericReference implements PsiJavaRefer
@Nullable
private List<? extends LocalQuickFix> registerFixes(HighlightInfo info) {
final List<LocalQuickFix> list = OrderEntryFix.registerFixes(new QuickFixActionRegistrarImpl(info), this);
final List<LocalQuickFix> list = QuickFixFactory.getInstance().registerOrderEntryFixes(new QuickFixActionRegistrarImpl(info), this);
final String[] extendClasses = getExtendClassNames();
final String extendClass = extendClasses != null && extendClasses.length > 0 ? extendClasses[0] : null;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -17,47 +17,43 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightBundle;
import com.intellij.codeInsight.FileModificationService;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
import com.intellij.lang.LanguageNamesValidation;
import com.intellij.lang.refactoring.NamesValidator;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiNamedElement;
import com.intellij.refactoring.rename.RenameProcessor;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author ven
*/
public class RenameElementFix implements IntentionAction, LocalQuickFix {
public class RenameElementFix extends LocalQuickFixAndIntentionActionOnPsiElement {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.quickfix.RenameFileFix");
private final PsiNamedElement myElement;
private final String myNewName;
private final String myText;
public RenameElementFix(@NotNull PsiNamedElement element) {
myElement = element;
final VirtualFile vFile = myElement.getContainingFile().getVirtualFile();
super(element);
final VirtualFile vFile = element.getContainingFile().getVirtualFile();
assert vFile != null : element;
myNewName = vFile.getNameWithoutExtension();
myText = CodeInsightBundle.message("rename.public.class.text", myElement.getName(), myNewName);
myText = CodeInsightBundle.message("rename.public.class.text", element.getName(), myNewName);
}
public RenameElementFix(@NotNull PsiNamedElement element, @NotNull String newName) {
myElement = element;
super(element);
myNewName = newName;
myText = CodeInsightBundle.message("rename.named.element.text", myElement.getName(), myNewName);
myText = CodeInsightBundle.message("rename.named.element.text", element.getName(), myNewName);
}
@Override
@@ -66,12 +62,6 @@ public class RenameElementFix implements IntentionAction, LocalQuickFix {
return myText;
}
@Override
@NotNull
public String getName() {
return getText();
}
@Override
@NotNull
public String getFamilyName() {
@@ -79,34 +69,36 @@ public class RenameElementFix implements IntentionAction, LocalQuickFix {
}
@Override
public void applyFix(@NotNull final Project project, @NotNull ProblemDescriptor descriptor) {
final PsiFile file = descriptor.getPsiElement().getContainingFile();
public void invoke(@NotNull final Project project,
@NotNull final PsiFile file,
@Nullable("is null when called from inspection") Editor editor,
@NotNull final PsiElement startElement,
@NotNull PsiElement endElement) {
if (isAvailable(project, null, file)) {
new WriteCommandAction(project) {
@Override
protected void run(Result result) throws Throwable {
invoke(project, FileEditorManager.getInstance(project).getSelectedTextEditor(), file);
protected void run(@NotNull Result result) throws Throwable {
LOG.assertTrue(file == startElement.getContainingFile());
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
RenameProcessor processor = new RenameProcessor(project, startElement, myNewName, false, false);
processor.run();
}
}.execute();
}
}
@Override
public boolean isAvailable(@NotNull Project project, @Nullable Editor editor, PsiFile file) {
if (!myElement.isValid()) {
public boolean isAvailable(@NotNull Project project,
@NotNull PsiFile file,
@NotNull PsiElement startElement,
@NotNull PsiElement endElement) {
if (!startElement.isValid()) {
return false;
}
final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(file.getLanguage());
return namesValidator != null && namesValidator.isIdentifier(myNewName, project);
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
LOG.assertTrue(file == myElement.getContainingFile());
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
RenameProcessor processor = new RenameProcessor(project, myElement, myNewName, false, false);
processor.run();
}
@Override
public boolean startInWriteAction() {
@@ -1483,6 +1483,8 @@
<selectInTarget implementation="org.jetbrains.plugins.groovy.mvc.projectView.MvcProjectViewSelectInTarget"/>
<applicationService serviceImplementation="org.jetbrains.plugins.groovy.mvc.MvcRunTargetHistoryService"
serviceInterface="org.jetbrains.plugins.groovy.mvc.MvcRunTargetHistoryService"/>
<applicationService serviceInterface="org.jetbrains.plugins.groovy.codeInspection.GroovyQuickFixFactory"
serviceImplementation="org.jetbrains.plugins.groovy.codeInspection.GroovyQuickFixFactoryImpl"/>
<debugger.positionManagerFactory id="groovyPositionManager"
implementation="org.jetbrains.plugins.groovy.debugger.GroovyPositionManagerFactory"/>
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -0,0 +1,80 @@
/*
* Copyright 2000-2014 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;
import com.intellij.codeInsight.daemon.impl.quickfix.CreateClassKind;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiType;
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
import org.jetbrains.plugins.groovy.lang.psi.api.util.GrVariableDeclarationOwner;
public abstract class GroovyQuickFixFactory {
public static GroovyQuickFixFactory getInstance() {
return ServiceManager.getService(GroovyQuickFixFactory.class);
}
public abstract IntentionAction createDynamicMethodFix(GrReferenceExpression expression, PsiType[] types);
public abstract IntentionAction createDynamicPropertyFix(GrReferenceExpression expression);
public abstract IntentionAction createGroovyAddImportAction(GrReferenceElement element);
public abstract IntentionAction createClassFromNewAction(GrNewExpression parent);
public abstract IntentionAction createClassFixAction(GrReferenceElement element, CreateClassKind anInterface);
public abstract IntentionAction createCreateFieldFromUsageFix(GrReferenceExpression expr);
public abstract IntentionAction createCreateGetterFromUsageFix(GrReferenceExpression expr, PsiClass aClass);
public abstract IntentionAction createCreateSetterFromUsageFix(GrReferenceExpression expr);
public abstract IntentionAction createCreateMethodFromUsageFix(GrReferenceExpression expr);
public abstract IntentionAction createCreateLocalVariableFromUsageFix(GrReferenceExpression expr, GrVariableDeclarationOwner owner);
public abstract IntentionAction createCreateParameterFromUsageFix(GrReferenceExpression expr);
public abstract IntentionAction createGroovyStaticImportMethodFix(GrMethodCall parent);
public abstract GroovyFix createRenameFix();
public abstract GroovyFix createReplaceWithImportFix();
public abstract LocalQuickFix createGrMoveToDirFix(String actual);
public abstract LocalQuickFix createCreateFieldFromConstructorLabelFix(GrTypeDefinition element, GrNamedArgument argument);
public abstract LocalQuickFix createDynamicPropertyFix(GrArgumentLabel label, PsiClass element);
public abstract GroovyFix createAddMethodFix(String methodName, GrTypeDefinition aClass);
public abstract GroovyFix createAddClassToExtendsFix(GrTypeDefinition aClass, String comparable);
public abstract IntentionAction createOptimizeImportsFix(boolean onTheFly);
public abstract IntentionAction createRemoveUnusedGrParameterFix(GrParameter parameter);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -22,10 +22,9 @@ import com.intellij.psi.util.InheritanceUtil;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.GroovyBundle;
import org.jetbrains.plugins.groovy.annotator.intentions.CreateFieldFromConstructorLabelFix;
import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicPropertyFix;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspection;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.codeInspection.GroovyQuickFixFactory;
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
@@ -139,10 +138,10 @@ public class GroovyConstructorNamedArgumentsInspection extends BaseInspection {
List<LocalQuickFix> fixes = new ArrayList<LocalQuickFix>(2);
if (element instanceof GrTypeDefinition) {
fixes.add(new CreateFieldFromConstructorLabelFix((GrTypeDefinition)element, label.getNamedArgument()));
fixes.add(GroovyQuickFixFactory.getInstance().createCreateFieldFromConstructorLabelFix((GrTypeDefinition)element, label.getNamedArgument()));
}
if (element instanceof PsiClass) {
fixes.add(new DynamicPropertyFix(label, (PsiClass)element));
fixes.add(GroovyQuickFixFactory.getInstance().createDynamicPropertyFix(label, (PsiClass)element));
}
registerError(label, GroovyBundle.message("no.such.property", label.getName()), fixes.toArray(new LocalQuickFix[fixes.size()]),
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -0,0 +1,153 @@
/*
* Copyright 2000-2014 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.bugs;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.*;
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.arithmetic.GrRangeExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
import org.jetbrains.plugins.groovy.lang.psi.impl.GrRangeType;
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author Maxim.Medvedev
*/
public class GroovyRangeTypeCheckInspection extends BaseInspection {
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new MyVisitor();
}
@Nls
@NotNull
@Override
public String getGroupDisplayName() {
return PROBABLE_BUGS;
}
@Nls
@NotNull
@Override
public String getDisplayName() {
return GroovyInspectionBundle.message("incorrect.range.argument");
}
@Override
protected GroovyFix buildFix(@NotNull PsiElement location) {
final GrRangeExpression range = (GrRangeExpression)location;
final PsiType type = range.getType();
final List<GroovyFix> fixes = new ArrayList<GroovyFix>(3);
if (type instanceof GrRangeType) {
PsiType iterationType = ((GrRangeType)type).getIterationType();
if (!(iterationType instanceof PsiClassType)) return null;
final PsiClass psiClass = ((PsiClassType)iterationType).resolve();
if (!(psiClass instanceof GrTypeDefinition)) return null;
final GroovyResolveResult[] nexts = ResolveUtil.getMethodCandidates(iterationType, "next", range);
final GroovyResolveResult[] previouses = ResolveUtil.getMethodCandidates(iterationType, "previous", range);
final GroovyResolveResult[] compareTos = ResolveUtil.getMethodCandidates(iterationType, "compareTo", range, iterationType);
if (countImplementations(psiClass, nexts)==0) {
fixes.add(GroovyQuickFixFactory.getInstance().createAddMethodFix("next", (GrTypeDefinition)psiClass));
}
if (countImplementations(psiClass, previouses) == 0) {
fixes.add(GroovyQuickFixFactory.getInstance().createAddMethodFix("previous", (GrTypeDefinition)psiClass));
}
if (!InheritanceUtil.isInheritor(iterationType, CommonClassNames.JAVA_LANG_COMPARABLE) ||
countImplementations(psiClass, compareTos) == 0) {
fixes.add(GroovyQuickFixFactory.getInstance().createAddClassToExtendsFix((GrTypeDefinition)psiClass, CommonClassNames.JAVA_LANG_COMPARABLE));
}
return new GroovyFix() {
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
for (GroovyFix fix : fixes) {
fix.applyFix(project, descriptor);
}
}
@NotNull
@Override
public String getName() {
return GroovyInspectionBundle.message("fix.class", psiClass.getName());
}
};
}
return null;
}
private static int countImplementations(PsiClass clazz, GroovyResolveResult[] methods) {
if (clazz.isInterface()) return methods.length;
int result = 0;
for (GroovyResolveResult method : methods) {
final PsiElement el = method.getElement();
if (el instanceof PsiMethod && !((PsiMethod)el).hasModifierProperty(PsiModifier.ABSTRACT)) result++;
else if (el instanceof PsiField) result++;
}
return result;
}
@Override
protected String buildErrorString(Object... args) {
switch (args.length) {
case 1:
return GroovyInspectionBundle.message("type.doesnt.implemnt.comparable", args);
case 2:
return GroovyInspectionBundle.message("type.doesnt.contain.method", args);
default:
throw new IncorrectOperationException("incorrect args:" + Arrays.toString(args));
}
}
private static class MyVisitor extends BaseInspectionVisitor {
@Override
public void visitRangeExpression(GrRangeExpression range) {
super.visitRangeExpression(range);
final PsiType type = range.getType();
if (!(type instanceof GrRangeType)) return;
final PsiType iterationType = ((GrRangeType)type).getIterationType();
if (iterationType == null) return;
final GroovyResolveResult[] nexts = ResolveUtil.getMethodCandidates(iterationType, "next", range, PsiType.EMPTY_ARRAY);
final GroovyResolveResult[] previouses = ResolveUtil.getMethodCandidates(iterationType, "previous", range, PsiType.EMPTY_ARRAY);
if (nexts.length == 0) {
registerError(range, iterationType.getPresentableText(), "next()");
}
if (previouses.length == 0) {
registerError(range, iterationType.getPresentableText(), "previous()");
}
if (!InheritanceUtil.isInheritor(iterationType, CommonClassNames.JAVA_LANG_COMPARABLE)) {
registerError(range, iterationType.getPresentableText());
}
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -28,10 +28,10 @@ import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.GroovyBundle;
import org.jetbrains.plugins.groovy.annotator.intentions.GrMoveToDirFix;
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.codeInspection.GroovyQuickFixFactory;
import org.jetbrains.plugins.groovy.lang.psi.GrNamedElement;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
@@ -96,7 +96,7 @@ public class GrPackageInspection extends BaseInspection {
if (toHighlight == null) return;
registerError(toHighlight, "Package name mismatch. Actual: '" + actual + "', expected: '" + expectedPackage+"'",
new LocalQuickFix[]{new ChangePackageQuickFix(expectedPackage), new GrMoveToDirFix(actual)},
new LocalQuickFix[]{new ChangePackageQuickFix(expectedPackage), GroovyQuickFixFactory.getInstance().createGrMoveToDirFix(actual)},
ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
@@ -18,7 +18,7 @@ package org.jetbrains.plugins.groovy.codeInspection.confusing;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.diagnostic.LogMessageEx;
import com.intellij.openapi.diagnostic.Attachment;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
@@ -104,7 +104,7 @@ public class GrUnusedIncDecInspection extends BaseInspection {
final Instruction cur = ControlFlowUtils.findInstruction(operand, owner.getControlFlow());
if (cur == null) {
LogMessageEx.error(LOG, "no instruction found in flow." + "operand: " + operand.getText(), owner.getText());
LOG.error("no instruction found in flow." + "operand: " + operand.getText(), new Attachment("", owner.getText()));
}
//get write access for inc or dec
@@ -0,0 +1,199 @@
/*
* Copyright 2000-2014 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.psi.PsiElement;
import com.intellij.psi.PsiType;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspection;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression;
import java.util.HashSet;
import java.util.Set;
public class GroovyOverlyComplexArithmeticExpressionInspectionBase extends BaseInspection {
private static final int TERM_LIMIT = 3;
/**
* @noinspection PublicField,WeakerAccess
*/
public int m_limit = TERM_LIMIT;
@Override
@NotNull
public String getDisplayName() {
return "Overly complex arithmetic expression";
}
@Override
@NotNull
public String getGroupDisplayName() {
return CONFUSING_CODE_CONSTRUCTS;
}
private int getLimit() {
return m_limit;
}
@Override
protected String buildErrorString(Object... args) {
return "Overly complex arithmetic expression #loc";
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new Visitor();
}
private class Visitor extends BaseInspectionVisitor {
private final Set<IElementType> arithmeticTokens = new HashSet<IElementType>(5);
{
arithmeticTokens.add(GroovyTokenTypes.mPLUS);
arithmeticTokens.add(GroovyTokenTypes.mMINUS);
arithmeticTokens.add(GroovyTokenTypes.mSTAR);
arithmeticTokens.add(GroovyTokenTypes.mDIV);
arithmeticTokens.add(GroovyTokenTypes.mMOD);
}
@Override
public void visitBinaryExpression(@NotNull GrBinaryExpression expression) {
super.visitBinaryExpression(expression);
checkExpression(expression);
}
@Override
public void visitUnaryExpression(@NotNull GrUnaryExpression expression) {
super.visitUnaryExpression(expression);
checkExpression(expression);
}
@Override
public void visitParenthesizedExpression(GrParenthesizedExpression expression) {
super.visitParenthesizedExpression(expression);
checkExpression(expression);
}
private void checkExpression(GrExpression expression) {
if (isParentArithmetic(expression)) {
return;
}
if (!isArithmetic(expression)) {
return;
}
if (containsStringConcatenation(expression)) {
return;
}
final int numTerms = countTerms(expression);
if (numTerms <= getLimit()) {
return;
}
registerError(expression);
}
private int countTerms(GrExpression expression) {
if (expression == null) {
return 0;
}
if (!isArithmetic(expression)) {
return 1;
}
if (expression instanceof GrBinaryExpression) {
final GrBinaryExpression binaryExpression = (GrBinaryExpression) expression;
final GrExpression lhs = binaryExpression.getLeftOperand();
final GrExpression rhs = binaryExpression.getRightOperand();
return countTerms(lhs) + countTerms(rhs);
} else if (expression instanceof GrUnaryExpression) {
final GrUnaryExpression unaryExpression = (GrUnaryExpression) expression;
final GrExpression operand = unaryExpression.getOperand();
return countTerms(operand);
} else if (expression instanceof GrParenthesizedExpression) {
final GrParenthesizedExpression parenthesizedExpression = (GrParenthesizedExpression) expression;
final GrExpression contents = parenthesizedExpression.getOperand();
return countTerms(contents);
}
return 1;
}
private boolean isParentArithmetic(GrExpression expression) {
final PsiElement parent = expression.getParent();
if (!(parent instanceof GrExpression)) {
return false;
}
return isArithmetic((GrExpression) parent);
}
private boolean isArithmetic(GrExpression expression) {
if (expression instanceof GrBinaryExpression) {
final GrBinaryExpression binaryExpression = (GrBinaryExpression) expression;
final IElementType sign = binaryExpression.getOperationTokenType();
return arithmeticTokens.contains(sign);
} else if (expression instanceof GrUnaryExpression) {
final GrUnaryExpression unaryExpression = (GrUnaryExpression) expression;
final IElementType sign = unaryExpression.getOperationTokenType();
return arithmeticTokens.contains(sign);
} else if (expression instanceof GrParenthesizedExpression) {
final GrParenthesizedExpression parenthesizedExpression = (GrParenthesizedExpression) expression;
final GrExpression contents = parenthesizedExpression.getOperand();
return isArithmetic(contents);
}
return false;
}
private boolean containsStringConcatenation(GrExpression expression) {
if (isString(expression)) {
return true;
}
if (expression instanceof GrBinaryExpression) {
final GrBinaryExpression binaryExpression = (GrBinaryExpression) expression;
final GrExpression lhs = binaryExpression.getLeftOperand();
if (containsStringConcatenation(lhs)) {
return true;
}
final GrExpression rhs = binaryExpression.getRightOperand();
return containsStringConcatenation(rhs);
} else if (expression instanceof GrUnaryExpression) {
final GrUnaryExpression unaryExpression = (GrUnaryExpression) expression;
final GrExpression operand = unaryExpression.getOperand();
return containsStringConcatenation(operand);
} else if (expression instanceof GrParenthesizedExpression) {
final GrParenthesizedExpression parenthesizedExpression = (GrParenthesizedExpression) expression;
final GrExpression contents = parenthesizedExpression.getOperand();
return containsStringConcatenation(contents);
}
return false;
}
private boolean isString(GrExpression expression) {
if (expression == null) {
return false;
}
final PsiType type = expression.getType();
if (type == null) {
return false;
}
return "java.lang.String".equals(type.getCanonicalText());
}
}
}
@@ -0,0 +1,146 @@
/*
* Copyright 2000-2014 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.psi.PsiElement;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspection;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression;
public class GroovyOverlyComplexBooleanExpressionInspectionBase extends BaseInspection {
private static final int TERM_LIMIT = 3;
/**
* @noinspection PublicField,WeakerAccess
*/
public int m_limit = TERM_LIMIT;
@Override
@NotNull
public String getDisplayName() {
return "Overly complex boolean expression";
}
@Override
@NotNull
public String getGroupDisplayName() {
return CONFUSING_CODE_CONSTRUCTS;
}
private int getLimit() {
return m_limit;
}
@Override
protected String buildErrorString(Object... args) {
return "Overly complex boolean expression #loc";
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new Visitor();
}
private class Visitor extends BaseInspectionVisitor {
@Override
public void visitBinaryExpression(@NotNull GrBinaryExpression expression) {
super.visitBinaryExpression(expression);
checkExpression(expression);
}
@Override
public void visitUnaryExpression(@NotNull GrUnaryExpression expression) {
super.visitUnaryExpression(expression);
checkExpression(expression);
}
@Override
public void visitParenthesizedExpression(GrParenthesizedExpression expression) {
super.visitParenthesizedExpression(expression);
checkExpression(expression);
}
private void checkExpression(GrExpression expression) {
if (!isBoolean(expression)) {
return;
}
if (isParentBoolean(expression)) {
return;
}
final int numTerms = countTerms(expression);
if (numTerms <= getLimit()) {
return;
}
registerError(expression);
}
private int countTerms(GrExpression expression) {
if (expression == null) {
return 0;
}
if (!isBoolean(expression)) {
return 1;
}
if (expression instanceof GrBinaryExpression) {
final GrBinaryExpression binaryExpression = (GrBinaryExpression) expression;
final GrExpression lhs = binaryExpression.getLeftOperand();
final GrExpression rhs = binaryExpression.getRightOperand();
return countTerms(lhs) + countTerms(rhs);
} else if (expression instanceof GrUnaryExpression) {
final GrUnaryExpression prefixExpression = (GrUnaryExpression) expression;
final GrExpression operand = prefixExpression.getOperand();
return countTerms(operand);
} else if (expression instanceof GrParenthesizedExpression) {
final GrParenthesizedExpression parenthesizedExpression = (GrParenthesizedExpression) expression;
final GrExpression contents = parenthesizedExpression.getOperand();
return countTerms(contents);
}
return 1;
}
private boolean isParentBoolean(GrExpression expression) {
final PsiElement parent = expression.getParent();
if (!(parent instanceof GrExpression)) {
return false;
}
return isBoolean((GrExpression) parent);
}
private boolean isBoolean(GrExpression expression) {
if (expression instanceof GrBinaryExpression) {
final GrBinaryExpression binaryExpression = (GrBinaryExpression) expression;
final IElementType sign = binaryExpression.getOperationTokenType();
return GroovyTokenTypes.mLAND.equals(sign) ||
GroovyTokenTypes.mLOR.equals(sign);
} else if (expression instanceof GrUnaryExpression) {
final GrUnaryExpression prefixExpression = (GrUnaryExpression) expression;
final IElementType sign = prefixExpression.getOperationTokenType();
return GroovyTokenTypes.mLNOT.equals(sign);
} else if (expression instanceof GrParenthesizedExpression) {
final GrParenthesizedExpression parenthesizedExpression = (GrParenthesizedExpression) expression;
final GrExpression contents = parenthesizedExpression.getOperand();
return isBoolean(contents);
}
return false;
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -15,22 +15,11 @@
*/
package org.jetbrains.plugins.groovy.codeInspection.confusing;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspection;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.codeInspection.GroovyFix;
import org.jetbrains.plugins.groovy.codeInspection.GroovyInspectionBundle;
import org.jetbrains.plugins.groovy.codeStyle.GrReferenceAdjuster;
import org.jetbrains.plugins.groovy.codeStyle.GroovyCodeStyleSettings;
import org.jetbrains.plugins.groovy.lang.psi.GrQualifiedReference;
import org.jetbrains.plugins.groovy.codeInspection.*;
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
@@ -40,12 +29,13 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrRefere
import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement;
import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition;
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyCodeStyleSettingsFacade;
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
/**
* @author Max Medvedev
*/
public class UnnecessaryQualifiedReferenceInspection extends BaseInspection {
private static final Logger LOG = Logger.getInstance(UnnecessaryQualifiedReferenceInspection.class);
@NotNull
@Override
@@ -118,20 +108,7 @@ public class UnnecessaryQualifiedReferenceInspection extends BaseInspection {
@Override
protected GroovyFix buildFix(@NotNull PsiElement location) {
return new GroovyFix() {
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
final PsiElement startElement = descriptor.getStartElement();
LOG.assertTrue(startElement instanceof GrReferenceElement<?>);
GrReferenceAdjuster.shortenReference((GrQualifiedReference<?>)startElement);
}
@NotNull
@Override
public String getName() {
return GroovyInspectionBundle.message("replace.qualified.name.with.import");
}
};
return GroovyQuickFixFactory.getInstance().createReplaceWithImportFix();
}
@Override
@@ -146,7 +123,7 @@ public class UnnecessaryQualifiedReferenceInspection extends BaseInspection {
if (PsiTreeUtil.getParentOfType(element, GrImportStatement.class, GrPackageDefinition.class) != null) return false;
}
else if (element instanceof GrReferenceExpression) {
if (!GrReferenceAdjuster.seemsToBeQualifiedClassName((GrReferenceExpression)element)) return false;
if (!PsiImplUtil.seemsToBeQualifiedClassName((GrReferenceExpression)element)) return false;
}
else {
return false;
@@ -172,14 +149,10 @@ public class UnnecessaryQualifiedReferenceInspection extends BaseInspection {
final PsiClass containingClass = ((PsiClass)resolved).getContainingClass();
if (containingClass != null &&
!CodeStyleSettingsManager.getSettings(resolved.getProject()).getCustomSettings(GroovyCodeStyleSettings.class).INSERT_INNER_CLASS_IMPORTS) {
!GroovyCodeStyleSettingsFacade.getInstance(containingClass.getProject()).insertInnerClassImports()) {
return false;
}
if (resolveResult.getElement() == null || !resolveResult.isAccessible() || !resolveResult.isStaticsOK()) {
return true;
}
return false;
return resolveResult.getElement() == null || !resolveResult.isAccessible() || !resolveResult.isStaticsOK();
}
}
@@ -0,0 +1,91 @@
/*
* Copyright 2000-2014 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.control;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspection;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
public class GroovyIfStatementWithTooManyBranchesInspectionBase extends BaseInspection {
private static final int DEFAULT_BRANCH_LIMIT = 3;
/**
* @noinspection PublicField,WeakerAccess
*/
public int m_limit = DEFAULT_BRANCH_LIMIT; //this is public for the DefaultJDOMExternalizer thingy
private static int calculateNumBranches(GrIfStatement statement) {
final GrStatement branch = statement.getElseBranch();
if (branch == null) {
return 1;
}
if (!(branch instanceof GrIfStatement)) {
return 2;
}
return 1 + calculateNumBranches((GrIfStatement) branch);
}
@Override
@NotNull
public String getDisplayName() {
return "If statement with too many branches";
}
@Override
@NotNull
public String getGroupDisplayName() {
return CONTROL_FLOW;
}
private int getLimit() {
return m_limit;
}
@Override
protected String buildErrorString(Object... args) {
final GrIfStatement statement = (GrIfStatement) args[0];
final int branches = calculateNumBranches(statement);
return "'#ref' statement with too many branches (" + branches + ") #loc";
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new Visitor();
}
private class Visitor extends BaseInspectionVisitor {
@Override
public void visitIfStatement(@NotNull GrIfStatement statement) {
super.visitIfStatement(statement);
final PsiElement parent = statement.getParent();
if (parent instanceof GrIfStatement) {
final GrIfStatement parentStatement = (GrIfStatement) parent;
final GrStatement elseBranch = parentStatement.getElseBranch();
if (statement.equals(elseBranch)) {
return;
}
}
final int branches = calculateNumBranches(statement);
if (branches <= getLimit()) {
return;
}
registerStatementError(statement, statement);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -15,7 +15,7 @@
*/
package org.jetbrains.plugins.groovy.codeInspection.exception;
import com.intellij.codeInsight.daemon.impl.quickfix.RenameElementFix;
import com.intellij.codeInsight.intention.QuickFixFactory;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
@@ -82,8 +82,9 @@ public class GroovyEmptyCatchBlockInspection extends BaseInspection {
if (parameter == null) return;
if (myIgnore && GrExceptionUtil.ignore(parameter)) return;
LocalQuickFix fix = QuickFixFactory.getInstance().createRenameElementFix(parameter, "ignored");
final LocalQuickFix[] fixes = myIgnore
? new RenameElementFix[]{new RenameElementFix(parameter, "ignored")}
? new LocalQuickFix[]{fix}
: LocalQuickFix.EMPTY_ARRAY;
registerError(catchClause.getFirstChild(), "Empty '#ref' block #loc", fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
@@ -15,7 +15,7 @@
*/
package org.jetbrains.plugins.groovy.codeInspection.exception;
import com.intellij.codeInsight.daemon.impl.quickfix.RenameElementFix;
import com.intellij.codeInsight.intention.QuickFixFactory;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.psi.PsiElement;
@@ -70,7 +70,7 @@ public class GroovyUnusedCatchParameterInspection extends BaseInspection {
block.accept(visitor);
if (!visitor.isUsed()) {
final PsiElement nameIdentifier = parameter.getNameIdentifierGroovy();
registerError(nameIdentifier, "Unused catch parameter '#ref' #loc", new LocalQuickFix[]{new RenameElementFix(parameter, "ignored")},
registerError(nameIdentifier, "Unused catch parameter '#ref' #loc", new LocalQuickFix[]{QuickFixFactory.getInstance().createRenameElementFix(parameter, "ignored")},
ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
@@ -17,9 +17,6 @@
package org.jetbrains.plugins.groovy.codeInspection.local;
import com.intellij.codeHighlighting.TextEditorHighlightingPass;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.FileModificationService;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInsight.daemon.impl.*;
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
@@ -29,22 +26,13 @@ import com.intellij.codeInsight.intention.QuickFixFactory;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
import com.intellij.diagnostic.AttachmentFactory;
import com.intellij.diagnostic.LogMessageEx;
import com.intellij.lang.annotation.Annotation;
import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.lang.annotation.AnnotationSession;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.command.undo.UndoManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
@@ -53,14 +41,13 @@ import com.intellij.psi.*;
import com.intellij.psi.impl.PsiClassImplUtil;
import com.intellij.psi.search.searches.OverridingMethodsSearch;
import com.intellij.psi.search.searches.SuperMethodsSearch;
import com.intellij.util.DocumentUtil;
import com.intellij.util.Processor;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.GroovyInspectionBundle;
import org.jetbrains.plugins.groovy.codeInspection.GroovyQuickFixFactory;
import org.jetbrains.plugins.groovy.codeInspection.GroovySuppressableInspectionTool;
import org.jetbrains.plugins.groovy.codeInspection.GroovyUnusedDeclarationInspection;
import org.jetbrains.plugins.groovy.editor.GroovyImportOptimizer;
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyImportUtil;
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
import org.jetbrains.plugins.groovy.lang.psi.GrNamedElement;
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
@@ -81,12 +68,10 @@ import java.util.*;
* @author ilyas
*/
public class GroovyPostHighlightingPass extends TextEditorHighlightingPass {
private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.codeInspection.local.GroovyPostHighlightingPass");
private final GroovyFile myFile;
private final Editor myEditor;
private volatile Set<GrImportStatement> myUnusedImports;
private volatile Runnable myOptimizeRunnable;
private volatile List<HighlightInfo> myUnusedDeclarations;
public GroovyPostHighlightingPass(GroovyFile file, Editor editor) {
@@ -180,7 +165,7 @@ public class GroovyPostHighlightingPass extends TextEditorHighlightingPass {
}
});
final Set<GrImportStatement> unusedImports = new HashSet<GrImportStatement>(PsiUtil.getValidImportStatements(myFile));
unusedImports.removeAll(GroovyImportOptimizer.findUsedImports(myFile));
unusedImports.removeAll(GroovyImportUtil.findUsedImports(myFile));
myUnusedImports = unusedImports;
if (deadCodeEnabled) {
@@ -194,7 +179,7 @@ public class GroovyPostHighlightingPass extends TextEditorHighlightingPass {
PsiElement identifier = parameter.getNameIdentifierGroovy();
HighlightInfo highlightInfo = PostHighlightingPass
.createUnusedSymbolInfo(identifier, "Parameter " + parameter.getName() + " is unused", HighlightInfoType.UNUSED_SYMBOL);
QuickFixAction.registerQuickFixAction(highlightInfo, new RemoveUnusedGrParameterFix(parameter), unusedDefKey);
QuickFixAction.registerQuickFixAction(highlightInfo, GroovyQuickFixFactory.getInstance().createRemoveUnusedGrParameterFix(parameter), unusedDefKey);
ContainerUtil.addIfNotNull(unusedDeclarations, highlightInfo);
}
}
@@ -204,21 +189,6 @@ public class GroovyPostHighlightingPass extends TextEditorHighlightingPass {
}
}
myUnusedDeclarations = unusedDeclarations;
if (!unusedImports.isEmpty() && CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY) {
final VirtualFile vfile = myFile.getVirtualFile();
if (vfile != null && ProjectRootManager.getInstance(myFile.getProject()).getFileIndex().isInSource(vfile)) {
final GrImportStatement[] imports = myFile.getImportStatements();
if (imports.length > 0) {
final int offset = myEditor.getCaretModel().getOffset();
if (imports[0].getTextRange().getStartOffset() <= offset && offset <= imports[imports.length - 1].getTextRange().getEndOffset()) {
return;
}
}
myOptimizeRunnable = new GroovyImportOptimizer().processFile(myFile);
}
}
}
private static boolean methodMayHaveUnusedParameters(GrMethod method) {
@@ -256,41 +226,6 @@ public class GroovyPostHighlightingPass extends TextEditorHighlightingPass {
return overrides || OverridingMethodsSearch.search(method).findFirst() != null;
}
private static IntentionAction createUnusedImportIntention() {
return new IntentionAction() {
@Override
@NotNull
public String getText() {
return GroovyInspectionBundle.message("optimize.all.imports");
}
@Override
@NotNull
public String getFamilyName() {
return GroovyInspectionBundle.message("optimize.imports");
}
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
return true;
}
@Override
public void invoke(@NotNull final Project project, Editor editor, PsiFile file) {
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
final Runnable runnable = new GroovyImportOptimizer().processFile(file);
CommandProcessor.getInstance().executeCommand(project, runnable, "optimize imports", this);
}
@Override
public boolean startInWriteAction() {
return true;
}
};
}
@Override
public void doApplyInformationToEditor() {
if (myUnusedDeclarations == null || myUnusedImports == null) {
@@ -302,48 +237,18 @@ public class GroovyPostHighlightingPass extends TextEditorHighlightingPass {
for (GrImportStatement unusedImport : myUnusedImports) {
Annotation annotation = annotationHolder.createWarningAnnotation(calculateRangeToUse(unusedImport), GroovyInspectionBundle.message("unused.import"));
annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL);
annotation.registerFix(createUnusedImportIntention());
annotation.registerFix(GroovyQuickFixFactory.getInstance().createOptimizeImportsFix(false));
infos.add(HighlightInfo.fromAnnotation(annotation));
}
UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), infos, getColorsScheme(), getId());
final Runnable optimize = myOptimizeRunnable;
if (optimize != null && timeToOptimizeImports()) {
invokeOnTheFlyImportOptimizer(new Runnable() {
@Override
public void run() {
optimize.run();
}
}, myFile, myEditor);
}
}
public static void invokeOnTheFlyImportOptimizer(@NotNull final Runnable runnable,
@NotNull final PsiFile file,
@NotNull final Editor editor) {
final long stamp = editor.getDocument().getModificationStamp();
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (file.getProject().isDisposed() || editor.isDisposed() || editor.getDocument().getModificationStamp() != stamp) return;
//no need to optimize imports on the fly during undo/redo
final UndoManager undoManager = UndoManager.getInstance(editor.getProject());
if (undoManager.isUndoInProgress() || undoManager.isRedoInProgress()) return;
PsiDocumentManager.getInstance(file.getProject()).commitAllDocuments();
String beforeText = file.getText();
final long oldStamp = editor.getDocument().getModificationStamp();
DocumentUtil.writeInRunUndoTransparentAction(runnable);
if (oldStamp != editor.getDocument().getModificationStamp()) {
String afterText = file.getText();
if (Comparing.strEqual(beforeText, afterText)) {
LOG.error(
LogMessageEx.createEvent("Import optimizer hasn't optimized any imports", file.getViewProvider().getVirtualFile().getPath(),
AttachmentFactory.createAttachment(file.getViewProvider().getVirtualFile())));
}
}
if (myUnusedImports != null && !myUnusedImports.isEmpty()) {
IntentionAction fix = GroovyQuickFixFactory.getInstance().createOptimizeImportsFix(true);
if (fix.isAvailable(myProject, myEditor, myFile) && myFile.isWritable()) {
fix.invoke(myProject, myEditor, myFile);
}
});
}
}
@@ -361,41 +266,6 @@ public class GroovyPostHighlightingPass extends TextEditorHighlightingPass {
return new TextRange(start, range.getEndOffset());
}
private boolean timeToOptimizeImports() {
if (!CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY) return false;
DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(myProject);
if (!codeAnalyzer.isHighlightingAvailable(myFile)) return false;
if (!codeAnalyzer.isErrorAnalyzingFinished(myFile)) return false;
boolean errors = containsErrorsPreventingOptimize();
return !errors && DaemonListeners.canChangeFileSilently(myFile);
}
private boolean containsErrorsPreventingOptimize() {
// ignore unresolved imports errors
final TextRange ignoreRange;
final GrImportStatement[] imports = myFile.getImportStatements();
if (imports.length != 0) {
final int start = imports[0].getTextRange().getStartOffset();
final int end = imports[imports.length - 1].getTextRange().getEndOffset();
ignoreRange = new TextRange(start, end);
} else {
ignoreRange = TextRange.EMPTY_RANGE;
}
return !DaemonCodeAnalyzerEx
.processHighlights(myDocument, myProject, HighlightSeverity.ERROR, 0, myDocument.getTextLength(), new Processor<HighlightInfo>() {
@Override
public boolean process(HighlightInfo error) {
int infoStart = error.getActualStartOffset();
int infoEnd = error.getActualEndOffset();
return ignoreRange.containsRange(infoStart, infoEnd) && error.type.equals(HighlightInfoType.WRONG_REF);
}
});
}
}
@@ -17,9 +17,6 @@ package org.jetbrains.plugins.groovy.codeInspection.metrics;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspection;
import org.jetbrains.plugins.groovy.codeInspection.utils.SingleIntegerFieldOptionsPanel;
import javax.swing.*;
public abstract class GroovyMethodMetricInspection extends BaseInspection {
@@ -33,10 +30,4 @@ public abstract class GroovyMethodMetricInspection extends BaseInspection {
protected int getLimit() {
return m_limit;
}
@Override
public JComponent createOptionsPanel() {
final String configurationLabel = getConfigurationLabel();
return new SingleIntegerFieldOptionsPanel(configurationLabel, this, "m_limit");
}
}
@@ -0,0 +1,72 @@
/*
* Copyright 2000-2014 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.metrics;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.codeInspection.utils.LibraryUtil;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
public class GroovyMethodParameterCountInspectionBase extends GroovyMethodMetricInspection {
@Override
@NotNull
public String getDisplayName() {
return "Method with too many parameters";
}
@Override
@NotNull
public String getGroupDisplayName() {
return METHOD_METRICS;
}
@Override
protected int getDefaultLimit() {
return 5;
}
@Override
protected String getConfigurationLabel() {
return "Maximum number of parameters:";
}
@Override
public String buildErrorString(Object... args) {
return "Method '#ref' contains too many parameters (" + args[0] + '>' + args[1] + ')';
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new Visitor();
}
private class Visitor extends BaseInspectionVisitor {
@Override
public void visitMethod(GrMethod grMethod) {
super.visitMethod(grMethod);
final GrParameter[] parameters = grMethod.getParameters();
final int limit = getLimit();
if (parameters == null || parameters.length <= limit) {
return;
}
if (LibraryUtil.isOverrideOfLibraryMethod(grMethod)) {
return;
}
registerMethodError(grMethod, parameters.length, limit);
}
}
}
@@ -0,0 +1,111 @@
/*
* Copyright 2000-2014 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.metrics;
import com.intellij.psi.PsiType;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
public class GroovyMultipleReturnPointsPerMethodInspectionBase extends GroovyMethodMetricInspection {
@Override
@Nls
@NotNull
public String getGroupDisplayName() {
return METHOD_METRICS;
}
@Override
@NotNull
public String getDisplayName() {
return "Method with multiple return points";
}
@Override
protected int getDefaultLimit() {
return 1;
}
@Override
protected String getConfigurationLabel() {
return "Return point limit:";
}
@Override
@NotNull
public String buildErrorString(Object... infos) {
final Integer returnPointCount = (Integer) infos[0];
return "<code>#ref</code> has " + returnPointCount + " return points #loc";
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new MultipleReturnPointsVisitor();
}
private class MultipleReturnPointsVisitor extends BaseInspectionVisitor {
@Override
public void visitMethod(@NotNull GrMethod method) {
// note: no call to super
if (method.getNameIdentifier() == null) {
return;
}
final int returnPointCount = calculateReturnPointCount(method);
if (returnPointCount <= getLimit()) {
return;
}
registerMethodError(method, Integer.valueOf(returnPointCount));
}
private int calculateReturnPointCount(GrMethod method) {
final ReturnPointCountVisitor visitor =
new ReturnPointCountVisitor();
method.accept(visitor);
final int count = visitor.getCount();
if (!mayFallThroughBottom(method)) {
return count;
}
final GrCodeBlock body = method.getBlock();
if (body == null) {
return count;
}
final GrStatement[] statements = body.getStatements();
if (statements.length == 0) {
return count + 1;
}
final GrStatement lastStatement =
statements[statements.length - 1];
if (ControlFlowUtils.statementMayCompleteNormally(lastStatement)) {
return count + 1;
}
return count;
}
private boolean mayFallThroughBottom(GrMethod method) {
if (method.isConstructor()) {
return true;
}
final PsiType returnType = method.getReturnType();
return PsiType.VOID.equals(returnType);
}
}
}
@@ -0,0 +1,74 @@
/*
* Copyright 2000-2014 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.metrics;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
public class GroovyOverlyComplexMethodInspectionBase extends GroovyMethodMetricInspection {
@Override
@NotNull
public String getDisplayName() {
return "Overly complex method";
}
@Override
@NotNull
public String getGroupDisplayName() {
return METHOD_METRICS;
}
@Override
protected int getDefaultLimit() {
return 10;
}
@Override
protected String getConfigurationLabel() {
return "Method complexity limit:";
}
@Override
public String buildErrorString(Object... args) {
return "Method '#ref' is overly complex ( cyclomatic complexity =" + args[0] + '>' + args[1] + ')';
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new Visitor();
}
private class Visitor extends BaseInspectionVisitor {
@Override
public void visitMethod(GrMethod grMethod) {
super.visitMethod(grMethod);
final int limit = getLimit();
final CyclomaticComplexityVisitor visitor = new CyclomaticComplexityVisitor();
final GrOpenBlock body = grMethod.getBlock();
if (body == null) {
return;
}
body.accept(visitor);
final int complexity = visitor.getComplexity();
if (complexity <= limit) {
return;
}
registerMethodError(grMethod, complexity, limit);
}
}
}
@@ -0,0 +1,72 @@
/*
* Copyright 2000-2014 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.metrics;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
public class GroovyOverlyLongMethodInspectionBase extends GroovyMethodMetricInspection {
@Override
@NotNull
public String getDisplayName() {
return "Overly long method";
}
@Override
@NotNull
public String getGroupDisplayName() {
return METHOD_METRICS;
}
@Override
protected int getDefaultLimit() {
return 30;
}
@Override
protected String getConfigurationLabel() {
return "Maximum statements per method:";
}
@Override
public String buildErrorString(Object... args) {
return "Method '#ref' is too long ( statement count =" + args[0] + '>' + args[1] + ')';
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new Visitor();
}
private class Visitor extends BaseInspectionVisitor {
@Override
public void visitMethod(GrMethod method) {
super.visitMethod(method);
final int limit = getLimit();
final StatementCountVisitor visitor = new StatementCountVisitor();
final GrOpenBlock block = method.getBlock();
if (block == null) return;
block.accept(visitor);
final int statementCount = visitor.getStatementCount();
if (statementCount <= limit) {
return;
}
registerMethodError(method, statementCount, limit);
}
}
}
@@ -0,0 +1,74 @@
/*
* Copyright 2000-2014 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.metrics;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
public class GroovyOverlyNestedMethodInspectionBase extends GroovyMethodMetricInspection {
@Override
@NotNull
public String getDisplayName() {
return "Overly nested method";
}
@Override
@NotNull
public String getGroupDisplayName() {
return METHOD_METRICS;
}
@Override
protected int getDefaultLimit() {
return 5;
}
@Override
protected String getConfigurationLabel() {
return "Maximum nesting depth:";
}
@Override
public String buildErrorString(Object... args) {
return "Method '#ref' is overly nested ( nesting depth =" + args[0] + '>' + args[1] + ')';
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new Visitor();
}
private class Visitor extends BaseInspectionVisitor {
@Override
public void visitMethod(GrMethod grMethod) {
super.visitMethod(grMethod);
final int limit = getLimit();
final NestingDepthVisitor visitor = new NestingDepthVisitor();
final GrOpenBlock body = grMethod.getBlock();
if (body == null) {
return;
}
body.accept(visitor);
final int nestingDepth = visitor.getMaximumDepth();
if (nestingDepth <= limit) {
return;
}
registerMethodError(grMethod, nestingDepth, limit);
}
}
}
@@ -19,6 +19,7 @@ import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.codeInspection.GroovyFix;
import org.jetbrains.plugins.groovy.codeInspection.GroovyQuickFixFactory;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnnotationTypeDefinition;
public class GroovyAnnotationNamingConventionInspection extends ConventionInspection {
@@ -34,7 +35,7 @@ public class GroovyAnnotationNamingConventionInspection extends ConventionInspec
@Override
protected GroovyFix buildFix(@NotNull PsiElement location) {
return new RenameFix();
return GroovyQuickFixFactory.getInstance().createRenameFix();
}
@Override
@@ -19,6 +19,7 @@ import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.codeInspection.GroovyFix;
import org.jetbrains.plugins.groovy.codeInspection.GroovyQuickFixFactory;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrClassDefinition;
public class GroovyClassNamingConventionInspection extends ConventionInspection {
@@ -34,7 +35,7 @@ public class GroovyClassNamingConventionInspection extends ConventionInspection
@Override
protected GroovyFix buildFix(@NotNull PsiElement location) {
return new RenameFix();
return GroovyQuickFixFactory.getInstance().createRenameFix();
}
@Override
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiModifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.codeInspection.GroovyFix;
import org.jetbrains.plugins.groovy.codeInspection.GroovyQuickFixFactory;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
public class GroovyConstantNamingConventionInspection extends ConventionInspection {
@@ -35,7 +36,7 @@ public class GroovyConstantNamingConventionInspection extends ConventionInspecti
@Override
protected GroovyFix buildFix(PsiElement location) {
return new RenameFix();
return GroovyQuickFixFactory.getInstance().createRenameFix();
}
@Override
@@ -19,6 +19,7 @@ import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.codeInspection.GroovyFix;
import org.jetbrains.plugins.groovy.codeInspection.GroovyQuickFixFactory;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumTypeDefinition;
public class GroovyEnumerationNamingConventionInspection extends ConventionInspection {
@@ -34,7 +35,7 @@ public class GroovyEnumerationNamingConventionInspection extends ConventionInspe
@Override
protected GroovyFix buildFix(@NotNull PsiElement location) {
return new RenameFix();
return GroovyQuickFixFactory.getInstance().createRenameFix();
}
@Override
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiModifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.codeInspection.GroovyFix;
import org.jetbrains.plugins.groovy.codeInspection.GroovyQuickFixFactory;
import org.jetbrains.plugins.groovy.codeInspection.utils.LibraryUtil;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
@@ -36,7 +37,7 @@ public class GroovyInstanceMethodNamingConventionInspection extends ConventionIn
@Override
protected GroovyFix buildFix(PsiElement location) {
return new RenameFix();
return GroovyQuickFixFactory.getInstance().createRenameFix();
}
@Override
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiModifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
import org.jetbrains.plugins.groovy.codeInspection.GroovyFix;
import org.jetbrains.plugins.groovy.codeInspection.GroovyQuickFixFactory;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
public class GroovyInstanceVariableNamingConventionInspection extends ConventionInspection {
@@ -35,7 +36,7 @@ public class GroovyInstanceVariableNamingConventionInspection extends Convention
@Override
protected GroovyFix buildFix(PsiElement location) {
return new RenameFix();
return GroovyQuickFixFactory.getInstance().createRenameFix();
}
@Override

Some files were not shown because too many files have changed in this diff Show More