moved to analysis

This commit is contained in:
Alexey Kudravtsev
2013-07-09 15:53:04 +04:00
parent 17c7473bff
commit 8801671ffd
122 changed files with 1344 additions and 953 deletions
@@ -0,0 +1,51 @@
/*
* Copyright 2000-2013 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.
*/
/*
* User: anna
* Date: 19-Dec-2007
*/
package com.intellij.codeInspection;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.reference.RefManager;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class GlobalJavaBatchInspectionTool extends GlobalInspectionTool implements BatchSuppressableTool {
@Override
public boolean queryExternalUsagesRequests(@NotNull final InspectionManager manager,
@NotNull final GlobalInspectionContext globalContext,
@NotNull final ProblemDescriptionsProcessor problemDescriptionsProcessor) {
return queryExternalUsagesRequests(globalContext.getRefManager(), globalContext.getExtension(GlobalJavaInspectionContext.CONTEXT), problemDescriptionsProcessor);
}
protected boolean queryExternalUsagesRequests(@NotNull RefManager manager, @NotNull GlobalJavaInspectionContext globalContext, @NotNull ProblemDescriptionsProcessor processor) {
return false;
}
@NotNull
@Override
public SuppressQuickFix[] getBatchSuppressActions(@Nullable PsiElement element) {
return BatchSuppressManager.SERVICE.getInstance().createBatchSuppressActions(HighlightDisplayKey.find(getShortName()));
}
@Override
public boolean isSuppressedFor(@NotNull final PsiElement element) {
return BatchSuppressManager.SERVICE.getInstance().isSuppressedFor(element, getShortName());
}
}
@@ -0,0 +1,100 @@
/*
* Copyright 2000-2009 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.
*/
/*
* User: anna
* Date: 18-Dec-2007
*/
package com.intellij.codeInspection;
import com.intellij.codeInspection.ex.EntryPointsManager;
import com.intellij.codeInspection.lang.GlobalInspectionContextExtension;
import com.intellij.codeInspection.reference.RefClass;
import com.intellij.codeInspection.reference.RefField;
import com.intellij.codeInspection.reference.RefManager;
import com.intellij.codeInspection.reference.RefMethod;
import com.intellij.openapi.util.Key;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiReference;
import com.intellij.util.Processor;
import org.jetbrains.annotations.NotNull;
public abstract class GlobalJavaInspectionContext implements GlobalInspectionContextExtension<GlobalJavaInspectionContext> {
public static final Key<GlobalJavaInspectionContext> CONTEXT = Key.create("GlobalJavaInspectionContext");
public interface DerivedClassesProcessor extends Processor<PsiClass> {
}
public interface DerivedMethodsProcessor extends Processor<PsiMethod> {
}
public interface UsagesProcessor extends Processor<PsiReference> {
}
/**
* Requests that usages of the specified class outside the current analysis
* scope be passed to the specified processor.
*
* @param refClass the reference graph node for the class whose usages should be processed.
* @param p the processor to pass the usages to.
*/
public abstract void enqueueClassUsagesProcessor(RefClass refClass, UsagesProcessor p);
/**
* Requests that derived classes of the specified class outside the current analysis
* scope be passed to the specified processor.
*
* @param refClass the reference graph node for the class whose derived classes should be processed.
* @param p the processor to pass the classes to.
*/
public abstract void enqueueDerivedClassesProcessor(RefClass refClass, DerivedClassesProcessor p);
/**
* Requests that implementing or overriding methods of the specified method outside
* the current analysis scope be passed to the specified processor.
*
* @param refMethod the reference graph node for the method whose derived methods should be processed.
* @param p the processor to pass the methods to.
*/
public abstract void enqueueDerivedMethodsProcessor(RefMethod refMethod, DerivedMethodsProcessor p);
/**
* Requests that usages of the specified field outside the current analysis
* scope be passed to the specified processor.
*
* @param refField the reference graph node for the field whose usages should be processed.
* @param p the processor to pass the usages to.
*/
public abstract void enqueueFieldUsagesProcessor(RefField refField, UsagesProcessor p);
/**
* Requests that usages of the specified method outside the current analysis
* scope be passed to the specified processor.
*
* @param refMethod the reference graph node for the method whose usages should be processed.
* @param p the processor to pass the usages to.
*/
public abstract void enqueueMethodUsagesProcessor(RefMethod refMethod, UsagesProcessor p);
public abstract EntryPointsManager getEntryPointsManager(RefManager manager);
@NotNull
@Override
public Key<GlobalJavaInspectionContext> getID() {
return CONTEXT;
}
}
@@ -0,0 +1,70 @@
/*
* Copyright 2000-2009 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.intellij.codeInspection.reference;
import com.intellij.psi.PsiClass;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Set;
/**
* User: anna
* Date: 27-Dec-2005
*/
public interface RefClass extends RefJavaElement {
@NotNull
Set<RefClass> getBaseClasses();
@NotNull
Set<RefClass> getSubClasses();
@NotNull
List<RefMethod> getConstructors();
@NotNull
Set<RefElement> getInTypeReferences();
@NotNull
Set<RefElement> getInstanceReferences();
RefMethod getDefaultConstructor();
@NotNull
List<RefMethod> getLibraryMethods();
boolean isAnonymous();
boolean isInterface();
boolean isUtilityClass();
boolean isAbstract();
boolean isApplet();
boolean isServlet();
boolean isTestCase();
boolean isLocalClass();
boolean isSelfInheritor(PsiClass psiClass);
@Override
PsiClass getElement();
}
@@ -0,0 +1,57 @@
/*
* Copyright 2000-2009 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.intellij.codeInspection.reference;
import com.intellij.psi.PsiField;
/**
* A node in the reference graph corresponding to a Java field.
*
* @author anna
* @since 6.0
*/
public interface RefField extends RefJavaElement {
/**
* Checks if the field is used for reading.
*
* @return true if the field has read accesses, false otherwise.
*/
boolean isUsedForReading();
/**
* Checks if the field is used for writing.
*
* @return true if the field has write accesses, false otherwise.
*/
boolean isUsedForWriting();
/**
* Checks if the only write access of the field is its initializer.
*
* @return true if the only write access of the field is its initializer, false otherwise.
*/
boolean isOnlyAssignedInInitializer();
/**
* Returns the reference graph node for the class to which the field belongs.
*
* @return the owner class of the field.
*/
RefClass getOwnerClass();
@Override
PsiField getElement();
}
@@ -0,0 +1,25 @@
/*
* Copyright 2000-2009 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.intellij.codeInspection.reference;
/**
* A node in the reference graph corresponding to the implicit constructor of a Java class.
*
* @author anna
* @since 6.0
*/
public interface RefImplicitConstructor extends RefMethod {
}
@@ -0,0 +1,75 @@
/*
* Copyright 2000-2009 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.
*/
/*
* User: anna
* Date: 18-Dec-2007
*/
package com.intellij.codeInspection.reference;
import com.intellij.psi.PsiModifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
public interface RefJavaElement extends RefElement {
/**
* Returns the collection of references used in this element.
* @return the collection of used types
*/
@NotNull
Collection<RefClass> getOutTypeReferences();
/**
* Checks if the element is <code>final</code>.
*
* @return true if the element is final, false otherwise.
*/
boolean isFinal();
/**
* Checks if the element is <code>static</code>.
*
* @return true if the element is static, false otherwise.
*/
boolean isStatic();
/**
* Checks if the element directly references any elements marked as deprecated.
*
* @return true if the element references any deprecated elements, false otherwise.
*/
boolean isUsesDeprecatedApi();
/**
* Checks if the element is, or belongs to, a synthetic class or method created for a JSP page.
*
* @return true if the element is a synthetic JSP element, false otherwise.
*/
boolean isSyntheticJSP();
/**
* Returns the access modifier for the element, as one of the keywords from the
* {@link com.intellij.psi.PsiModifier} class.
*
* @return the modifier, or null if the element does not have any access modifier.
*/
@Nullable
@PsiModifier.ModifierConstant
String getAccessModifier();
}
@@ -0,0 +1,85 @@
/*
* Copyright 2000-2009 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.
*/
/*
* User: anna
* Date: 18-Dec-2007
*/
package com.intellij.codeInspection.reference;
import com.intellij.codeInspection.ex.EntryPointsManager;
import com.intellij.codeInspection.lang.RefManagerExtension;
import com.intellij.lang.Language;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.util.Key;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiParameter;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
public abstract class RefJavaManager implements RefManagerExtension<RefJavaManager> {
@NonNls public static final String CLASS = "class";
@NonNls public static final String METHOD = "method";
@NonNls public static final String FIELD = "field";
@NonNls public static final String PARAMETER = "parameter";
//used in OfflineProjectDescriptor
@NonNls public static final String PACKAGE = "package";
public static final Key<RefJavaManager> MANAGER = Key.create("RefJavaManager");
/**
* Creates (if necessary) and returns the reference graph node for the package
* with the specified name.
*
* @param packageName the name of the package for which the reference graph node is requested.
* @return the node for the package.
*/
public abstract RefPackage getPackage(String packageName);
/**
* Creates (if necessary) and returns the reference graph node for the specified PSI parameter.
*
* @param param the parameter for which the reference graph node is requested.
* @param index the index of the parameter in its parameter list.
* @return the node for the element, or null if the element is not valid or does not have
* a corresponding reference graph node type (is not a field, method, class or file).
*/
public abstract RefParameter getParameterReference(PsiParameter param, int index);
public abstract RefPackage getDefaultPackage();
public abstract PsiMethod getAppMainPattern();
public abstract PsiMethod getAppPremainPattern();
public abstract PsiClass getApplet();
public abstract PsiClass getServlet();
public abstract EntryPointsManager getEntryPointsManager();
@NotNull
@Override
public Language getLanguage() {
return JavaLanguage.INSTANCE;
}
@NotNull
@Override
public Key<RefJavaManager> getID() {
return MANAGER;
}
}
@@ -0,0 +1,73 @@
/*
* Copyright 2000-2009 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.
*/
/*
* User: anna
* Date: 21-Dec-2007
*/
package com.intellij.codeInspection.reference;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.psi.*;
import org.jetbrains.annotations.Nullable;
public abstract class RefJavaUtil {
public abstract void addReferences(final PsiModifierListOwner psiFrom, final RefJavaElement ref, @Nullable PsiElement findIn);
public abstract RefClass getTopLevelClass(RefElement refElement);
public abstract boolean isInheritor(RefClass subClass, RefClass superClass);
@Nullable //default package name
public abstract String getPackageName(RefEntity refEntity);
@Nullable
public abstract RefClass getOwnerClass(RefManager refManager, PsiElement psiElement);
@Nullable
public abstract RefClass getOwnerClass(RefElement refElement);
public abstract int compareAccess(String a1, String a2);
public abstract String getAccessModifier(PsiModifierListOwner psiElement);
public abstract void setAccessModifier(RefJavaElement refElement, String newAccess);
public abstract void setIsStatic(RefJavaElement refElement, boolean isStatic);
public abstract void setIsFinal(RefJavaElement refElement, boolean isFinal);
public abstract boolean isMethodOnlyCallsSuper(final PsiMethod derivedMethod);
public static boolean isDeprecated(PsiElement psiResolved) {
return psiResolved instanceof PsiDocCommentOwner && ((PsiDocCommentOwner)psiResolved).isDeprecated();
}
@Nullable
public static RefPackage getPackage(RefEntity refEntity) {
while (refEntity != null && !(refEntity instanceof RefPackage)) refEntity = refEntity.getOwner();
return (RefPackage)refEntity;
}
public static RefJavaUtil getInstance() {
return ServiceManager.getService(RefJavaUtil.class);
}
public abstract boolean isCallToSuperMethod(PsiExpression expression, PsiMethod method);
public abstract void addTypeReference(PsiElement psiElement, PsiType psiType, RefManager refManager);
}
@@ -0,0 +1,47 @@
/*
* Copyright 2000-2009 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.intellij.codeInspection.reference;
import org.jetbrains.annotations.NotNull;
/**
* Visitor for reference graph nodes.
*
* @see RefEntity#accept
* @see RefManager#iterate
* @since 6.0
*/
public class RefJavaVisitor extends RefVisitor {
public void visitField(@NotNull RefField field) {
visitElement(field);
}
public void visitMethod(@NotNull RefMethod method) {
visitElement(method);
}
public void visitParameter(@NotNull RefParameter parameter) {
visitElement(parameter);
}
public void visitClass(@NotNull RefClass aClass) {
visitElement(aClass);
}
public void visitPackage(@NotNull RefPackage aPackage) {
visitElement(aPackage);
}
}
@@ -0,0 +1,159 @@
/*
* Copyright 2000-2009 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.intellij.codeInspection.reference;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiModifierListOwner;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
/**
* A node in the reference graph corresponding to a Java method.
*
* @author anna
* @since 6.0
*/
public interface RefMethod extends RefJavaElement {
/**
* Returns the collection of the direct super methods of this method in the
* analysis scope.
*
* @return the collection of super methods.
* @see com.intellij.psi.PsiMethod#findSuperMethods()
* @see #hasSuperMethods
*/
@NotNull Collection<RefMethod> getSuperMethods();
/**
* Returns the collection of the overriding methods of this method in the
* analysis scope.
*
* @return the collection of overriding methods.
*/
@NotNull Collection<RefMethod> getDerivedMethods();
/**
* Checks if this method has a body (that is, not a method of an interface or an abstract
* method).
*
* @return true if the method has a body, false otherwise.
*/
boolean hasBody();
/**
* Checks if the method has no body or its body contains no statements besides
* (possibly) a call to its super method.
*
* @return true if the element has no body or the body is empty, false otherwise.
*/
boolean isBodyEmpty();
/**
* Checks if the method has a body which consists only of the call to its super method.
*
* @return true if the method only calls its super method, false otherwise.
*/
boolean isOnlyCallsSuper();
/**
* Checks if the method is a test method in a testcase class.
*
* @return true if the method is a test method, false otherwise.
*/
boolean isTestMethod();
/**
* Checks if the signature of the method matches the signature of the standard <code>main</code>
* or <code>premain</code> method.
*
* @return true if the method can be a main function of the application, false otherwise.
*/
boolean isAppMain();
/**
* Checks if the method has super methods either in the analysis scope or outside of it.
*
* @return true if the method has super methods, false otherwise.
* @see #getSuperMethods()
*/
boolean hasSuperMethods();
/**
* Checks if the method overrides a method outside the current analysis scope.
*
* @return true if the method overrides a method not in the analysis scope, false otherwise.
*/
boolean isExternalOverride();
/**
* Checks if the method is a constructor.
*
* @return true if the method is a constructor, false otherwise.
*/
boolean isConstructor();
/**
* Checks if the method is abstract.
*
* @return true if the method is abstract, false otherwise.
*/
boolean isAbstract();
/**
* Checks if the return value of the method is used by any of its callers.
*
* @return true if the method return value is used, false otherwise.
*/
boolean isReturnValueUsed();
/**
* If the method always returns the same value, returns that value (the name of a static
* final field or the text of a literal expression). Otherwise, returns null.
*
* @return the method return value or null if it's different or impossible to determine.
*/
@Nullable String getReturnValueIfSame();
/**
* Returns the list of exceptions which are included in the <code>throws</code> list
* of the method but cannot be actually thrown.
*
* @return the list of exceptions declared but not thrown, or null if there are no
* such exceptions.
*/
@Nullable PsiClass[] getUnThrownExceptions();
/**
* Returns the list of reference graph nodes for the method parameters.
*
* @return the method parameters.
*/
@NotNull RefParameter[] getParameters();
/**
* Returns the class to which the method belongs.
*
* @return the class instance.
*/
RefClass getOwnerClass();
@Override
PsiModifierListOwner getElement();
boolean isCalledOnSubClass();
}
@@ -0,0 +1,36 @@
/*
* Copyright 2000-2009 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.intellij.codeInspection.reference;
import org.jetbrains.annotations.NotNull;
/**
* A node in the reference graph corresponding to a Java package.
*
* @author anna
* @since 6.0
* @see RefJavaManager#getPackage
*/
public interface RefPackage extends RefEntity {
/**
* Returns the full-qualified name for the package, or an empty string for the default package.
*
* @return the full-qualified name for the package.
*/
@NotNull
@Override
String getQualifiedName();
}
@@ -0,0 +1,68 @@
/*
* Copyright 2000-2009 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.intellij.codeInspection.reference;
import com.intellij.psi.PsiParameter;
import org.jetbrains.annotations.Nullable;
/**
* A node in the reference graph corresponding to a Java method parameter.
*
* @author anna
* @since 6.0
*/
public interface RefParameter extends RefJavaElement {
/**
* Checks if the parameter is used for reading.
*
* @return true if the parameter has read accesses, false otherwise.
*/
boolean isUsedForReading();
/**
* Checks if the parameter is used for writing.
*
* @return true if the parameter has write accesses, false otherwise.
*/
boolean isUsedForWriting();
/**
* Returns the index of the parameter in the parameter list of its owner method.
*
* @return the index of the parameter.
*/
int getIndex();
/**
* If all invocations of the method pass the same value to the parameter, returns
* that value (the name of a static final field or the text of a literal expression).
* Otherwise, returns null.
*
* @return the parameter value or null if it's different or impossible to determine.
*/
@Nullable String getActualValueIfSame();
/**
* Marks the parameter as referenced for reading or writing.
*
* @param forWriting true if the parameter is marked as referenced for writing, false
* otherwise.
*/
void parameterReferenced(final boolean forWriting);
@Override
PsiParameter getElement();
}