long d = 5;
int a = 0;
}
+
+ void m() {
+ "".equals("");
+ }
}
--- /dev/null
+public class Test2 {
+
+ void m123() {
+
+
+ "".equals("");
+
+
+ }
+
+}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<problems>
+ <problem>
+ <file>file://$PROJECT_DIR$/src/Test.java</file>
+ <line>54</line>
+ <module>test</module>
+ <package><default></package>
+ <entry_point TYPE="method" FQNAME="Test void m()" />
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'equals()' called on itself</problem_class>
+ <description>Identical qualifier and argument to <code>equals()</code> call</description>
+ </problem>
+ <problem>
+ <file>file://$PROJECT_DIR$/src/Test2.java</file>
+ <line>6</line>
+ <module>test</module>
+ <package><default></package>
+ <entry_point TYPE="method" FQNAME="Test2 void m123()" />
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'equals()' called on itself</problem_class>
+ <description>Identical qualifier and argument to <code>equals()</code> call</description>
+ </problem>
+</problems>
+
import com.intellij.codeInspection.actions.ViewOfflineResultsAction;
import com.intellij.codeInspection.defUse.DefUseInspection;
import com.intellij.codeInspection.defUse.DefUseInspectionBase;
-import com.intellij.codeInspection.ex.InspectionProfileImpl;
-import com.intellij.codeInspection.ex.InspectionToolWrapper;
-import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
-import com.intellij.codeInspection.ex.ToolsImpl;
+import com.intellij.codeInspection.ex.*;
import com.intellij.codeInspection.offline.OfflineProblemDescriptor;
+import com.intellij.codeInspection.offlineViewer.OfflineProblemDescriptorNode;
import com.intellij.codeInspection.offlineViewer.OfflineViewParseUtil;
import com.intellij.codeInspection.ui.InspectionResultsView;
import com.intellij.codeInspection.ui.InspectionTree;
import com.intellij.codeInspection.ui.InspectionTreeNode;
+import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import com.intellij.psi.PsiElement;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.TestSourceBasedTestCase;
+import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.tree.TreeUtil;
+import com.siyeh.ig.bugs.EqualsWithItselfInspection;
+import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
import java.io.File;
public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase {
private InspectionResultsView myView;
- private LocalInspectionToolWrapper myToolWrapper;
+ private LocalInspectionToolWrapper myUnusedToolWrapper;
+ private LocalInspectionToolWrapper myDataFlowToolWrapper;
private static String varMessage(String name) {
return InspectionsBundle.message("inspection.unused.assignment.problem.descriptor1", "'" + name + "'");
HighlightDisplayKey.register(DefUseInspectionBase.SHORT_NAME);
}
- myToolWrapper = new LocalInspectionToolWrapper(new DefUseInspection());
- myView = ViewOfflineResultsAction.showOfflineView(getProject(), parse(), new InspectionProfileImpl("test") {
+ final InspectionProfileImpl profile = new InspectionProfileImpl("test") {
@Override
public boolean isToolEnabled(final HighlightDisplayKey key, PsiElement element) {
return Comparing.strEqual(key.toString(), DefUseInspectionBase.SHORT_NAME);
@Override
@NotNull
public InspectionToolWrapper[] getInspectionTools(PsiElement element) {
- return new InspectionToolWrapper[]{myToolWrapper};
+ return new InspectionToolWrapper[]{myUnusedToolWrapper};
}
@Override
@Override
@NotNull
public InspectionToolWrapper[] getInspectionTools(PsiElement element) {
- return new InspectionToolWrapper[]{myToolWrapper};
+ return new InspectionToolWrapper[]{myUnusedToolWrapper};
}
@Override
}
};
}
- }, "");
- myView.getGlobalInspectionContext().getTools().put(
- myToolWrapper.getShortName(), new ToolsImpl(myToolWrapper, myToolWrapper.getDefaultLevel(), true));
- myToolWrapper.initialize(myView.getGlobalInspectionContext());
- }
+ };
+
+ myView = ViewOfflineResultsAction.showOfflineView(getProject(), parse(), profile, "");
+ myUnusedToolWrapper = new LocalInspectionToolWrapper(new DefUseInspection());
+ myDataFlowToolWrapper = new LocalInspectionToolWrapper(new EqualsWithItselfInspection());
+
+ final Map<String, Tools> tools = myView.getGlobalInspectionContext().getTools();
+ for (LocalInspectionToolWrapper tool : ContainerUtil.ar(myUnusedToolWrapper, myDataFlowToolWrapper)) {
+ profile.addTool(getProject(), tool, new THashMap<>());
+ tools.put(tool.getShortName(), new ToolsImpl(tool, tool.getDefaultLevel(), true));
+ tool.initialize(myView.getGlobalInspectionContext());
+ }
+}
private Map<String, Map<String, Set<OfflineProblemDescriptor>>> parse() throws IOException {
final String moduleName = getModule().getName();
protected void tearDown() throws Exception {
Disposer.dispose(myView);
myView = null;
- myToolWrapper = null;
+ myUnusedToolWrapper = null;
+ myDataFlowToolWrapper = null;
super.tearDown();
}
- public void testOfflineView() throws Exception {
+ public void testOfflineWithInvalid() throws Exception {
+ ApplicationManager.getApplication().runWriteAction(() -> getJavaFacade().findClass("Test2").getContainingFile().delete());
myView.getGlobalInspectionContext().getUIOptions().SHOW_STRUCTURE = true;
InspectionTree tree = updateTree();
TreeUtil.expandAll(tree);
- PlatformTestUtil.assertTreeEqual(tree, "-" + getProject() + "\n"
- + " -Probable bugs\n"
- + " -" + myToolWrapper + "\n"
+ PlatformTestUtil.assertTreeEqual(tree, "-" + getProject() + "\n" +
+ " -Probable bugs\n" +
+ " -" + myDataFlowToolWrapper + "\n" +
+ " -Module: 'testOfflineWithInvalid'\n" +
+ " -<default>\n" +
+ " -Test\n" +
+ " -m()\n" +
+ " Identical qualifier and argument to 'equals()' call\n" +
+ " Identical qualifier and argument to <code>equals()</code> call\n"
+ + " -" + myUnusedToolWrapper + "\n"
+ " -" + getModule().toString() + "\n"
+ " -<default>\n"
+ " -Test\n"
+ " -foo()\n"
+ " " + varMessage("j") + "\n"
+ + " -main(String[])\n"
+ + " " + varMessage("test") + "\n"
+ " -f()\n"
+ " -D\n"
+ " -b()\n"
+ " " + varMessage("i") + "\n"
+ " -ff()\n"
+ " " + varMessage("d") + "\n"
- + " " + varMessage("a") + "\n"
+ + " " + varMessage("a") + "\n");
+ tree.setSelectionRow(7);
+ final OfflineProblemDescriptorNode node =
+ (OfflineProblemDescriptorNode)tree.getSelectionModel().getSelectionPath().getLastPathComponent();
+ assertFalse(node.isValid());
+ }
+
+ public void testOfflineView() throws Exception {
+ myView.getGlobalInspectionContext().getUIOptions().SHOW_STRUCTURE = true;
+ InspectionTree tree = updateTree();
+ TreeUtil.expandAll(tree);
+ PlatformTestUtil.assertTreeEqual(tree, "-" + getProject() + "\n" +
+ " -Probable bugs\n" +
+ " -" + myDataFlowToolWrapper + "\n" +
+ " -Module: 'testOfflineView'\n" +
+ " -<default>\n" +
+ " -Test\n" +
+ " -m()\n" +
+ " Identical qualifier and argument to 'equals()' call\n" +
+ " -Test2\n" +
+ " -m123()\n" +
+ " Identical qualifier and argument to 'equals()' call\n"
+ + " -" + myUnusedToolWrapper + "\n"
+ + " -" + getModule().toString() + "\n"
+ + " -<default>\n"
+ + " -Test\n"
+ + " -foo()\n"
+ + " " + varMessage("j") + "\n"
+ " -main(String[])\n"
- + " " + varMessage("test") + "\n");
- myView.getGlobalInspectionContext().getUIOptions().SHOW_STRUCTURE = false;
+ + " " + varMessage("test") + "\n"
+ + " -f()\n"
+ + " -D\n"
+ + " -b()\n"
+ + " " + varMessage("r") + "\n"
+ + " -anonymous (java.lang.Runnable)\n"
+ + " -run()\n"
+ + " " + varMessage("i") + "\n"
+ + " -ff()\n"
+ + " " + varMessage("d") + "\n"
+ + " " + varMessage("a") + "\n");
+ myView.getGlobalInspectionContext().getUIOptions().SHOW_STRUCTURE = false;
tree = updateTree();
PlatformTestUtil.assertTreeEqual(tree, "-" + getProject() + "\n"
+ " -Probable bugs\n"
- + " -" + myToolWrapper + "\n"
+ + " -" + myDataFlowToolWrapper + "\n" +
+ " -Test\n" +
+ " Identical qualifier and argument to 'equals()' call\n" +
+ " -Test2\n" +
+ " Identical qualifier and argument to 'equals()' call\n"
+ + " -" + myUnusedToolWrapper + "\n"
+ " -Test\n"
+ " " + varMessage("j") + "\n"
+ + " " + varMessage("test") + "\n"
+ " " + varMessage("r") + "\n"
+ " " + varMessage("i") + "\n"
+ " " + varMessage("d") + "\n"
- + " " + varMessage("a") + "\n"
- + " " + varMessage("test") + "\n");
+ + " " + varMessage("a") + "\n");
TreeUtil.selectFirstNode(tree);
final InspectionTreeNode root = (InspectionTreeNode)tree.getLastSelectedPathComponent();
root.excludeElement(myView.getExcludedManager());
tree = updateTree();
PlatformTestUtil.assertTreeEqual(tree, "-" + getProject() + "\n"
+ " -Probable bugs\n"
- + " -" + myToolWrapper + "\n"
+ + " -" + myDataFlowToolWrapper + "\n" +
+ " -Test\n" +
+ " Identical qualifier and argument to 'equals()' call\n" +
+ " -Test2\n" +
+ " Identical qualifier and argument to 'equals()' call\n"
+ + " -" + myUnusedToolWrapper + "\n"
+ " -Test\n"
+ " " + varMessage("j") + "\n"
+ + " " + varMessage("test") + "\n"
+ " " + varMessage("r") + "\n"
+ " " + varMessage("i") + "\n"
+ " " + varMessage("d") + "\n"
- + " " + varMessage("a") + "\n"
- + " " + varMessage("test") + "\n");
+ + " " + varMessage("a") + "\n");
}
private InspectionTree updateTree() {
import com.intellij.psi.*;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.scope.packageSet.NamedScope;
-import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashMap;
import gnu.trove.THashMap;
Element element = new Element(ENTRY_POINT);
element.setAttribute(TYPE_ATTR, myType);
element.setAttribute(FQNAME_ATTR, getFQName());
- /*if (myRefElement != null) {
- final RefEntity entity = myRefElement.getOwner();
- if (entity != null) {
- new SmartRefElementPointerImpl(entity, myIsPersistent).writeExternal(element);
- }
- }*/
parentNode.addContent(element);
}
package com.intellij.codeInspection.offline;
import com.intellij.codeInspection.reference.RefElement;
-import com.intellij.codeInspection.reference.RefManager;
import com.intellij.codeInspection.reference.RefEntity;
-import com.intellij.openapi.application.Application;
+import com.intellij.codeInspection.reference.RefManager;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
-import com.intellij.util.ArrayUtil;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.Nullable;
public List<String> myHints;
public int myProblemIndex;
public int myLine;
- public String[] myParentType;
- public String[] myParentFQName;
public String myModuleName;
public String getType() {
myLine = line;
}
- public String[] getParentType() {
- return myParentType;
- }
-
- public void setParentType(final String[] parentType) {
- myParentType = parentType;
- }
-
- public String[] getParentFQName() {
- return myParentFQName;
- }
-
- public void setParentFQName(final String[] parentFQName) {
- myParentFQName = parentFQName;
- }
-
@Nullable
public RefEntity getRefElement(final RefManager refManager) {
final RefEntity refElement = refManager.getReference(myType, myFQName);
return refElement;
}
- @Nullable
- public OfflineProblemDescriptor getOwner() {
- if (myParentType != null && myParentFQName != null) {
- final OfflineProblemDescriptor descriptor = new OfflineProblemDescriptor();
- descriptor.setLine(myLine);
- descriptor.setFQName(myParentFQName[0]);
- descriptor.setType(myParentType[0]);
- if (myParentType.length > 1 && myParentFQName.length > 1) {
- descriptor.setParentType(ArrayUtil.remove(myParentType, 0));
- descriptor.setParentFQName(ArrayUtil.remove(myParentFQName, 0));
- }
- return descriptor;
- }
- return null;
- }
-
-
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (myFQName != null ? !myFQName.equals(that.myFQName) : that.myFQName != null) return false;
if (myHints != null ? !myHints.equals(that.myHints) : that.myHints != null) return false;
if (myModuleName != null ? !myModuleName.equals(that.myModuleName) : that.myModuleName != null) return false;
- if (!Arrays.equals(myParentFQName, that.myParentFQName)) return false;
- if (!Arrays.equals(myParentType, that.myParentType)) return false;
if (myType != null ? !myType.equals(that.myType) : that.myType != null) return false;
return true;
result = 31 * result + (myHints != null ? myHints.hashCode() : 0);
result = 31 * result + myProblemIndex;
result = 31 * result + myLine;
- result = 31 * result + (myParentType != null ? Arrays.hashCode(myParentType) : 0);
- result = 31 * result + (myParentFQName != null ? Arrays.hashCode(myParentFQName) : 0);
result = 31 * result + (myModuleName != null ? myModuleName.hashCode() : 0);
return result;
}
import com.intellij.codeInspection.CommonProblemDescriptor;
import com.intellij.codeInspection.QuickFix;
-import com.intellij.codeInspection.offlineViewer.OfflineRefElementNode;
+import com.intellij.codeInspection.reference.RefDirectory;
+import com.intellij.codeInspection.reference.RefElement;
import com.intellij.codeInspection.reference.RefEntity;
+import com.intellij.codeInspection.reference.RefModule;
import com.intellij.codeInspection.ui.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Ref;
import com.intellij.util.Function;
import com.intellij.util.containers.MultiMap;
myProject = project;
}
- protected interface UserObjectContainer<T> {
+ protected static class RefEntityContainer<Descriptor> {
+ private final Descriptor[] myDescriptors;
@Nullable
- UserObjectContainer<T> getOwner();
+ private final RefEntity myEntity;
- @NotNull
- RefElementNode createNode(@NotNull InspectionToolPresentation presentation);
+ public RefEntityContainer(@Nullable RefEntity entity, Descriptor[] descriptors) {
+ myEntity = entity;
+ myDescriptors = descriptors;
+ }
+
+ @Nullable
+ public RefEntityContainer<Descriptor> getOwner() {
+ if (myEntity == null) return null;
+ final RefEntity entity = myEntity.getOwner();
+ return entity instanceof RefElement && !(entity instanceof RefDirectory)
+ ? new RefEntityContainer<Descriptor>(entity, myDescriptors)
+ : null;
+ }
@NotNull
- T getUserObject();
+ public RefElementNode createNode(@NotNull InspectionToolPresentation presentation) {
+ return new RefElementNode(myEntity, presentation);
+ }
+
+ @Nullable
+ public RefEntity getRefEntity() {
+ return myEntity;
+ }
@Nullable
- String getModule();
+ public String getModule() {
+ final RefModule refModule = myEntity instanceof RefElement
+ ? ((RefElement)myEntity).getModule()
+ : myEntity instanceof RefModule ? (RefModule)myEntity : null;
+ return refModule != null ? refModule.getName() : null;
+ }
- boolean areEqual(final T o1, final T o2);
+ boolean areEqual(final @NotNull RefEntity o1, final @NotNull RefEntity o2) {
+ return Comparing.equal(o1, o2);
+ }
- boolean supportStructure();
+ boolean supportStructure() {
+ return myEntity == null || myEntity instanceof RefElement && !(myEntity instanceof RefDirectory); //do not show structure for refModule and refPackage
+ }
+
+ public Descriptor[] getDescriptors() {
+ return myDescriptors;
+ }
}
public abstract boolean checkReportedProblems(@NotNull GlobalInspectionContextImpl context, @NotNull InspectionToolWrapper toolWrapper);
protected abstract void appendDescriptor(@NotNull GlobalInspectionContextImpl context,
@NotNull InspectionToolWrapper toolWrapper,
- @NotNull UserObjectContainer container,
+ @NotNull RefEntityContainer container,
@NotNull InspectionTreeNode pNode,
final boolean canPackageRepeat);
@NotNull Map<String, Set<T>> packageContents,
final boolean canPackageRepeat,
@NotNull InspectionToolWrapper toolWrapper,
- @NotNull Function<T, UserObjectContainer<T>> computeContainer,
+ @NotNull Function<T, RefEntityContainer<?>> computeContainer,
final boolean showStructure,
final UnaryOperator<InspectionTreeNode> createdNodesConsumer) {
final Map<String, Map<String, InspectionPackageNode>> module2PackageMap = new HashMap<String, Map<String, InspectionPackageNode>>();
boolean supportStructure = showStructure;
- final MultiMap<InspectionPackageNode, UserObjectContainer<T>> packageDescriptors = new MultiMap<>();
+ final MultiMap<InspectionPackageNode, RefEntityContainer<?>> packageDescriptors = new MultiMap<>();
for (String packageName : packageContents.keySet()) {
final Set<T> elements = packageContents.get(packageName);
for (T userObject : elements) {
- final UserObjectContainer<T> container = computeContainer.fun(userObject);
+ final RefEntityContainer container = computeContainer.fun(userObject);
supportStructure &= container.supportStructure();
final String moduleName = showStructure ? container.getModule() : null;
Map<String, InspectionPackageNode> packageNodes = module2PackageMap.get(moduleName);
else {
for (InspectionPackageNode packageNode : packageNodes.values()) {
createdNodesConsumer.apply(packageNode);
- for (UserObjectContainer<T> container : packageDescriptors.get(packageNode)) {
+ for (RefEntityContainer<?> container : packageDescriptors.get(packageNode)) {
appendDescriptor(context, toolWrapper, container, packageNode, canPackageRepeat);
}
}
}
for (InspectionPackageNode packageNode : packageNodes.values()) {
if (packageNode.getPackageName() != null) {
- Collection<UserObjectContainer<T>> objectContainers = packageDescriptors.get(packageNode);
+ Collection<RefEntityContainer<?>> objectContainers = packageDescriptors.get(packageNode);
packageNode = (InspectionPackageNode)merge(packageNode, moduleNode, true);
- for (UserObjectContainer<T> container : objectContainers) {
+ for (RefEntityContainer<?> container : objectContainers) {
appendDescriptor(context, toolWrapper, container, packageNode, canPackageRepeat);
}
}
else {
- for (UserObjectContainer<T> container : packageDescriptors.get(packageNode)) {
+ for (RefEntityContainer<?> container : packageDescriptors.get(packageNode)) {
appendDescriptor(context, toolWrapper, container, moduleNode, canPackageRepeat);
}
}
else {
for (Map<String, InspectionPackageNode> packageNodes : module2PackageMap.values()) {
for (InspectionPackageNode pNode : packageNodes.values()) {
- for (UserObjectContainer<T> container : packageDescriptors.get(pNode)) {
+ for (RefEntityContainer<?> container : packageDescriptors.get(pNode)) {
appendDescriptor(context, toolWrapper, container, pNode, canPackageRepeat);
}
final int count = pNode.getChildCount();
}
@NotNull
- protected static RefElementNode addNodeToParent(@NotNull UserObjectContainer container,
+ protected static RefElementNode addNodeToParent(@NotNull RefEntityContainer container,
@NotNull InspectionToolPresentation presentation,
final InspectionTreeNode parentNode) {
final RefElementNode nodeToBeAdded = container.createNode(presentation);
final Ref<RefElementNode> result = new Ref<RefElementNode>();
while (true) {
final RefElementNode currentNode = firstLevel.get() ? nodeToBeAdded : container.createNode(presentation);
- final UserObjectContainer finalContainer = container;
+ final RefEntityContainer finalContainer = container;
final RefElementNode finalPrevNode = prevNode;
TreeUtil.traverseDepth(parentNode, new TreeUtil.Traverse() {
@Override
public boolean accept(Object node) {
if (node instanceof RefElementNode) {
final RefElementNode refElementNode = (RefElementNode)node;
- final Object userObject = finalContainer.getUserObject();
- final Object object = node instanceof OfflineRefElementNode ? ((OfflineRefElementNode) refElementNode).getOfflineDescriptor() : refElementNode.getUserObject();
- if ((object == null || userObject.getClass().equals(object.getClass())) && finalContainer.areEqual(object, userObject)) {
+ final RefEntity userObject = finalContainer.getRefEntity();
+ final RefEntity object = refElementNode.getElement();
+ if (userObject == null || object == null || (userObject.getClass().equals(object.getClass())) && finalContainer.areEqual(object, userObject)) {
if (firstLevel.get()) {
result.set(refElementNode);
return false;
if (!firstLevel.get()) {
currentNode.insertByOrder(prevNode, false);
}
- final UserObjectContainer owner = container.getOwner();
+ final RefEntityContainer owner = container.getOwner();
if (owner == null) {
parentNode.insertByOrder(currentNode, false);
return nodeToBeAdded;
import com.intellij.codeInspection.reference.*;
import com.intellij.codeInspection.ui.*;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.search.LocalSearchScope;
contents,
false,
toolWrapper,
- refElement -> new RefElementContainer(refElement, problems.get(refElement)),
+ refElement -> new RefEntityContainer<CommonProblemDescriptor>(refElement, problems.get(refElement)),
showStructure,
node -> merge(node, mergedToolNode, true));
return mergedToolNode;
@Override
protected void appendDescriptor(@NotNull GlobalInspectionContextImpl context,
@NotNull final InspectionToolWrapper toolWrapper,
- @NotNull final UserObjectContainer container,
+ @NotNull final RefEntityContainer container,
@NotNull final InspectionTreeNode pNode,
final boolean canPackageRepeat) {
- final RefElementContainer refElementDescriptor = (RefElementContainer)container;
- final RefEntity refElement = refElementDescriptor.getUserObject();
+ final RefEntity refElement = container.getRefEntity();
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
- final CommonProblemDescriptor[] problems = refElementDescriptor.getProblemDescriptors();
+ final CommonProblemDescriptor[] problems = ((RefEntityContainer<CommonProblemDescriptor>)container).getDescriptors();
if (problems != null) {
final RefElementNode elemNode = addNodeToParent(container, presentation, pNode);
for (CommonProblemDescriptor problem : problems) {
addNodeToParent(container, presentation, pNode);
}
}
-
- private static class RefElementContainer implements UserObjectContainer<RefEntity> {
- @NotNull
- private final RefEntity myElement;
- private final CommonProblemDescriptor[] myDescriptors;
-
- public RefElementContainer(@NotNull RefEntity element, CommonProblemDescriptor[] descriptors) {
- myElement = element;
- myDescriptors = descriptors;
- }
-
- @Override
- @Nullable
- public RefElementContainer getOwner() {
- final RefEntity entity = myElement.getOwner();
- if (entity instanceof RefElement && !(entity instanceof RefDirectory)) {
- return new RefElementContainer(entity, myDescriptors);
- }
- return null;
- }
-
- @NotNull
- @Override
- public RefElementNode createNode(@NotNull InspectionToolPresentation presentation) {
- return new RefElementNode(myElement, presentation);
- }
-
- @Override
- @NotNull
- public RefEntity getUserObject() {
- return myElement;
- }
-
- @Override
- @Nullable
- public String getModule() {
- final RefModule refModule = myElement instanceof RefElement
- ? ((RefElement)myElement).getModule()
- : myElement instanceof RefModule ? (RefModule)myElement : null;
- return refModule != null ? refModule.getName() : null;
- }
-
- @Override
- public boolean areEqual(final RefEntity o1, final RefEntity o2) {
- return Comparing.equal(o1, o2);
- }
-
- @Override
- public boolean supportStructure() {
- return myElement instanceof RefElement && !(myElement instanceof RefDirectory); //do not show structure for refModule and refPackage
- }
-
- public CommonProblemDescriptor[] getProblemDescriptors() {
- return myDescriptors;
- }
- }
}
import com.intellij.codeInspection.offline.OfflineProblemDescriptor;
import com.intellij.codeInspection.reference.RefElement;
import com.intellij.codeInspection.reference.RefEntity;
-import com.intellij.codeInspection.reference.SmartRefElementPointer;
import com.intellij.codeInspection.ui.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
final Map<String, Set<OfflineProblemDescriptor>> filteredContent = getFilteredContent(context, toolWrapper);
if (filteredContent != null && !filteredContent.values().isEmpty()) {
parentNode.insertByOrder(toolNode, false);
- buildTree(context, filteredContent, false, toolWrapper, OfflineProblemDescriptorContainer::new, showStructure,
+ buildTree(context, filteredContent, false, toolWrapper, descriptor -> {
+ final RefEntity element = descriptor.getRefElement(context.getRefManager());
+ return new RefEntityContainer<OfflineProblemDescriptor>(element, new OfflineProblemDescriptor[] {descriptor}) {
+ @Nullable
+ @Override
+ public String getModule() {
+ final String module = super.getModule();
+ return module == null ? descriptor.getModuleName() : module;
+ }
+ };
+ }, showStructure,
(newChild) -> {
toolNode.insertByOrder(newChild, false);
return newChild;
@Override
protected void appendDescriptor(@NotNull GlobalInspectionContextImpl context,
@NotNull final InspectionToolWrapper toolWrapper,
- @NotNull final UserObjectContainer container,
+ @NotNull final RefEntityContainer container,
@NotNull final InspectionTreeNode packageNode,
final boolean canPackageRepeat) {
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
final RefElementNode elemNode = addNodeToParent(container, presentation, packageNode);
if (toolWrapper instanceof LocalInspectionToolWrapper) {
- final OfflineProblemDescriptorNode child =
- OfflineProblemDescriptorNode.create(((OfflineProblemDescriptorContainer)container).getUserObject(),
- (LocalInspectionToolWrapper)toolWrapper, presentation);
- elemNode.insertByOrder(child, true);
- }
- }
-
-
- private static class OfflineProblemDescriptorContainer implements UserObjectContainer<OfflineProblemDescriptor> {
- @NotNull
- private final OfflineProblemDescriptor myDescriptor;
-
- public OfflineProblemDescriptorContainer(@NotNull OfflineProblemDescriptor descriptor) {
- myDescriptor = descriptor;
- }
-
- @Override
- @Nullable
- public OfflineProblemDescriptorContainer getOwner() {
- final OfflineProblemDescriptor descriptor = myDescriptor.getOwner();
- if (descriptor != null) {
- final OfflineProblemDescriptorContainer container = new OfflineProblemDescriptorContainer(descriptor);
- return container.supportStructure() ? container : null;
- }
- return null;
- }
-
- @NotNull
- @Override
- public RefElementNode createNode(@NotNull InspectionToolPresentation presentation) {
- return new OfflineRefElementNode(myDescriptor, presentation);
- }
-
- @Override
- @NotNull
- public OfflineProblemDescriptor getUserObject() {
- return myDescriptor;
- }
-
- @Override
- public String getModule() {
- return myDescriptor.getModuleName();
- }
-
- @Override
- public boolean areEqual(final OfflineProblemDescriptor o1, final OfflineProblemDescriptor o2) {
- if (o1 == null || o2 == null) {
- return o1 == o2;
+ for (OfflineProblemDescriptor descriptor : ((RefEntityContainer<OfflineProblemDescriptor>)container).getDescriptors()) {
+ final OfflineProblemDescriptorNode child = OfflineProblemDescriptorNode.create(descriptor, (LocalInspectionToolWrapper)toolWrapper, presentation);
+ elemNode.insertByOrder(child, true);
}
-
- if (!Comparing.strEqual(o1.getFQName(), o2.getFQName())) return false;
- if (!Comparing.strEqual(o1.getType(), o2.getType())) return false;
-
- return true;
- }
-
- @Override
- public boolean supportStructure() {
- return !Comparing.strEqual(myDescriptor.getType(), SmartRefElementPointer.MODULE) &&
- !Comparing.strEqual(myDescriptor.getType(), "package") &&
- !Comparing.strEqual(myDescriptor.getType(), SmartRefElementPointer.PROJECT);
}
}
}
+++ /dev/null
-/*
- * 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: 05-Jan-2007
- */
-package com.intellij.codeInspection.offlineViewer;
-
-import com.intellij.codeInspection.offline.OfflineProblemDescriptor;
-import com.intellij.codeInspection.reference.RefEntity;
-import com.intellij.codeInspection.ui.InspectionToolPresentation;
-import com.intellij.codeInspection.ui.RefElementNode;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-public class OfflineRefElementNode extends RefElementNode {
- @NotNull
- private OfflineProblemDescriptor myOfflineDescriptor;
-
- public OfflineRefElementNode(@NotNull OfflineProblemDescriptor descriptor, @NotNull InspectionToolPresentation presentation) {
- super(descriptor.getRefElement(presentation.getContext().getRefManager()), presentation);
- myOfflineDescriptor = descriptor;
- }
-
- @Override
- @Nullable
- public RefEntity getElement() {
- return (RefEntity)getUserObject();
- }
-
- @NotNull
- public OfflineProblemDescriptor getOfflineDescriptor() {
- return myOfflineDescriptor;
- }
-}
\ No newline at end of file
import com.intellij.codeInspection.InspectionApplication;
import com.intellij.codeInspection.offline.OfflineProblemDescriptor;
import com.intellij.codeInspection.reference.SmartRefElementPointerImpl;
-import com.intellij.util.ArrayUtil;
import com.thoughtworks.xstream.io.xml.XppReader;
import gnu.trove.THashMap;
import gnu.trove.THashSet;
int idx = fqName2IdxMap.get(fqName);
descriptor.setProblemIndex(idx);
fqName2IdxMap.put(fqName, idx + 1);
-
- final List<String> parentTypes = new ArrayList<String>();
- final List<String> parentNames = new ArrayList<String>();
- int deep = 0;
- while (true) {
- if (reader.hasMoreChildren()) {
- reader.moveDown();
- parentTypes.add(reader.getAttribute(SmartRefElementPointerImpl.TYPE_ATTR));
- parentNames.add(reader.getAttribute(SmartRefElementPointerImpl.FQNAME_ATTR));
- deep ++;
- } else {
- while (deep-- > 0) {
- reader.moveUp();
- }
- break;
- }
- }
- if (!parentTypes.isEmpty() && !parentNames.isEmpty()) {
- descriptor.setParentType(ArrayUtil.toStringArray(parentTypes));
- descriptor.setParentFQName(ArrayUtil.toStringArray(parentNames));
- }
}
if (DESCRIPTION.equals(reader.getNodeName())) {
descriptor.setDescription(reader.getValue());
import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
import com.intellij.codeInspection.CommonProblemDescriptor;
import com.intellij.codeInspection.ProblemDescriptor;
-import com.intellij.codeInspection.offline.OfflineProblemDescriptor;
-import com.intellij.codeInspection.offlineViewer.OfflineRefElementNode;
import com.intellij.codeInspection.reference.RefElement;
import com.intellij.codeInspection.reference.RefEntity;
import com.intellij.codeInspection.reference.RefFile;
if (node1 instanceof InspectionPackageNode) return -1;
if (node2 instanceof InspectionPackageNode) return 1;
- if (node1 instanceof OfflineRefElementNode && node2 instanceof OfflineRefElementNode) {
- final Object userObject1 = ((OfflineRefElementNode)node1).getOfflineDescriptor();
- final Object userObject2 = ((OfflineRefElementNode)node2).getOfflineDescriptor();
- final OfflineProblemDescriptor descriptor1 = (OfflineProblemDescriptor)userObject1;
- final OfflineProblemDescriptor descriptor2 = (OfflineProblemDescriptor)userObject2;
- final int res = descriptor1.getFQName().compareToIgnoreCase(descriptor2.getFQName());
- if (res != 0) {
- return res;
- }
- return descriptor1.getLine() - descriptor2.getLine();
- }
-
if (node1 instanceof RefElementNode && node2 instanceof RefElementNode){ //sort by filename and inside file by start offset
return compareEntities(((RefElementNode)node1).getElement(), ((RefElementNode)node2).getElement());
}
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.reference.RefElement;
import com.intellij.codeInspection.reference.RefEntity;
-import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.FileStatus;
import com.intellij.psi.PsiElement;
@Override
protected boolean calculateIsValid() {
if (myDescriptor == null) return false;
- if (myElement instanceof RefElement && !myElement.isValid()) return false;
+ if (myElement == null || myElement instanceof RefElement && !myElement.isValid()) return false;
if (myDescriptor instanceof ProblemDescriptor) {
final PsiElement psiElement = ((ProblemDescriptor)myDescriptor).getPsiElement();
return psiElement != null && psiElement.isValid();
inspection.suspicious.collections.method.calls.problem.descriptor=''{0}'' may not contain objects of type ''{1}''
inspection.suspicious.collections.method.calls.problem.descriptor1=Suspicious call to ''{0}''
-inspection.reference.invalid=invalid
+inspection.reference.invalid=element no longer exists
inspection.reference.default.package=default package
inspection.reference.implicit.constructor.name=implicit constructor of {0}
inspection.reference.noname=noname