Merge remote-tracking branch 'origin/master'

This commit is contained in:
Konstantin Bulenkov
2016-10-06 18:44:58 +02:00
9 changed files with 66 additions and 30 deletions
@@ -65,9 +65,11 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
private Set<RefElement> myInTypeReferences;
private Set<RefElement> myInstanceReferences;
private List<RefJavaElement> myClassExporters;
private RefModule myRefModule;
RefClassImpl(PsiClass psiClass, RefManager manager) {
super(psiClass, manager);
myRefModule = manager.getRefModule(ModuleUtilCore.findModuleForPsiElement(psiClass));
}
@Override
@@ -226,6 +228,12 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
return (PsiClass)super.getElement();
}
@Nullable
@Override
public RefModule getModule() {
return myRefModule;
}
private static boolean isSelfInheritor(PsiClass psiClass, ArrayList<PsiClass> visited) {
if (visited.contains(psiClass)) return true;
@@ -34,8 +34,10 @@ import org.jetbrains.annotations.Nullable;
public class RefImplicitConstructorImpl extends RefMethodImpl implements RefImplicitConstructor {
private final RefClass myOwnerClass;
RefImplicitConstructorImpl(@NotNull RefClass ownerClass) {
super(InspectionsBundle.message("inspection.reference.implicit.constructor.name", ownerClass.getName()), ownerClass);
myOwnerClass = ownerClass;
}
@Override
@@ -57,24 +57,20 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
private RefParameter[] myParameters;
private String myReturnValueTemplate;
protected final RefClass myOwnerClass;
RefMethodImpl(@NotNull RefClass ownerClass, PsiMethod method, RefManager manager) {
super(method, manager);
((RefClassImpl)ownerClass).add(this);
myOwnerClass = ownerClass;
}
// To be used only from RefImplicitConstructor.
protected RefMethodImpl(@NotNull String name, @NotNull RefClass ownerClass) {
super(name, ownerClass);
myOwnerClass = ownerClass;
((RefClassImpl)ownerClass).add(this);
addOutReference(getOwnerClass());
((RefClassImpl)getOwnerClass()).addInReference(this);
addOutReference(ownerClass);
((RefClassImpl)ownerClass).addInReference(this);
setConstructor(true);
}
@@ -26,8 +26,10 @@ import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class RefDirectoryImpl extends RefElementImpl implements RefDirectory{
private RefModule myRefModule;
protected RefDirectoryImpl(PsiDirectory psiElement, RefManager refManager) {
super(psiElement.getName(), psiElement, refManager);
final PsiDirectory parentDirectory = psiElement.getParentDirectory();
@@ -38,13 +40,10 @@ public class RefDirectoryImpl extends RefElementImpl implements RefDirectory{
return;
}
}
final Module module = ModuleUtilCore.findModuleForPsiElement(psiElement);
if (module != null) {
final RefModuleImpl refModule = (RefModuleImpl)refManager.getRefModule(module);
if (refModule != null) {
refModule.add(this);
return;
}
myRefModule = refManager.getRefModule(ModuleUtilCore.findModuleForPsiElement(psiElement));
if (myRefModule != null) {
((RefModuleImpl)myRefModule).add(this);
return;
}
((RefProjectImpl)refManager.getRefProject()).add(this);
}
@@ -54,6 +53,12 @@ public class RefDirectoryImpl extends RefElementImpl implements RefDirectory{
ApplicationManager.getApplication().runReadAction(() -> visitor.visitDirectory(this));
}
@Nullable
@Override
public RefModule getModule() {
return myRefModule;
}
@Override
protected void initialize() {
}
@@ -61,14 +61,12 @@ public abstract class RefElementImpl extends RefEntityImpl implements RefElement
private String[] mySuppressions = null;
private boolean myIsDeleted ;
private final Module myModule;
protected static final int IS_REACHABLE_MASK = 0x40;
protected RefElementImpl(@NotNull String name, @NotNull RefElement owner) {
super(name, owner.getRefManager());
myID = null;
myFlags = 0;
myModule = ModuleUtilCore.findModuleForPsiElement(owner.getElement());
}
protected RefElementImpl(PsiFile file, RefManager manager) {
@@ -79,7 +77,6 @@ public abstract class RefElementImpl extends RefEntityImpl implements RefElement
super(name, manager);
myID = SmartPointerManager.getInstance(manager.getProject()).createSmartPsiElementPointer(element);
myFlags = 0;
myModule = ModuleUtilCore.findModuleForPsiElement(element);
}
@Override
@@ -114,7 +111,8 @@ public abstract class RefElementImpl extends RefEntityImpl implements RefElement
@Override
public RefModule getModule() {
return myManager.getRefModule(myModule);
final RefEntity owner = getOwner();
return owner instanceof RefElement ? ((RefElement)owner).getModule() : null;
}
@Override
@@ -470,7 +470,10 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
GlobalSimpleInspectionTool tool = (GlobalSimpleInspectionTool)toolWrapper.getTool();
ProblemDescriptionsProcessor problemDescriptionProcessor = getProblemDescriptionProcessor(toolWrapper, map);
tool.inspectionFinished(inspectionManager, this, problemDescriptionProcessor);
}
addProblemsToView(globalSimpleTools);
}
private void inspectFile(@NotNull final PsiFile file,
@@ -656,12 +659,8 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
LOG.error(e);
}
}
if (!ApplicationManager.getApplication().isUnitTestMode() && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
if (myView == null && !ReadAction.compute(() -> InspectionResultsView.hasProblems(globalTools, this, createContentProvider())).booleanValue()) {
return;
}
initializeViewIfNeed().doWhenDone(() -> myView.addTools(globalTools));
}
addProblemsToView(globalTools);
}
public ActionCallback initializeViewIfNeed() {
@@ -994,4 +993,14 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
private InspectionRVContentProvider createContentProvider() {
return new InspectionRVContentProviderImpl(getProject());
}
private void addProblemsToView(List<Tools> tools) {
if (ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isHeadlessEnvironment()) {
return;
}
if (myView == null && !ReadAction.compute(() -> InspectionResultsView.hasProblems(tools, this, createContentProvider())).booleanValue()) {
return;
}
initializeViewIfNeed().doWhenDone(() -> myView.addTools(tools));
}
}
@@ -211,7 +211,7 @@ public class DefaultInspectionToolPresentation implements ProblemDescriptionsPro
if (context.isViewClosed() || !(refElement instanceof RefElement)) {
return;
}
if (!ApplicationManager.getApplication().isUnitTestMode()) {
if (myToolWrapper instanceof LocalInspectionToolWrapper && !ApplicationManager.getApplication().isUnitTestMode()) {
context.initializeViewIfNeed().doWhenDone(() -> context.getView().addProblemDescriptors(myToolWrapper, refElement, descriptors));
}
}
@@ -313,7 +313,13 @@ public class DefaultInspectionToolPresentation implements ProblemDescriptionsPro
@Override
public void ignoreElement(@NotNull final RefEntity refEntity) {
getProblemElements().remove(refEntity);
final CommonProblemDescriptor[] removedDescriptors = getProblemElements().remove(refEntity);
if (removedDescriptors != null) {
for (CommonProblemDescriptor descriptor : removedDescriptors) {
getProblemToElements().remove(descriptor);
}
}
getQuickFixActions().remove(refEntity);
}
@@ -32,6 +32,7 @@ import com.intellij.codeInspection.reference.RefEntity;
import com.intellij.codeInspection.reference.RefFile;
import com.intellij.openapi.diagnostic.Logger;
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;
import com.intellij.profile.codeInspection.ui.inspectionsTree.InspectionsConfigTreeComparator;
@@ -107,8 +108,18 @@ public class InspectionResultsViewComparator implements Comparator {
if (diff != 0) {
return diff;
}
return PsiUtilCore.compareElementsByPosition(((ProblemDescriptor)descriptor2).getEndElement(),
diff = PsiUtilCore.compareElementsByPosition(((ProblemDescriptor)descriptor2).getEndElement(),
((ProblemDescriptor)descriptor1).getEndElement());
if (diff != 0) return diff;
final TextRange range1 = ((ProblemDescriptor)descriptor1).getTextRangeInElement();
final TextRange range2 = ((ProblemDescriptor)descriptor2).getTextRangeInElement();
if (range1 != null && range2 != null) {
diff = range1.getStartOffset() - range2.getStartOffset();
if (diff != 0) return diff;
diff = range1.getEndOffset() - range2.getEndOffset();
if (diff != 0) return diff;
}
}
if (descriptor1 != null && descriptor2 != null) {
return descriptor1.getDescriptionTemplate().compareToIgnoreCase(descriptor2.getDescriptionTemplate());
@@ -1010,7 +1010,7 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj
JScrollPane optionsPane = ScrollPaneFactory.createScrollPane(myAdditionalOptionsPanel, true);
JPanel infoPanel = JBUI.Panels.simplePanel(optionsPane).withBorder(JBUI.Borders.emptyLeft(10));
mainPanel = new JPanel(new MyOptionsLayout(mySplitter, infoPanel, JBUI.scale(250)));
mainPanel = new JPanel(new MyOptionsLayout(mySplitter, infoPanel, JBUI.scale(150), JBUI.scale(400)));
mainPanel.add(mySplitter);
mainPanel.add(infoPanel);
} else {
@@ -1348,11 +1348,13 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj
private final JComponent myPanel;
private final JComponent myOptions;
private final int myMinOptionsWidth;
private final int myMaxOptionsWidth;
public MyOptionsLayout(@NotNull JComponent panel, @NotNull JComponent options, int minOptionsWidth) {
public MyOptionsLayout(@NotNull JComponent panel, @NotNull JComponent options, int minOptionsWidth, int maxOptionsWidth) {
myPanel = panel;
myOptions = options;
myMinOptionsWidth = minOptionsWidth;
myMaxOptionsWidth = maxOptionsWidth;
}
@Override
@@ -1365,9 +1367,8 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj
@Override
public void layoutContainer(Container parent) {
Rectangle bounds = parent.getBounds();
int availableWidth = bounds.width - myPanel.getPreferredSize().width;
int preferredWidth = myOptions.getPreferredSize().width;
int optionsWidth = Math.max(Math.min(availableWidth, preferredWidth), myMinOptionsWidth);
int optionsWidth = Math.max(Math.min(myMaxOptionsWidth, preferredWidth), myMinOptionsWidth);
myPanel.setBounds(new Rectangle(0, 0, bounds.width - optionsWidth, bounds.height));
myOptions.setBounds(new Rectangle(bounds.width - optionsWidth, 0, optionsWidth, bounds.height));
}