From 6e0ae95918c3f931a1bf05fdfb3fb89f85a6f9a7 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 23 May 2011 13:39:33 +0400 Subject: [PATCH 1/5] PsiDirectories are soft referenced --- .../psi/impl/file/impl/FileManagerImpl.java | 4 +- .../ConcurrentSoftValueHashMap.java | 70 ++++++++++++++++--- 2 files changed, 63 insertions(+), 11 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java index 8c70a41e371d..782325fd300d 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java @@ -51,7 +51,7 @@ import com.intellij.psi.search.SearchScope; import com.intellij.util.ConcurrencyUtil; import com.intellij.util.FileContentUtil; import com.intellij.util.containers.ConcurrentFactoryMap; -import com.intellij.util.containers.ConcurrentHashMap; +import com.intellij.util.containers.ConcurrentSoftValueHashMap; import com.intellij.util.containers.ConcurrentWeakValueHashMap; import com.intellij.util.messages.MessageBusConnection; import gnu.trove.THashMap; @@ -74,7 +74,7 @@ public class FileManagerImpl implements FileManager { private final ProjectRootManager myProjectRootManager; private ProjectFileIndex myProjectFileIndex = null; - private final ConcurrentMap myVFileToPsiDirMap = new ConcurrentHashMap(); + private final ConcurrentMap myVFileToPsiDirMap = new ConcurrentSoftValueHashMap(); private final ConcurrentWeakValueHashMap myVFileToViewProviderMap = new ConcurrentWeakValueHashMap(); private final Map myDefaultResolveScopesCache = new ConcurrentFactoryMap() { diff --git a/platform/util/src/com/intellij/util/containers/ConcurrentSoftValueHashMap.java b/platform/util/src/com/intellij/util/containers/ConcurrentSoftValueHashMap.java index 6db3e4f14356..95595dddd2e6 100644 --- a/platform/util/src/com/intellij/util/containers/ConcurrentSoftValueHashMap.java +++ b/platform/util/src/com/intellij/util/containers/ConcurrentSoftValueHashMap.java @@ -38,19 +38,14 @@ public final class ConcurrentSoftValueHashMap implements ConcurrentMap } private void processQueue() { - //int count = 0; while(true){ MyReference ref = (MyReference)myQueue.poll(); if (ref == null) { - //if (count > 0){ - // System.out.println("SoftValueHashMap: " + count + " references have been collected"); - //} return; } if (myMap.get(ref.key) == ref){ myMap.remove(ref.key); } - //count++; } } @@ -103,7 +98,64 @@ public final class ConcurrentSoftValueHashMap implements ConcurrentMap } public Set> entrySet() { - throw new RuntimeException("method not implemented"); + return new AbstractSet>() { + @Override + public Iterator> iterator() { + final Iterator>> refEntries = myMap.entrySet().iterator(); + return new Iterator>() { + Entry next; + @Override + public boolean hasNext() { + while (next == null) { + if (!refEntries.hasNext()) return false; + Entry> ref = refEntries.next(); + final K k = ref.getKey(); + V v = ref.getValue().get(); + next = v == null ? null : new AbstractMap.SimpleEntry(k,v){ + @Override + public V setValue(V value) { + V old = super.setValue(value); + put(k, value); + return old; + } + }; + } + return true; + } + + @Override + public Entry next() { + if (!hasNext()) throw new NoSuchElementException(); + Entry r = next; + next = null; + return r; + } + + @Override + public void remove() { + if (next == null) { + throw new NoSuchElementException(); + } + ConcurrentSoftValueHashMap.this.remove(next.getKey()); + } + }; + } + + @Override + public int size() { + return myMap.size(); + } + + @Override + public boolean remove(Object o) { + return ConcurrentSoftValueHashMap.this.remove(((Entry)o).getKey()) != null; + } + + @Override + public void clear() { + ConcurrentSoftValueHashMap.this.clear(); + } + }; } public V putIfAbsent(final K key, final V value) { @@ -145,10 +197,10 @@ public final class ConcurrentSoftValueHashMap implements ConcurrentMap } public void putAll(Map t) { - for (K k : t.keySet()) { - V v = t.get(k); + for (Entry entry : t.entrySet()) { + V v = entry.getValue(); if (v != null) { - put(k, v); + put(entry.getKey(), v); } } } From 24140e4319c81ff0b3d9213ea5dfac5f28c7e32f Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 23 May 2011 14:01:19 +0400 Subject: [PATCH 2/5] reverted --- .../openapi/editor/ex/util/EditorUtil.java | 2 +- .../openapi/editor/impl/EditorImpl.java | 51 ++++++++----------- .../openapi/editor/impl/IterationState.java | 20 +++----- 3 files changed, 30 insertions(+), 43 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java index 756e4c3df1e7..e254c3789cc0 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java @@ -306,7 +306,7 @@ public class EditorUtil { // hence, we need to perform special calculations to get know that. EditorEx editorImpl = (EditorEx)editor; int offset = start; - IterationState state = new IterationState(editorImpl, start, end, false); + IterationState state = new IterationState(editorImpl, offset, false); int fontType = state.getMergedAttributes().getFontType(); int column = currentColumn[0]; int spaceSize = getSpaceWidth(fontType, editorImpl); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index d4569dea33d9..9070139e7939 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -929,25 +929,24 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } } - int textLength = myDocument.getTextLength(); LogicalPosition logicalPosition = visualToLogicalPosition(new VisualPosition(line, 0)); int offset = logicalPositionToOffset(logicalPosition); + int textLength = myDocument.getTextLength(); if (offset >= textLength) return new VisualPosition(line, EditorUtil.columnsNumber(p.x, EditorUtil.getSpaceWidth(Font.PLAIN, this))); // There is a possible case that starting logical line is split by soft-wraps and it's part after the split should be drawn. // We mark that we're under such circumstances then. - boolean activeSoftWrapProcessed = logicalPosition.softWrapLinesOnCurrentLogicalLine <= 0; + boolean activeSoftWrapProcessed = true; + if (logicalPosition.softWrapLinesOnCurrentLogicalLine > 0) { + activeSoftWrapProcessed = false; + } int column = 0; int prevX = 0; CharSequence text = myDocument.getCharsNoThreadCheck(); char c = ' '; - - LogicalPosition endLogicalPosition = visualToLogicalPosition(new VisualPosition(line+1, 0)); - int endOffset = logicalPositionToOffset(endLogicalPosition); - - IterationState state = new IterationState(this, offset, endOffset, false); + IterationState state = new IterationState(this, offset, false); int fontType = state.getMergedAttributes().getFontType(); int spaceSize = EditorUtil.getSpaceWidth(fontType, this); @@ -1246,7 +1245,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi int offset = startOffset; CharSequence text = myDocument.getCharsNoThreadCheck(); int textLength = myDocument.getTextLength(); - IterationState state = new IterationState(this, startOffset, startOffset + length, false); + IterationState state = new IterationState(this, offset, false); int fontType = state.getMergedAttributes().getFontType(); int spaceSize = EditorUtil.getSpaceWidth(fontType, this); @@ -1810,9 +1809,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi int visibleLineNumber = clip.y / lineHeight; VisualPosition visualPosition = xyToVisualPosition(new Point(0, clip.y)); - VisualPosition endVisualPosition = xyToVisualPosition(new Point(0, clip.y+clip.height)); LogicalPosition logicalPosition = visualToLogicalPosition(visualPosition); - LogicalPosition endLogicalPosition = visualToLogicalPosition(endVisualPosition); Point position = new Point(0, visibleLineNumber * lineHeight); if (visualPosition.line == 0 && myPrefixText != null) { @@ -1830,10 +1827,9 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi boolean locateBeforeSoftWrap = !SoftWrapHelper.isCaretAfterSoftWrap(this); int start = logicalPositionToOffset(logicalPosition); - int end = logicalPositionToOffset(endLogicalPosition); getSoftWrapModel().registerSoftWrapsIfNecessary(); - IterationState iterationState = new IterationState(this, start, end, paintSelection()); + IterationState iterationState = new IterationState(this, start, paintSelection()); LineIterator lIterator = createLineIterator(); lIterator.start(start); @@ -2262,10 +2258,8 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi // position is expected to be set to null as an indication that no soft wrap-introduced visual lines should be skipped on // current painting iteration. Ref logicalPosition = new Ref(xyToLogicalPosition(new Point(0, clip.y))); - LogicalPosition endLogicalPosition = xyToLogicalPosition(new Point(0, clip.y + clip.height)); int startLineNumber = logicalPosition.get().line; int start = logicalPositionToOffset(logicalPosition.get()); - int end = logicalPositionToOffset(endLogicalPosition); Point position = new Point(0, visibleLineNumber * lineHeight); if (startLineNumber == 0 && myPrefixText != null) { @@ -2278,7 +2272,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi return; } - IterationState iterationState = new IterationState(this, start, end, paintSelection()); + IterationState iterationState = new IterationState(this, start, paintSelection()); LineIterator lIterator = createLineIterator(); lIterator.start(start); if (lIterator.atEnd()) { @@ -2336,8 +2330,14 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } else { - position.x = drawStringWithSoftWraps(g, chars, start, Math.min(hEnd, lEnd - lIterator.getSeparatorLength()) , position, clip, - effectColor, effectType, fontType, currentColor, logicalPosition); + if (hEnd > lEnd - lIterator.getSeparatorLength()) { + position.x = drawStringWithSoftWraps(g, chars, start, lEnd - lIterator.getSeparatorLength(), position, clip, + effectColor, effectType, fontType, currentColor, logicalPosition); + } + else { + position.x = drawStringWithSoftWraps(g, chars, start, hEnd, position, clip, effectColor, effectType, fontType, + currentColor, logicalPosition); + } } iterationState.advance(); @@ -3054,11 +3054,11 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } int start = myDocument.getLineStartOffset(pos.line); - if (pos.column == 0) return start; int end = myDocument.getLineEndOffset(pos.line); CharSequence text = myDocument.getCharsNoThreadCheck(); + if (pos.column == 0) return start; return EditorUtil.calcOffset(this, text, start, end, pos.column, EditorUtil.getTabSize(this)); } @@ -5518,7 +5518,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } final CharSequence text = myDocument.getCharsNoThreadCheck(); - int documentLength = myDocument.getTextLength(); + int end = myDocument.getTextLength(); int x = 0; boolean lastLineLengthCalculated = false; final int fontSize = myScheme.getEditorFontSize(); @@ -5548,19 +5548,12 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } } - int endLine; - for (endLine=line+1; endLine= state.getEndOffset()) { state.advance(); @@ -5662,7 +5655,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi } public int calcColumnNumber(CharSequence text, int start, int offset, int tabSize) { - IterationState state = new IterationState(this, start, start+offset, false); + IterationState state = new IterationState(this, start, false); int fontType = state.getMergedAttributes().getFontType(); int column = 0; int x = 0; diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java index 1ec2336dd351..93aff891a42e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IterationState.java @@ -73,14 +73,11 @@ public final class IterationState { private final EditorEx myEditor; private final Color myReadOnlyColor; - public IterationState(@NotNull EditorEx editor, int start, boolean useCaretAndSelection) { - this(editor, start, editor.getDocument().getTextLength(), useCaretAndSelection); - } - public IterationState(@NotNull EditorEx editor, int start, int end, boolean useCaretAndSelection) { + public IterationState(EditorEx editor, int start, boolean useCaretAndSelection) { ApplicationManager.getApplication().assertReadAccessAllowed(); myDocument = (DocumentEx)editor.getDocument(); myStartOffset = start; - myEnd = end; + myEnd = editor.getDocument().getTextLength(); myEditor = editor; LOG.assertTrue(myStartOffset <= myEnd); @@ -108,10 +105,10 @@ public final class IterationState { myCurrentHighlighters = new ArrayList(); MarkupModelEx editorMarkup = (MarkupModelEx)editor.getMarkupModel(); - myView.init(editorMarkup, start, myEnd); + myView.init(editorMarkup, start); final MarkupModelEx docMarkup = (MarkupModelEx)editor.getDocument().getMarkupModel(editor.getProject()); - myDoc.init(docMarkup, start, myEnd); + myDoc.init(docMarkup, start); myEndOffset = myStartOffset; @@ -122,8 +119,8 @@ public final class IterationState { private RangeHighlighterEx myNextHighlighter = null; private Iterator myIterator; - private void init(@NotNull MarkupModelEx markupModel, int start, int end) { - myIterator = markupModel.overlappingIterator(start, end); + private void init(MarkupModelEx markupModel, int start) { + myIterator = markupModel.overlappingIterator(start, myDocument.getTextLength()); int skipped = 0; while (myIterator.hasNext()) { RangeHighlighterEx highlighter = myIterator.next(); @@ -133,10 +130,7 @@ public final class IterationState { } skipped++; } - if (skipped > Math.min(1000, markupModel.getDocument().getTextLength())) { - int i = 0; - //LOG.error("Inefficient iteration, use 'new IterationState(start, end)' constructor to limit the number of highlighters to iterate"); - } + int i = skipped; } private void advance() { From bb5e5e0fe7fbb8e2504f1eac618902558ee9835a Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 23 May 2011 11:28:48 +0400 Subject: [PATCH 3/5] implementations popup: check always names --- .../codeInsight/hint/ImplementationViewComponent.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewComponent.java index c9195be08742..dc36e9d74cd4 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewComponent.java @@ -109,11 +109,7 @@ public class ImplementationViewComponent extends JPanel { return presentableName; } - if (UISettings.getInstance().HIDE_KNOWN_EXTENSION_IN_TABS) { - if (Comparing.strEqual(presentableName, myElementPresentation)) { - return presentableName; - } - } else if (Comparing.strEqual(presentableName, myElementPresentation + "." + vFile.getExtension())){ + if (Comparing.strEqual(vFile.getName(), myElementPresentation + "." + vFile.getExtension())){ return presentableName; } From ea2e67e3e6ea774b414881e6510aa2591e8f979c Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 23 May 2011 14:30:06 +0400 Subject: [PATCH 4/5] EA-27916 - SOE: RefMethodImpl.updateReturnValueTemplate --- .../intellij/codeInspection/reference/RefMethodImpl.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java b/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java index 1ab4f888c691..f5aa2c90b0a7 100644 --- a/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/reference/RefMethodImpl.java @@ -179,6 +179,9 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod { @NotNull public Collection getSuperMethods() { if (mySuperMethods == null) return EMPTY_METHOD_LIST; + if (mySuperMethods.size() > 10) { + LOG.info("method: " + getName() + " owner:" + getOwnerClass().getQualifiedName()); + } return mySuperMethods; } @@ -216,7 +219,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod { } public void addSuperMethod(RefMethodImpl refSuperMethod) { - if (!getSuperMethods().contains(refSuperMethod)) { + if (!getSuperMethods().contains(refSuperMethod) && !refSuperMethod.getSuperMethods().contains(this)) { if (mySuperMethods == null){ mySuperMethods = new ArrayList(1); } @@ -225,7 +228,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod { } public void markExtended(RefMethodImpl method) { - if (!getDerivedMethods().contains(method)) { + if (!getDerivedMethods().contains(method) && !method.getDerivedMethods().contains(this)) { if (myDerivedMethods == null) { myDerivedMethods = new ArrayList(1); } From 9b4a4e99af22e0ddebe78082f0b4f8b85b9364dd Mon Sep 17 00:00:00 2001 From: anna Date: Mon, 23 May 2011 14:31:03 +0400 Subject: [PATCH 5/5] create project: reuse one sdk step (IDEA-69921) --- .../projectWizard/ProjectWizardStepFactoryImpl.java | 8 +++++++- .../intellij/ide/util/projectWizard/WizardContext.java | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/java/idea-ui/src/com/intellij/ide/util/projectWizard/ProjectWizardStepFactoryImpl.java b/java/idea-ui/src/com/intellij/ide/util/projectWizard/ProjectWizardStepFactoryImpl.java index 12507d9b6d59..e6351824a20a 100644 --- a/java/idea-ui/src/com/intellij/ide/util/projectWizard/ProjectWizardStepFactoryImpl.java +++ b/java/idea-ui/src/com/intellij/ide/util/projectWizard/ProjectWizardStepFactoryImpl.java @@ -95,7 +95,11 @@ public class ProjectWizardStepFactoryImpl extends ProjectWizardStepFactory { } public ModuleWizardStep createProjectJdkStep(final WizardContext wizardContext) { - return new ProjectJdkStep(wizardContext){ + ModuleWizardStep projectSdkStep = wizardContext.getProjectSdkStep(); + if (projectSdkStep instanceof ProjectJdkStep) { + return projectSdkStep; + } + projectSdkStep = new ProjectJdkStep(wizardContext) { public boolean isStepVisible() { final Sdk newProjectJdk = AddModuleWizard.getNewProjectJdk(wizardContext); if (newProjectJdk == null) return true; @@ -103,6 +107,8 @@ public class ProjectWizardStepFactoryImpl extends ProjectWizardStepFactory { return projectBuilder != null && !projectBuilder.isSuitableSdk(newProjectJdk); } }; + wizardContext.setProjectSdkStep(projectSdkStep); + return projectSdkStep; } @Nullable diff --git a/platform/lang-api/src/com/intellij/ide/util/projectWizard/WizardContext.java b/platform/lang-api/src/com/intellij/ide/util/projectWizard/WizardContext.java index 2a608531a170..81aeedb78d9e 100644 --- a/platform/lang-api/src/com/intellij/ide/util/projectWizard/WizardContext.java +++ b/platform/lang-api/src/com/intellij/ide/util/projectWizard/WizardContext.java @@ -44,6 +44,8 @@ public class WizardContext { private final List myListeners = new ArrayList(); private StorageScheme myProjectStorageFormat = StorageScheme.DEFAULT; + private ModuleWizardStep myProjectSdkStep; + public void setProjectStorageFormat(StorageScheme format) { myProjectStorageFormat = format; } @@ -65,6 +67,14 @@ public class WizardContext { return myProject; } + public ModuleWizardStep getProjectSdkStep() { + return myProjectSdkStep; + } + + public void setProjectSdkStep(ModuleWizardStep projectSdkStep) { + myProjectSdkStep = projectSdkStep; + } + @NotNull public String getProjectFileDirectory() { if (myProjectFileDirectory != null) {