diff --git a/build/conf/classVersions.txt b/build/conf/classVersions.txt index cdd775177c7b..85b9258e9f57 100644 --- a/build/conf/classVersions.txt +++ b/build/conf/classVersions.txt @@ -35,7 +35,6 @@ 1.5 => plugins/Groovy/lib/groovy_rt.jar 1.5 => lib/annotations.jar -1.8 => lib/annotations-java8.jar 1.8 => redist/annotations-java8.jar 1.6 => plugins/gradle/lib/gradle-jps-plugin.jar diff --git a/build/scripts/layouts.gant b/build/scripts/layouts.gant index 99ef7740bfce..09de57938134 100644 --- a/build/scripts/layouts.gant +++ b/build/scripts/layouts.gant @@ -137,10 +137,6 @@ def layoutFull(String home, String targetDirectory, String patchedDescriptorDir module("annotations-common") module("annotations") } - jar("annotations-java8.jar") { - module("annotations-common") - module("annotations-java8") - } jar("jdkAnnotations.jar") { fileset(dir: "${home}/java/jdkAnnotations") } @@ -218,6 +214,13 @@ def layoutFull(String home, String targetDirectory, String patchedDescriptorDir } } + dir("redist") { + jar("annotations-java8.jar") { + module("annotations-common") + module("annotations-java8") + } + } + layoutCommunityPlugins(home) dir("plugins") { diff --git a/build/scripts/tests.gant b/build/scripts/tests.gant index 85a867015574..0fb3490efb47 100644 --- a/build/scripts/tests.gant +++ b/build/scripts/tests.gant @@ -25,7 +25,6 @@ if ("GIT_TESTS".equalsIgnoreCase(System.getProperty("idea.test.group"))) { def args = [ "-Xmx450m", - "-XX:MaxPermSize=430m", "-Dsun.io.useCanonCaches=false" ] diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/LambdaSmartStepTarget.java b/java/debugger/impl/src/com/intellij/debugger/actions/LambdaSmartStepTarget.java index dec71630764e..e81156611684 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/LambdaSmartStepTarget.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/LambdaSmartStepTarget.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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,12 +15,17 @@ */ package com.intellij.debugger.actions; +import com.intellij.icons.AllIcons; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiLambdaExpression; +import com.intellij.psi.PsiSubstitutor; +import com.intellij.psi.util.PsiFormatUtil; import com.intellij.util.Range; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.*; + /** * @author Eugene Zhuravlev * Date: 10/25/13 @@ -43,6 +48,20 @@ public class LambdaSmartStepTarget extends SmartStepTarget{ return myOrdinal; } + @Nullable + @Override + public Icon getIcon() { + return AllIcons.Nodes.Function; + } + + @NotNull + @Override + public String getPresentation() { + String typeText = PsiFormatUtil.formatType(myLambda.getType(), 0, PsiSubstitutor.EMPTY); + String label = getLabel(); + return label != null ? label + typeText : typeText; + } + public boolean equals(Object o) { if (this == o) { return true; diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/MethodSmartStepTarget.java b/java/debugger/impl/src/com/intellij/debugger/actions/MethodSmartStepTarget.java index 69281e66c9bd..fff689783af1 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/MethodSmartStepTarget.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/MethodSmartStepTarget.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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,10 +17,15 @@ package com.intellij.debugger.actions; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiMethod; +import com.intellij.psi.PsiSubstitutor; +import com.intellij.psi.util.PsiFormatUtil; +import com.intellij.psi.util.PsiFormatUtilBase; import com.intellij.util.Range; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.*; + /** * @author Eugene Zhuravlev * Date: 10/25/13 @@ -38,6 +43,25 @@ public class MethodSmartStepTarget extends SmartStepTarget { return myMethod; } + @Override + public Icon getIcon() { + return myMethod.getIcon(0); + } + + @NotNull + @Override + public String getPresentation() { + String label = getLabel(); + String formatted = PsiFormatUtil.formatMethod( + myMethod, + PsiSubstitutor.EMPTY, + PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, + PsiFormatUtilBase.SHOW_TYPE, + 999 + ); + return label != null? label + formatted : formatted; + } + public boolean equals(Object o) { if (this == o) { return true; diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/PsiMethodListPopupStep.java b/java/debugger/impl/src/com/intellij/debugger/actions/PsiMethodListPopupStep.java index 335a188cbe3b..eb64da77bdad 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/PsiMethodListPopupStep.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/PsiMethodListPopupStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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,13 +17,8 @@ package com.intellij.debugger.actions; import com.intellij.codeInsight.unwrap.ScopeHighlighter; import com.intellij.debugger.DebuggerBundle; -import com.intellij.icons.AllIcons; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.ui.popup.*; -import com.intellij.psi.PsiLambdaExpression; -import com.intellij.psi.PsiMethod; -import com.intellij.psi.PsiSubstitutor; -import com.intellij.psi.util.PsiFormatUtil; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -62,38 +57,13 @@ class PsiMethodListPopupStep implements ListPopupStep { return true; } - public Icon getIconFor(SmartStepTarget aValue) { - if (aValue instanceof MethodSmartStepTarget) { - return ((MethodSmartStepTarget)aValue).getMethod().getIcon(0); - } - if (aValue instanceof LambdaSmartStepTarget) { - return AllIcons.Nodes.Function; - } - return null; + public Icon getIconFor(SmartStepTarget avalue) { + return avalue.getIcon(); } @NotNull - public String getTextFor(SmartStepTarget value) { - final String label = value.getLabel(); - final String formatted; - if (value instanceof MethodSmartStepTarget) { - final PsiMethod method = ((MethodSmartStepTarget)value).getMethod(); - formatted = PsiFormatUtil.formatMethod( - method, - PsiSubstitutor.EMPTY, - PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS, - PsiFormatUtil.SHOW_TYPE, - 999 - ); - } - else if (value instanceof LambdaSmartStepTarget){ - final PsiLambdaExpression lambda = ((LambdaSmartStepTarget)value).getLambda(); - formatted = PsiFormatUtil.formatType(lambda.getType(), 0, PsiSubstitutor.EMPTY); - } - else { - formatted = ""; - } - return label != null? label + formatted : formatted; + public String getTextFor(SmartStepTarget value) { + return value.getPresentation(); } public ListSeparator getSeparatorAbove(SmartStepTarget value) { @@ -132,7 +102,7 @@ class PsiMethodListPopupStep implements ListPopupStep { return false; } - public MnemonicNavigationFilter getMnemonicNavigationFilter() { + public MnemonicNavigationFilter getMnemonicNavigationFilter() { return null; } @@ -140,7 +110,7 @@ class PsiMethodListPopupStep implements ListPopupStep { return false; } - public SpeedSearchFilter getSpeedSearchFilter() { + public SpeedSearchFilter getSpeedSearchFilter() { return null; } diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/SmartStepTarget.java b/java/debugger/impl/src/com/intellij/debugger/actions/SmartStepTarget.java index 4fd7a3ea9e96..70803260c64c 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/SmartStepTarget.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/SmartStepTarget.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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,10 +15,14 @@ */ package com.intellij.debugger.actions; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.util.Range; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.*; + /** * @author Eugene Zhuravlev * Date: 10/25/13 @@ -58,4 +62,14 @@ public abstract class SmartStepTarget { public void setCallingExpressionLines(Range expressionLines) { myExpressionLines = expressionLines; } + + @Nullable + public Icon getIcon() { + return null; + } + + @NotNull + public String getPresentation() { + return StringUtil.notNullize(getLabel()); + } } diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/RefCountHolder.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/RefCountHolder.java index 71dfe1355436..dc9be261626f 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/RefCountHolder.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/RefCountHolder.java @@ -276,18 +276,22 @@ class RefCountHolder { TextRange dirtyScope, @NotNull ProgressIndicator indicator, @NotNull Runnable analyze) { + ProgressIndicator result; if (myState.compareAndSet(EMPTY, indicator)) { if (!file.getTextRange().equals(dirtyScope)) { // empty holder needs filling before it can be used, so restart daemon to re-analyze the whole file myState.set(EMPTY); return false; } + result = EMPTY; } - else if (!myState.compareAndSet(READY, indicator)) { + else if (myState.compareAndSet(READY, indicator)) { + result = READY; + } + else { log("a: failed to change ", myState, "->", indicator); return false; } - boolean success = false; try { log("a: changed ", myState, "->", indicator); if (dirtyScope != null) { @@ -300,11 +304,10 @@ class RefCountHolder { } analyze.run(); - success = true; + result = READY; return true; } finally { - ProgressIndicator result = success ? READY : EMPTY; boolean set = myState.compareAndSet(indicator, result); assert set : myState.get(); log("a: changed after analyze", indicator, "->", result); diff --git a/java/java-impl/src/com/intellij/codeEditor/JavaEditorFileSwapper.java b/java/java-impl/src/com/intellij/codeEditor/JavaEditorFileSwapper.java index d0b7f022bcc6..eac8b001f123 100644 --- a/java/java-impl/src/com/intellij/codeEditor/JavaEditorFileSwapper.java +++ b/java/java-impl/src/com/intellij/codeEditor/JavaEditorFileSwapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -25,6 +25,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.impl.compiled.ClsClassImpl; import com.intellij.psi.util.PsiTreeUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class JavaEditorFileSwapper extends EditorFileSwapper { @@ -76,12 +77,12 @@ public class JavaEditorFileSwapper extends EditorFileSwapper { } @Nullable - public static VirtualFile findSourceFile(Project project, VirtualFile file) { + public static VirtualFile findSourceFile(@NotNull Project project, @NotNull VirtualFile file) { PsiFile psiFile = PsiManager.getInstance(project).findFile(file); - if ((psiFile instanceof PsiCompiledFile && psiFile instanceof PsiClassOwner)) { - PsiClass clsClass = ((PsiClassOwner)psiFile).getClasses()[0]; - if ((clsClass instanceof ClsClassImpl)) { - PsiClass sourceClass = ((ClsClassImpl)clsClass).getSourceMirrorClass(); + if (psiFile instanceof PsiCompiledFile && psiFile instanceof PsiClassOwner) { + PsiClass[] classes = ((PsiClassOwner)psiFile).getClasses(); + if (classes.length != 0 && classes[0] instanceof ClsClassImpl) { + PsiClass sourceClass = ((ClsClassImpl)classes[0]).getSourceMirrorClass(); if (sourceClass != null) { VirtualFile result = sourceClass.getContainingFile().getVirtualFile(); assert result != null : sourceClass; diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/ReferenceExpressionCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/ReferenceExpressionCompletionContributor.java index 476fcaf2531a..f68c8b046079 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/ReferenceExpressionCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/ReferenceExpressionCompletionContributor.java @@ -485,7 +485,7 @@ public class ReferenceExpressionCompletionContributor { if (expr instanceof PsiReferenceExpression) { return (PsiReferenceExpression)expr; } - LOG.error("Unexpected type: " + expr.getType() + " from text " + text); + LOG.error("Unexpected type: " + expr.getClass() + " from text " + text); return null; } catch (IncorrectOperationException e) { diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java index 1fca087d0d1c..73b067ce25ed 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java @@ -384,8 +384,17 @@ public abstract class OrderEntryFix implements IntentionAction, LocalQuickFix { @Nullable public static String locateAnnotationsJar(@NotNull Module module) { - String jarName = EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(module).isAtLeast(LanguageLevel.JDK_1_8) ? "annotations-java8.jar" : "annotations.jar"; - final LocateLibraryDialog dialog = new LocateLibraryDialog(module, PathManager.getLibPath(), jarName, QuickFixBundle.message("add.library.annotations.description")); + String jarName; + String libPath; + if (EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(module).isAtLeast(LanguageLevel.JDK_1_8)) { + jarName = "annotations-java8.jar"; + libPath = new File(PathManager.getHomePath(), "redist").getAbsolutePath(); + } + else { + jarName = "annotations.jar"; + libPath = PathManager.getLibPath(); + } + final LocateLibraryDialog dialog = new LocateLibraryDialog(module, libPath, jarName, QuickFixBundle.message("add.library.annotations.description")); return dialog.showAndGet() ? dialog.getResultingLibraryPath() : null; } diff --git a/platform/analysis-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java b/platform/analysis-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java index d51ab1842bb4..d1337d5883ad 100644 --- a/platform/analysis-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java +++ b/platform/analysis-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -149,7 +149,7 @@ public abstract class TextEditorHighlightingPass implements HighlightingPass { @Override @NonNls public String toString() { - return getClass() + "; id=" + getId(); + return (getClass().isAnonymousClass() ? getClass().getSuperclass() : getClass()).getSimpleName() + "; id=" + getId(); } public boolean isRunIntentionPassAfter() { diff --git a/platform/annotations/annotations.iml b/platform/annotations/annotations.iml index a60e6489f219..7bb67096ad16 100644 --- a/platform/annotations/annotations.iml +++ b/platform/annotations/annotations.iml @@ -3,7 +3,6 @@ - diff --git a/platform/core-api/src/com/intellij/psi/stubs/PsiFileStubImpl.java b/platform/core-api/src/com/intellij/psi/stubs/PsiFileStubImpl.java index 207e7649a3d6..60ba5f21a0d2 100644 --- a/platform/core-api/src/com/intellij/psi/stubs/PsiFileStubImpl.java +++ b/platform/core-api/src/com/intellij/psi/stubs/PsiFileStubImpl.java @@ -20,6 +20,7 @@ package com.intellij.psi.stubs; import com.intellij.lang.Language; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.PsiFile; import com.intellij.psi.tree.IStubFileElementType; import org.jetbrains.annotations.NotNull; @@ -45,7 +46,7 @@ public class PsiFileStubImpl extends StubBase implements P public void setPsi(@NotNull final T psi) { myFile = psi; } - + public void clearPsi(@NotNull String reason) { myInvalidationReason = reason; myFile = null; @@ -73,6 +74,9 @@ public class PsiFileStubImpl extends StubBase implements P } public void setStubRoots(@NotNull PsiFileStub[] roots) { + if (roots.length == 0) { + Logger.getInstance(getClass()).error("Incorrect psi file stub roots count" + this + "," + getStubType()); + } myStubRoots = roots; } } \ No newline at end of file diff --git a/platform/core-api/src/com/intellij/psi/stubs/StubSerializationHelper.java b/platform/core-api/src/com/intellij/psi/stubs/StubSerializationHelper.java index db52c572d1a8..aba1221fed2e 100644 --- a/platform/core-api/src/com/intellij/psi/stubs/StubSerializationHelper.java +++ b/platform/core-api/src/com/intellij/psi/stubs/StubSerializationHelper.java @@ -16,6 +16,7 @@ package com.intellij.psi.stubs; import com.intellij.openapi.diagnostic.LogUtil; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream; import com.intellij.util.containers.RecentStringInterner; import com.intellij.util.io.AbstractStringEnumerator; @@ -77,15 +78,22 @@ public class StubSerializationHelper { BufferExposingByteArrayOutputStream out = new BufferExposingByteArrayOutputStream(); FileLocalStringEnumerator storage = new FileLocalStringEnumerator(true); StubOutputStream stubOutputStream = new StubOutputStream(out, storage); + boolean doDefaultSerialization = true; if (rootStub instanceof PsiFileStub) { final PsiFileStub[] roots = ((PsiFileStub)rootStub).getStubRoots(); - DataInputOutputUtil.writeINT(stubOutputStream, roots.length); - for (PsiFileStub root : roots) { - doSerialize(root, stubOutputStream); + if (roots.length == 0) { + Logger.getInstance(getClass()).error("Incorrect stub files count during serialization:" + rootStub + "," + rootStub.getStubType()); + } else { + doDefaultSerialization = false; + DataInputOutputUtil.writeINT(stubOutputStream, roots.length); + for (PsiFileStub root : roots) { + doSerialize(root, stubOutputStream); + } } } - else { + + if (doDefaultSerialization) { DataInputOutputUtil.writeINT(stubOutputStream, 1); doSerialize(rootStub, stubOutputStream); } @@ -137,6 +145,9 @@ public class StubSerializationHelper { return stubsArray[0]; } else { + if (stubFilesCount != 1) { + Logger.getInstance(getClass()).error("Incorrect stub files count during deserialization:"+stubFilesCount); + } return deserialize(inputStream, null); } } diff --git a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java index ceb856e077e6..527c87bd01ca 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java +++ b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java @@ -35,16 +35,16 @@ import java.lang.ref.SoftReference; * User: cdr */ public class SelfElementInfo implements SmartPointerElementInfo { - protected final VirtualFile myVirtualFile; + private final VirtualFile myVirtualFile; private Reference myMarkerRef; // create marker only in case of live document private volatile int mySyncStartOffset; private volatile int mySyncEndOffset; - protected volatile boolean mySyncMarkerIsValid; + volatile boolean mySyncMarkerIsValid; private final Class myType; - protected final Project myProject; - @SuppressWarnings({"UnusedDeclaration"}) + private final Project myProject; + @SuppressWarnings("UnusedDeclaration") private volatile RangeMarker myRangeMarker; //maintains hard reference during modification - protected final Language myLanguage; + private final Language myLanguage; SelfElementInfo(@NotNull Project project, @NotNull ProperTextRange range, @@ -157,7 +157,7 @@ public class SelfElementInfo implements SmartPointerElementInfo { return restoreFromFile(file); } - protected PsiElement restoreFromFile(@NotNull PsiFile file) { + private PsiElement restoreFromFile(@NotNull PsiFile file) { final int syncStartOffset = getSyncStartOffset(); final int syncEndOffset = getSyncEndOffset(); diff --git a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerElementInfo.java b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerElementInfo.java index 8200cad50070..e0bf6b2eb10c 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerElementInfo.java +++ b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerElementInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -30,7 +30,7 @@ interface SmartPointerElementInfo { @Nullable Document getDocumentToSynchronize(); - void fastenBelt(int offset, RangeMarker[] cachedRangeMarkers); + void fastenBelt(int offset, @Nullable RangeMarker[] cachedRangeMarkers); void unfastenBelt(int offset); diff --git a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerEx.java b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerEx.java index acce06a05bff..df0ca95ae7d0 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerEx.java +++ b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerEx.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -20,7 +20,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.SmartPsiElementPointer; import org.jetbrains.annotations.Nullable; -public interface SmartPointerEx extends SmartPsiElementPointer { +interface SmartPointerEx extends SmartPsiElementPointer { void fastenBelt(int offset, @Nullable RangeMarker[] cachedRangeMarkers); void unfastenBelt(int offset); diff --git a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java index 8e46b571bdc3..54ad834f2a6b 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPointerManagerImpl.java @@ -162,26 +162,25 @@ public class SmartPointerManagerImpl extends SmartPointerManager { } processQueue(); SmartPointerEx pointer = getCachedPointer(element); - if (pointer != null) { - containingFile = containingFile == null ? element.getContainingFile() : containingFile; - if (containingFile != null && areBeltsFastened(containingFile.getViewProvider().getVirtualFile())) { - pointer.fastenBelt(0, null); - } - } - else { + if (pointer == null) { pointer = new SmartPsiElementPointerImpl(myProject, element, containingFile); if (containingFile != null) { - initPointer(pointer, containingFile.getViewProvider().getVirtualFile()); + initPointer((SmartPsiElementPointerImpl)pointer, containingFile.getViewProvider().getVirtualFile()); } element.putUserData(CACHED_SMART_POINTER_KEY, new SoftReference(pointer)); } - if (pointer instanceof SmartPsiElementPointerImpl) { + else { + containingFile = containingFile == null ? element.getContainingFile() : containingFile; synchronized (lock) { - ((SmartPsiElementPointerImpl)pointer).incrementAndGetReferenceCount(1); + if (containingFile != null && areBeltsFastened(containingFile.getViewProvider().getVirtualFile())) { + pointer.fastenBelt(0, null); + } + if (pointer instanceof SmartPsiElementPointerImpl) { + ((SmartPsiElementPointerImpl)pointer).incrementAndGetReferenceCount(1); + } } } return pointer; - } private static SmartPointerEx getCachedPointer(@NotNull E element) { @@ -210,51 +209,52 @@ public class SmartPointerManagerImpl extends SmartPointerManager { return pointer; } - private void initPointer(@NotNull SmartPointerEx pointer, @NotNull VirtualFile containingFile) { + private void initPointer(@NotNull SmartPsiElementPointerImpl pointer, @NotNull VirtualFile containingFile) { synchronized (lock) { Set pointers = getPointers(containingFile); if (pointers == null) { pointers = ContainerUtil.newTroveSet(); // we synchronise access anyway containingFile.putUserData(POINTERS_KEY, pointers); } - pointers.add(new PointerReference(pointer, containingFile, ourQueue, POINTERS_KEY)); - if (areBeltsFastened(containingFile)) { pointer.fastenBelt(0, null); } + pointer.incrementAndGetReferenceCount(1); + + pointers.add(new PointerReference(pointer, containingFile, ourQueue, POINTERS_KEY)); } } @Override public boolean removePointer(@NotNull SmartPsiElementPointer pointer) { + if (!(pointer instanceof SmartPsiElementPointerImpl)) { + return false; + } + PsiFile containingFile = pointer.getContainingFile(); + if (containingFile == null) return false; synchronized (lock) { - if (pointer instanceof SmartPsiElementPointerImpl) { - int refCount = ((SmartPsiElementPointerImpl)pointer).incrementAndGetReferenceCount(-1); - if (refCount == 0) { - PsiElement element = ((SmartPointerEx)pointer).getCachedElement(); - if (element != null) { - element.putUserData(CACHED_SMART_POINTER_KEY, null); - } - PsiFile containingFile = pointer.getContainingFile(); - if (containingFile == null) return false; + int refCount = ((SmartPsiElementPointerImpl)pointer).incrementAndGetReferenceCount(-1); + if (refCount == 0) { + PsiElement element = ((SmartPointerEx)pointer).getCachedElement(); + if (element != null) { + element.putUserData(CACHED_SMART_POINTER_KEY, null); + } - VirtualFile vFile = containingFile.getViewProvider().getVirtualFile(); - Set pointers = getPointers(vFile); - if (pointers == null) return false; + VirtualFile vFile = containingFile.getViewProvider().getVirtualFile(); + Set pointers = getPointers(vFile); + if (pointers == null) return false; - SmartPointerElementInfo info = ((SmartPsiElementPointerImpl)pointer).getElementInfo(); - info.cleanup(); + SmartPointerElementInfo info = ((SmartPsiElementPointerImpl)pointer).getElementInfo(); + info.cleanup(); - for (Iterator iterator = pointers.iterator(); iterator.hasNext(); ) { - if (pointer == iterator.next().get()) { - iterator.remove(); - if (pointers.isEmpty()) { - vFile.putUserData(POINTERS_KEY, null); - } - return true; + for (Iterator iterator = pointers.iterator(); iterator.hasNext(); ) { + if (pointer == iterator.next().get()) { + iterator.remove(); + if (pointers.isEmpty()) { + vFile.putUserData(POINTERS_KEY, null); } + return true; } - return false; } } } @@ -295,7 +295,7 @@ public class SmartPointerManagerImpl extends SmartPointerManager { file.putUserData(POINTERS_ARE_FASTENED_KEY, null); return fastened; } - private boolean areBeltsFastened(VirtualFile file) { + private boolean areBeltsFastened(@NotNull VirtualFile file) { return file.getUserData(POINTERS_ARE_FASTENED_KEY) == Boolean.TRUE; } diff --git a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java index c01a938a2cbb..2ea0695a08f0 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java @@ -188,7 +188,7 @@ class SmartPsiElementPointerImpl implements SmartPointerEx } @NotNull - public SmartPointerElementInfo getElementInfo() { + SmartPointerElementInfo getElementInfo() { return myElementInfo; } diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/NamedObjectProviderBinding.java b/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/NamedObjectProviderBinding.java index e847b542cee1..1564efffe4f1 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/NamedObjectProviderBinding.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/NamedObjectProviderBinding.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -29,38 +29,39 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; /** * @author maxim */ -public abstract class NamedObjectProviderBinding implements ProviderBinding { - private final Map>> myNamesToProvidersMap = new THashMap>>(5); - private final Map>> myNamesToProvidersMapInsensitive = new THashMap>>(5); +public abstract class NamedObjectProviderBinding implements ProviderBinding { + private final Map>> myNamesToProvidersMap = new THashMap>>(5); + private final Map>> myNamesToProvidersMapInsensitive = new THashMap>>(5); public void registerProvider(@NonNls @NotNull String[] names, @NotNull ElementPattern filter, boolean caseSensitive, - @NotNull Provider provider, + @NotNull PsiReferenceProvider provider, final double priority) { - final Map>> map = caseSensitive ? myNamesToProvidersMap : myNamesToProvidersMapInsensitive; + final Map>> map = caseSensitive ? myNamesToProvidersMap : myNamesToProvidersMapInsensitive; for (final String attributeName : names) { String key = caseSensitive ? attributeName : attributeName.toLowerCase(); - List> psiReferenceProviders = map.get(key); + List> psiReferenceProviders = map.get(key); if (psiReferenceProviders == null) { - map.put(key, psiReferenceProviders = new SmartList>()); + map.put(key, psiReferenceProviders = new SmartList>()); } - psiReferenceProviders.add(new ProviderInfo(provider, filter, priority)); + psiReferenceProviders.add(new ProviderInfo(provider, filter, priority)); } } @Override public void addAcceptableReferenceProviders(@NotNull PsiElement position, - @NotNull List> list, + @NotNull List> list, @NotNull PsiReferenceService.Hints hints) { String name = getName(position); if (name != null) { @@ -70,16 +71,16 @@ public abstract class NamedObjectProviderBinding implements ProviderBi } @Override - public void unregisterProvider(@NotNull final Provider provider) { - for (final List> list : myNamesToProvidersMap.values()) { - for (final ProviderInfo trinity : new ArrayList>(list)) { + public void unregisterProvider(@NotNull final PsiReferenceProvider provider) { + for (final List> list : myNamesToProvidersMap.values()) { + for (final ProviderInfo trinity : new ArrayList>(list)) { if (trinity.provider.equals(provider)) { list.remove(trinity); } } } - for (final List> list : myNamesToProvidersMapInsensitive.values()) { - for (final ProviderInfo trinity : new ArrayList>(list)) { + for (final List> list : myNamesToProvidersMapInsensitive.values()) { + for (final ProviderInfo trinity : new ArrayList>(list)) { if (trinity.provider.equals(provider)) { list.remove(trinity); } @@ -88,16 +89,18 @@ public abstract class NamedObjectProviderBinding implements ProviderBi } @Nullable - protected abstract String getName(final PsiElement position); + protected abstract String getName(@NotNull PsiElement position); - private void addMatchingProviders(final PsiElement position, - @Nullable final List> providerList, - @NotNull List> ret, - PsiReferenceService.Hints hints) { + static void addMatchingProviders(@NotNull PsiElement position, + @Nullable final List> providerList, + @NotNull Collection> output, + @NotNull PsiReferenceService.Hints hints) { if (providerList == null) return; - for(ProviderInfo trinity:providerList) { - if (hints != PsiReferenceService.Hints.NO_HINTS && !((PsiReferenceProvider)trinity.provider).acceptsHints(position, hints)) { + //noinspection ForLoopReplaceableByForEach + for (int i = 0; i < providerList.size(); i++) { + ProviderInfo info = providerList.get(i); + if (hints != PsiReferenceService.Hints.NO_HINTS && !info.provider.acceptsHints(position, hints)) { continue; } @@ -107,12 +110,12 @@ public abstract class NamedObjectProviderBinding implements ProviderBi } boolean suitable = false; try { - suitable = trinity.processingContext.accepts(position, context); + suitable = info.processingContext.accepts(position, context); } catch (IndexNotReadyException ignored) { } if (suitable) { - ret.add(new ProviderInfo(trinity.provider, context, trinity.priority)); + output.add(new ProviderInfo(info.provider, context, info.priority)); } } } diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/ProviderBinding.java b/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/ProviderBinding.java index aa0446257495..8bc93248f52f 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/ProviderBinding.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/ProviderBinding.java @@ -17,6 +17,7 @@ package com.intellij.psi.impl.source.resolve.reference; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiReferenceProvider; import com.intellij.psi.PsiReferenceService; import com.intellij.util.ProcessingContext; import org.jetbrains.annotations.NotNull; @@ -30,21 +31,21 @@ import java.util.List; * Time: 16:52:28 * To change this template use Options | File Templates. */ -public interface ProviderBinding { - class ProviderInfo { - public final T provider; +public interface ProviderBinding { + class ProviderInfo { + public final PsiReferenceProvider provider; public final Context processingContext; public final double priority; - public ProviderInfo(@NotNull T provider, @NotNull Context processingContext, double priority) { + public ProviderInfo(@NotNull PsiReferenceProvider provider, @NotNull Context processingContext, double priority) { this.provider = provider; this.processingContext = processingContext; this.priority = priority; } } void addAcceptableReferenceProviders(@NotNull PsiElement position, - @NotNull List> list, + @NotNull List> list, @NotNull PsiReferenceService.Hints hints); - void unregisterProvider(@NotNull T provider); + void unregisterProvider(@NotNull PsiReferenceProvider provider); } diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceRegistrarImpl.java b/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceRegistrarImpl.java index 5baae80ead23..f0a70396afb5 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceRegistrarImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/PsiReferenceRegistrarImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -40,18 +40,18 @@ import java.util.Map; */ public class PsiReferenceRegistrarImpl extends PsiReferenceRegistrar { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl"); - private final Map, SimpleProviderBinding> myBindingsMap = ContainerUtil.newTroveMap(); - private final Map, NamedObjectProviderBinding> myNamedBindingsMap = ContainerUtil.newTroveMap(); + private final Map, SimpleProviderBinding> myBindingsMap = ContainerUtil.newTroveMap(); + private final Map, NamedObjectProviderBinding> myNamedBindingsMap = ContainerUtil.newTroveMap(); @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") - private final ConcurrentFactoryMap[]> myBindingCache; + private final ConcurrentFactoryMap myBindingCache; private boolean myInitialized; public PsiReferenceRegistrarImpl(final Language language) { - myBindingCache = new ConcurrentFactoryMap[]>() { + myBindingCache = new ConcurrentFactoryMap() { @Nullable @Override - protected ProviderBinding[] create(Class key) { - List> result = ContainerUtil.newSmartList(); + protected ProviderBinding[] create(Class key) { + List result = ContainerUtil.newSmartList(); for (Class bindingClass : myBindingsMap.keySet()) { if (bindingClass.isAssignableFrom(key)) { result.add(myBindingsMap.get(bindingClass)); @@ -107,9 +107,9 @@ public class PsiReferenceRegistrarImpl extends PsiReferenceRegistrar { break; } - SimpleProviderBinding providerBinding = myBindingsMap.get(scope); + SimpleProviderBinding providerBinding = myBindingsMap.get(scope); if (providerBinding == null) { - myBindingsMap.put(scope, providerBinding = new SimpleProviderBinding()); + myBindingsMap.put(scope, providerBinding = new SimpleProviderBinding()); } providerBinding.registerProvider(provider, pattern, priority); @@ -117,8 +117,7 @@ public class PsiReferenceRegistrarImpl extends PsiReferenceRegistrar { } public void unregisterReferenceProvider(@NotNull Class scope, @NotNull PsiReferenceProvider provider) { - ProviderBinding providerBinding = myBindingsMap.get(scope); - providerBinding.unregisterProvider(provider); + myBindingsMap.get(scope).unregisterProvider(provider); } @@ -129,12 +128,12 @@ public class PsiReferenceRegistrarImpl extends PsiReferenceRegistrar { @NotNull PsiReferenceProvider provider, final double priority, @NotNull ElementPattern pattern) { - NamedObjectProviderBinding providerBinding = myNamedBindingsMap.get(scopeClass); + NamedObjectProviderBinding providerBinding = myNamedBindingsMap.get(scopeClass); if (providerBinding == null) { - myNamedBindingsMap.put(scopeClass, providerBinding = new NamedObjectProviderBinding() { + myNamedBindingsMap.put(scopeClass, providerBinding = new NamedObjectProviderBinding() { @Override - protected String getName(final PsiElement position) { + protected String getName(@NotNull final PsiElement position) { return nameCondition.getPropertyValue(position); } }); @@ -151,14 +150,14 @@ public class PsiReferenceRegistrarImpl extends PsiReferenceRegistrar { } @NotNull - List> getPairsByElement(@NotNull PsiElement element, + List> getPairsByElement(@NotNull PsiElement element, @NotNull PsiReferenceService.Hints hints) { - final ProviderBinding[] bindings = myBindingCache.get(element.getClass()); + final ProviderBinding[] bindings = myBindingCache.get(element.getClass()); if (bindings.length == 0) return Collections.emptyList(); - List> ret = ContainerUtil.newSmartList(); - for (ProviderBinding binding : bindings) { + List> ret = ContainerUtil.newSmartList(); + for (ProviderBinding binding : bindings) { binding.addAcceptableReferenceProviders(element, ret, hints); } return ret; diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistryImpl.java b/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistryImpl.java index 9078c6539f65..feae5aa673a4 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistryImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/ReferenceProvidersRegistryImpl.java @@ -31,11 +31,11 @@ public class ReferenceProvidersRegistryImpl extends ReferenceProvidersRegistry { private static final LanguageExtension CONTRIBUTOR_EXTENSION = new LanguageExtension(PsiReferenceContributor.EP_NAME.getName()); private static final LanguageExtension REFERENCE_PROVIDER_EXTENSION = new LanguageExtension(PsiReferenceProviderBean.EP_NAME.getName()); - private static final Comparator> PRIORITY_COMPARATOR = - new Comparator>() { + private static final Comparator> PRIORITY_COMPARATOR = + new Comparator>() { @Override - public int compare(ProviderBinding.ProviderInfo o1, - ProviderBinding.ProviderInfo o2) { + public int compare(ProviderBinding.ProviderInfo o1, + ProviderBinding.ProviderInfo o2) { return Comparing.compare(o2.priority, o1.priority); } }; @@ -99,7 +99,7 @@ public class ReferenceProvidersRegistryImpl extends ReferenceProvidersRegistry { @Override protected PsiReference[] doGetReferencesFromProviders(@NotNull PsiElement context, @NotNull PsiReferenceService.Hints hints) { - List> providers = getRegistrar(context.getLanguage()).getPairsByElement(context, hints); + List> providers = getRegistrar(context.getLanguage()).getPairsByElement(context, hints); if (providers.isEmpty()) { return PsiReference.EMPTY_ARRAY; @@ -114,7 +114,7 @@ public class ReferenceProvidersRegistryImpl extends ReferenceProvidersRegistry { List result = new ArrayList(); final double maxPriority = providers.get(0).priority; next: - for (ProviderBinding.ProviderInfo trinity : providers) { + for (ProviderBinding.ProviderInfo trinity : providers) { final PsiReference[] refs; try { refs = trinity.provider.getReferencesByElement(context, trinity.processingContext); diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/SimpleProviderBinding.java b/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/SimpleProviderBinding.java index 2394c04dd912..f6b4304dc52e 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/SimpleProviderBinding.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/resolve/reference/SimpleProviderBinding.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -16,7 +16,6 @@ package com.intellij.psi.impl.source.resolve.reference; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.patterns.ElementPattern; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReferenceProvider; @@ -35,41 +34,23 @@ import java.util.List; * Time: 16:52:28 * To change this template use Options | File Templates. */ -public class SimpleProviderBinding implements ProviderBinding { - private final List> myProviderPairs = new SmartList>(); +class SimpleProviderBinding implements ProviderBinding { + private final List> myProviderPairs = new SmartList>(); - public void registerProvider(Provider provider, ElementPattern pattern, double priority) { - myProviderPairs.add(new ProviderInfo(provider, pattern, priority)); + void registerProvider(@NotNull PsiReferenceProvider provider, @NotNull ElementPattern pattern, double priority) { + myProviderPairs.add(new ProviderInfo(provider, pattern, priority)); } @Override public void addAcceptableReferenceProviders(@NotNull PsiElement position, - @NotNull List> list, + @NotNull List> list, @NotNull PsiReferenceService.Hints hints) { - for (ProviderInfo trinity : myProviderPairs) { - if (hints != PsiReferenceService.Hints.NO_HINTS && !((PsiReferenceProvider)trinity.provider).acceptsHints(position, hints)) { - continue; - } - - final ProcessingContext context = new ProcessingContext(); - if (hints != PsiReferenceService.Hints.NO_HINTS) { - context.put(PsiReferenceService.HINTS, hints); - } - boolean suitable = false; - try { - suitable = trinity.processingContext.accepts(position, context); - } - catch (IndexNotReadyException ignored) { - } - if (suitable) { - list.add(new ProviderInfo(trinity.provider, context, trinity.priority)); - } - } + NamedObjectProviderBinding.addMatchingProviders(position, myProviderPairs, list, hints); } @Override - public void unregisterProvider(@NotNull final Provider provider) { - for (final ProviderInfo trinity : new ArrayList>(myProviderPairs)) { + public void unregisterProvider(@NotNull final PsiReferenceProvider provider) { + for (final ProviderInfo trinity : new ArrayList>(myProviderPairs)) { if (trinity.provider.equals(provider)) { myProviderPairs.remove(trinity); } diff --git a/platform/core-impl/src/com/intellij/psi/stubs/ObjectStubTree.java b/platform/core-impl/src/com/intellij/psi/stubs/ObjectStubTree.java index 4c47f6791195..89d30e3f0e32 100644 --- a/platform/core-impl/src/com/intellij/psi/stubs/ObjectStubTree.java +++ b/platform/core-impl/src/com/intellij/psi/stubs/ObjectStubTree.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -78,7 +78,10 @@ public class ObjectStubTree { protected static void enumerateStubs(@NotNull Stub root, @NotNull List result, int idOffset) { ((ObjectStubBase)root).id = idOffset + result.size(); result.add(root); - for (Stub child : root.getChildrenStubs()) { + List childrenStubs = root.getChildrenStubs(); + //noinspection ForLoopReplaceableByForEach + for (int i = 0; i < childrenStubs.size(); i++) { + Stub child = childrenStubs.get(i); enumerateStubs(child, result, idOffset); } } diff --git a/platform/indexing-api/src/com/intellij/psi/search/SingleTargetRequestResultProcessor.java b/platform/indexing-api/src/com/intellij/psi/search/SingleTargetRequestResultProcessor.java index 2cfa12ecf1dd..1ea755a7668e 100644 --- a/platform/indexing-api/src/com/intellij/psi/search/SingleTargetRequestResultProcessor.java +++ b/platform/indexing-api/src/com/intellij/psi/search/SingleTargetRequestResultProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -45,7 +45,9 @@ public final class SingleTargetRequestResultProcessor extends RequestResultProce final List references = ourReferenceService.getReferences(element, new PsiReferenceService.Hints(myTarget, offsetInElement)); - for (PsiReference ref : references) { + //noinspection ForLoopReplaceableByForEach + for (int i = 0; i < references.size(); i++) { + PsiReference ref = references.get(i); ProgressManager.checkCanceled(); if (ReferenceRange.containsOffsetInElement(ref, offsetInElement) && ref.isReferenceTo(myTarget) && !consumer.process(ref)) { return false; diff --git a/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/LibraryRuntimeClasspathScope.java b/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/LibraryRuntimeClasspathScope.java index f75a45ecb7d7..7304dadfe8c1 100644 --- a/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/LibraryRuntimeClasspathScope.java +++ b/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/LibraryRuntimeClasspathScope.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -38,11 +38,11 @@ import java.util.*; */ public class LibraryRuntimeClasspathScope extends GlobalSearchScope { private final ProjectFileIndex myIndex; - private final LinkedHashSet myEntries = new LinkedHashSet(); + private final Set myEntries = new LinkedHashSet(); - private int myCachedHashCode = 0; + private int myCachedHashCode; - public LibraryRuntimeClasspathScope(final Project project, final List modules) { + public LibraryRuntimeClasspathScope(@NotNull Project project, @NotNull Module[] modules) { super(project); myIndex = ProjectRootManager.getInstance(project).getFileIndex(); final Set processedSdk = new THashSet(); @@ -63,7 +63,7 @@ public class LibraryRuntimeClasspathScope extends GlobalSearchScope { } } - public LibraryRuntimeClasspathScope(Project project, LibraryOrderEntry entry) { + public LibraryRuntimeClasspathScope(@NotNull Project project, @NotNull LibraryOrderEntry entry) { super(project); myIndex = ProjectRootManager.getInstance(project).getFileIndex(); Collections.addAll(myEntries, entry.getRootFiles(OrderRootType.CLASSES)); @@ -89,12 +89,13 @@ public class LibraryRuntimeClasspathScope extends GlobalSearchScope { @NotNull final Set processedModules, @NotNull final Set processedLibraries, @NotNull final Set processedSdk, - Condition condition) { + @NotNull Condition condition) { if (!processedModules.add(module)) return; - ModuleRootManager.getInstance(module).orderEntries().recursively().satisfying(condition).process(new RootPolicy>() { - public LinkedHashSet visitLibraryOrderEntry(final LibraryOrderEntry libraryOrderEntry, - final LinkedHashSet value) { + ModuleRootManager.getInstance(module).orderEntries().recursively().satisfying(condition).process(new RootPolicy>() { + @Override + public Set visitLibraryOrderEntry(final LibraryOrderEntry libraryOrderEntry, + final Set value) { final Library library = libraryOrderEntry.getLibrary(); if (library != null && processedLibraries.add(library)) { ContainerUtil.addAll(value, libraryOrderEntry.getRootFiles(OrderRootType.CLASSES)); @@ -102,15 +103,16 @@ public class LibraryRuntimeClasspathScope extends GlobalSearchScope { return value; } - public LinkedHashSet visitModuleSourceOrderEntry(final ModuleSourceOrderEntry moduleSourceOrderEntry, - final LinkedHashSet value) { + @Override + public Set visitModuleSourceOrderEntry(final ModuleSourceOrderEntry moduleSourceOrderEntry, + final Set value) { processedModules.add(moduleSourceOrderEntry.getOwnerModule()); ContainerUtil.addAll(value, moduleSourceOrderEntry.getRootModel().getSourceRoots()); return value; } @Override - public LinkedHashSet visitModuleOrderEntry(ModuleOrderEntry moduleOrderEntry, LinkedHashSet value) { + public Set visitModuleOrderEntry(ModuleOrderEntry moduleOrderEntry, Set value) { final Module depModule = moduleOrderEntry.getModule(); if (depModule != null) { ContainerUtil.addAll(value, ModuleRootManager.getInstance(depModule).getSourceRoots()); @@ -118,7 +120,8 @@ public class LibraryRuntimeClasspathScope extends GlobalSearchScope { return value; } - public LinkedHashSet visitJdkOrderEntry(final JdkOrderEntry jdkOrderEntry, final LinkedHashSet value) { + @Override + public Set visitJdkOrderEntry(final JdkOrderEntry jdkOrderEntry, final Set value) { final Sdk jdk = jdkOrderEntry.getJdk(); if (jdk != null && processedSdk.add(jdk)) { ContainerUtil.addAll(value, jdkOrderEntry.getRootFiles(OrderRootType.CLASSES)); @@ -128,12 +131,13 @@ public class LibraryRuntimeClasspathScope extends GlobalSearchScope { }, myEntries); } + @Override public boolean contains(@NotNull VirtualFile file) { return myEntries.contains(getFileRoot(file)); } @Nullable - private VirtualFile getFileRoot(VirtualFile file) { + private VirtualFile getFileRoot(@NotNull VirtualFile file) { if (myIndex.isLibraryClassFile(file)) { return myIndex.getClassRootForFile(file); } @@ -146,6 +150,7 @@ public class LibraryRuntimeClasspathScope extends GlobalSearchScope { return null; } + @Override public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) { final VirtualFile r1 = getFileRoot(file1); final VirtualFile r2 = getFileRoot(file2); @@ -157,14 +162,17 @@ public class LibraryRuntimeClasspathScope extends GlobalSearchScope { } @TestOnly + @NotNull public List getRoots() { return new ArrayList(myEntries); } + @Override public boolean isSearchInModuleContent(@NotNull Module aModule) { return false; } + @Override public boolean isSearchInLibraries() { return true; } diff --git a/platform/indexing-impl/src/com/intellij/openapi/roots/impl/LibraryScopeCache.java b/platform/indexing-impl/src/com/intellij/openapi/roots/impl/LibraryScopeCache.java index 59a7bf602c1a..609e9f31d406 100644 --- a/platform/indexing-impl/src/com/intellij/openapi/roots/impl/LibraryScopeCache.java +++ b/platform/indexing-impl/src/com/intellij/openapi/roots/impl/LibraryScopeCache.java @@ -31,7 +31,6 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.ConcurrencyUtil; import com.intellij.util.containers.ConcurrentFactoryMap; import com.intellij.util.containers.ContainerUtil; -import gnu.trove.THashSet; import gnu.trove.TObjectHashingStrategy; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -74,7 +73,7 @@ public class LibraryScopeCache { myProject = project; } - public void clear() { + void clear() { myLibraryScopes.clear(); mySdkScopes.clear(); myLibraryResolveScopeCache.clear(); @@ -82,27 +81,19 @@ public class LibraryScopeCache { @NotNull public GlobalSearchScope getLibrariesOnlyScope() { - return getScopeForLibraryUsedIn(Collections.emptyList()); + return getScopeForLibraryUsedIn(Module.EMPTY_ARRAY); } @NotNull - public GlobalSearchScope getScopeForLibraryUsedIn(@NotNull List modulesLibraryIsUsedIn) { - Set set = new THashSet(modulesLibraryIsUsedIn); - Module[] uniques = set.toArray(new Module[set.size()]); - Arrays.sort(uniques, new Comparator() { - @Override - public int compare(Module o1, Module o2) { - return o1.getName().compareTo(o2.getName()); - } - }); - GlobalSearchScope scope = myLibraryScopes.get(uniques); + private GlobalSearchScope getScopeForLibraryUsedIn(@NotNull Module[] modulesLibraryIsUsedIn) { + GlobalSearchScope scope = myLibraryScopes.get(modulesLibraryIsUsedIn); if (scope != null) { return scope; } - GlobalSearchScope newScope = uniques.length == 0 + GlobalSearchScope newScope = modulesLibraryIsUsedIn.length == 0 ? new LibrariesOnlyScope(GlobalSearchScope.allScope(myProject)) : new LibraryRuntimeClasspathScope(myProject, modulesLibraryIsUsedIn); - return ConcurrencyUtil.cacheOrGet(myLibraryScopes, uniques, newScope); + return ConcurrencyUtil.cacheOrGet(myLibraryScopes, modulesLibraryIsUsedIn, newScope); } /** @@ -134,7 +125,17 @@ public class LibraryScopeCache { } } - GlobalSearchScope allCandidates = getScopeForLibraryUsedIn(modulesLibraryUsedIn); + Comparator comparator = new Comparator() { + @Override + public int compare(@NotNull Module o1, @NotNull Module o2) { + return o1.getName().compareTo(o2.getName()); + } + }; + Collections.sort(modulesLibraryUsedIn, comparator); + List uniquesList = ContainerUtil.removeDuplicatesFromSorted(modulesLibraryUsedIn, comparator); + Module[] uniques = uniquesList.toArray(new Module[uniquesList.size()]); + + GlobalSearchScope allCandidates = getScopeForLibraryUsedIn(uniques); if (lib != null) { final LibraryRuntimeClasspathScope preferred = new LibraryRuntimeClasspathScope(myProject, lib); // prefer current library diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java index 43842f9533d1..c3d09122ec6b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java @@ -239,6 +239,9 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers public List runMainPasses(@NotNull PsiFile psiFile, @NotNull Document document, @NotNull final ProgressIndicator progress) { + setUpdateByTimerEnabled(true); // by default we disable daemon while in modal dialog, but here we need to re-enable it because otherwise the paused daemon will conflict with our started passes + restart(); // clear status maps to run passes from scratch so that refCountHolder won't conflict and try to restart itself on partially filled maps + final List result = new ArrayList(); final VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile != null && !virtualFile.getFileType().isBinary()) { @@ -255,10 +258,18 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers } }); - for (TextEditorHighlightingPass pass : passes) { - pass.doCollectInformation(progress); - result.addAll(pass.getInfos()); + LOG.debug("All passes for " + psiFile.getName()+ " started (" + passes+"). progress canceled: "+progress.isCanceled()); + try { + for (TextEditorHighlightingPass pass : passes) { + pass.doCollectInformation(progress); + result.addAll(pass.getInfos()); + } } + catch (ProcessCanceledException e) { + LOG.debug("Canceled: " + progress); + throw e; + } + LOG.debug("All passes for " + psiFile.getName()+ " run. progress canceled: "+progress.isCanceled()+"; infos: "+result); } return result; @@ -548,7 +559,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers } private synchronized void cancelUpdateProgress(final boolean start, @NonNls String reason) { - PassExecutorService.log(myUpdateProgress, null, "CancelX", reason, start); + PassExecutorService.log(myUpdateProgress, null, "Cancel", reason, start); if (myUpdateProgress != null) { myUpdateProgress.cancel(); @@ -873,5 +884,4 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers private List getActiveEditors() { return myEditorTracker.getActiveEditors(); } - } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java index be30aa155c0a..951ad669c237 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java @@ -21,6 +21,7 @@ import com.intellij.codeHighlighting.Pass; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings; import com.intellij.codeInsight.hint.TooltipController; +import com.intellij.ide.AppLifecycleListener; import com.intellij.ide.IdeTooltipManager; import com.intellij.ide.PowerSaveMode; import com.intellij.ide.todo.TodoConfiguration; @@ -158,9 +159,15 @@ public class DaemonListeners implements Disposable { MessageBus messageBus = myProject.getMessageBus(); myDaemonEventPublisher = messageBus.syncPublisher(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC); - final MessageBusConnection connection = messageBus.connect(); - if (project.isDefault()) return; + MessageBusConnection connection = messageBus.connect(); + + connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { + @Override + public void appClosing() { + stopDaemon(false, "App closing"); + } + }); EditorEventMulticaster eventMulticaster = editorFactory.getEventMulticaster(); eventMulticaster.addDocumentListener(new DocumentAdapter() { // clearing highlighters before changing document because change can damage editor highlighters drastically, so we'll clear more than necessary @@ -338,7 +345,7 @@ public class DaemonListeners implements Disposable { public void beforeModalityStateChanged(boolean entering) { // before showing dialog we are in non-modal context yet, and before closing dialog we are still in modal context boolean inModalContext = LaterInvocator.isInModalContext(); - stopDaemon(inModalContext, "Modality change"); + stopDaemon(inModalContext, "Modality change. Was modal: "+inModalContext); myDaemonCodeAnalyzer.setUpdateByTimerEnabled(inModalContext); } }; @@ -503,7 +510,7 @@ public class DaemonListeners implements Disposable { private class MyTodoListener implements PropertyChangeListener { @Override - public void propertyChange(PropertyChangeEvent evt) { + public void propertyChange(@NotNull PropertyChangeEvent evt) { if (TodoConfiguration.PROP_TODO_PATTERNS.equals(evt.getPropertyName())) { stopDaemonAndRestartAllFiles("Todo patterns changed"); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java index 4eff22b618df..ec5cc51dc0c6 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java @@ -46,7 +46,6 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.ConcurrencyUtil; import com.intellij.util.Consumer; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; @@ -60,20 +59,22 @@ import org.jetbrains.annotations.TestOnly; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * @author cdr */ -public class PassExecutorService implements Disposable { +class PassExecutorService implements Disposable { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.PassExecutorService"); private static final boolean CHECK_CONSISTENCY = ApplicationManager.getApplication().isUnitTestMode(); private final Map> mySubmittedPasses = new ConcurrentHashMap>(); private final Project myProject; - protected volatile boolean isDisposed; + private volatile boolean isDisposed; private final AtomicInteger nextPassId = new AtomicInteger(100); - public PassExecutorService(@NotNull Project project) { + PassExecutorService(@NotNull Project project) { myProject = project; } @@ -83,7 +84,7 @@ public class PassExecutorService implements Disposable { isDisposed = true; } - public void cancelAll(boolean waitForTermination) { + void cancelAll(boolean waitForTermination) { for (Job submittedPass : mySubmittedPasses.values()) { submittedPass.cancel(); } @@ -116,10 +117,12 @@ public class PassExecutorService implements Disposable { MultiMap documentToEditors = MultiMap.createSet(); MultiMap documentBoundPasses = MultiMap.createSmart(); MultiMap editorBoundPasses = MultiMap.createSmart(); + Set vFiles = new HashSet(); + for (Map.Entry entry : passesMap.entrySet()) { FileEditor fileEditor = entry.getKey(); HighlightingPass[] passes = entry.getValue(); - Document document = null; + Document document; if (fileEditor instanceof TextEditor) { Editor editor = ((TextEditor)fileEditor).getEditor(); LOG.assertTrue(!(editor instanceof EditorWindow)); @@ -129,6 +132,9 @@ public class PassExecutorService implements Disposable { VirtualFile virtualFile = ((FileEditorManagerEx)FileEditorManager.getInstance(myProject)).getFile(fileEditor); document = virtualFile == null ? null : FileDocumentManager.getInstance().getDocument(virtualFile); } + if (document != null) { + vFiles.add(FileDocumentManager.getInstance().getFile(document)); + } int prevId = 0; for (final HighlightingPass pass : passes) { @@ -185,7 +191,7 @@ public class PassExecutorService implements Disposable { assertConsistency(freePasses, toBeSubmitted, threadsToStartCountdown); } - log(updateProgress, null, "---------------------starting------------------------ " + threadsToStartCountdown.get(), freePasses); + log(updateProgress, null, vFiles + " ----- starting " + threadsToStartCountdown.get(), freePasses); for (ScheduledPass dependentPass : dependentPasses) { mySubmittedPasses.put(dependentPass, Job.NULL_JOB); @@ -227,7 +233,7 @@ public class PassExecutorService implements Disposable { id2Visits.put(succId, Pair.create(succ, newPred)); assert newPred >= 0; if (newPred == 0) { - checkConsistency((succ), id2Visits); + checkConsistency(succ, id2Visits); } } } @@ -534,7 +540,7 @@ public class PassExecutorService implements Disposable { } @NotNull - public List getAllSubmittedPasses() { + List getAllSubmittedPasses() { List result = new ArrayList(mySubmittedPasses.size()); for (ScheduledPass scheduledPass : mySubmittedPasses.keySet()) { if (!scheduledPass.myUpdateProgress.isCanceled()) { @@ -548,24 +554,25 @@ public class PassExecutorService implements Disposable { private static void sortById(@NotNull List result) { ContainerUtil.quickSort(result, new Comparator() { @Override - public int compare(TextEditorHighlightingPass o1, TextEditorHighlightingPass o2) { + public int compare(@NotNull TextEditorHighlightingPass o1, @NotNull TextEditorHighlightingPass o2) { return o1.getId() - o2.getId(); } }); } - private static final ConcurrentMap threads = new ConcurrentHashMap(); private static int getThreadNum() { - return ConcurrencyUtil.cacheOrGet(threads, Thread.currentThread(), threads.size()); + Matcher matcher = Pattern.compile("JobScheduler FJ pool (\\d*)/(\\d*)").matcher(Thread.currentThread().getName()); + String num = matcher.matches() ? matcher.group(1) : null; + return StringUtil.parseInt(num, 0); } - public static void log(ProgressIndicator progressIndicator, TextEditorHighlightingPass pass, @NonNls @NotNull Object... info) { + static void log(ProgressIndicator progressIndicator, TextEditorHighlightingPass pass, @NonNls @NotNull Object... info) { if (LOG.isDebugEnabled()) { CharSequence docText = pass == null ? "" : StringUtil.first(pass.getDocument().getCharsSequence(), 10, true); synchronized (PassExecutorService.class) { StringBuilder s = new StringBuilder(); for (Object o : info) { - s.append(o.toString()).append(" "); + s.append(o).append(" "); } String message = StringUtil.repeatSymbol(' ', getThreadNum() * 4) + " " + pass + " " @@ -584,12 +591,12 @@ public class PassExecutorService implements Disposable { indicator.putUserDataIfAbsent(THROWABLE_KEY, e); } @TestOnly - public static Throwable getSavedException(@NotNull DaemonProgressIndicator indicator) { + static Throwable getSavedException(@NotNull DaemonProgressIndicator indicator) { return indicator.getUserData(THROWABLE_KEY); } // return true if terminated - public boolean waitFor(int millis) throws Throwable { + boolean waitFor(int millis) throws Throwable { ApplicationManager.getApplication().assertIsDispatchThread(); try { for (Job job : mySubmittedPasses.values()) { diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java index 3aa12c8f2e9e..d1fd09ffee1e 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.java @@ -38,7 +38,6 @@ import com.intellij.util.Function; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.HashMap; -import com.intellij.util.containers.WeakHashMap; import gnu.trove.THashMap; import gnu.trove.THashSet; import org.jdom.Element; @@ -65,7 +64,7 @@ public class RunManagerImpl extends RunManagerEx implements PersistentStateCompo private final Map myConfigurations = new LinkedHashMap(); // template configurations are not included here private final Map mySharedConfigurations = new THashMap(); - private final Map> myConfigurationToBeforeTasksMap = new WeakHashMap>(); + private final Map> myConfigurationToBeforeTasksMap = ContainerUtil.createConcurrentWeakMap(); // When readExternal not all configuration may be loaded, so we need to remember the selected configuration // so that when it is eventually loaded, we can mark is as a selected. diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java index 66f5de4179ad..0c8b507bd568 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java @@ -22,6 +22,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.LanguageFileType; +import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.newvfs.FileAttribute; @@ -139,6 +140,17 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi final BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream(); SerializationManagerEx.getInstanceEx().serialize(rootStub, bytes); + if (DebugAssertions.DEBUG) { + try { + Stub deserialized = + SerializationManagerEx.getInstanceEx().deserialize(new ByteArrayInputStream(bytes.getInternalBuffer(), 0, bytes.size())); + check(deserialized, rootStub); + } catch(ProcessCanceledException pce) { + throw pce; + } catch (Throwable t) { + LOG.error("Error indexing:" + file, t); + } + } final int key = Math.abs(FileBasedIndex.getFileId(file)); result.put(key, new SerializedStubTree(bytes.getInternalBuffer(), bytes.size(), rootStub, file.getLength(), contentLength)); } @@ -149,6 +161,16 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi }; } + private static void check(Stub stub, Stub stub2) { + assert stub.getStubType() == stub2.getStubType(); + List stubs = stub.getChildrenStubs(); + List stubs2 = stub2.getChildrenStubs(); + assert stubs.size() == stubs2.size(); + for(int i = 0, len = stubs.size(); i < len; ++i) { + check(stubs.get(i), stubs2.get(i)); + } + } + private static void rememberIndexingStamp(final VirtualFile file, long contentLength) { try { DataOutputStream stream = INDEXED_STAMP.writeAttribute(file); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java index 59cd0b94b504..eeb7a518c5ab 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java @@ -1471,7 +1471,7 @@ public class CaretImpl extends UserDataHolderBase implements Caret { @Override public boolean isAtDirectionBoundary() { - return myEditor.myUseNewRendering && myEditor.myView.isDirectionBoundary(myOffset); + return myEditor.myUseNewRendering && myEditor.myView.isDirectionBoundary(myVisibleCaret); } /** diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorCoordinateMapper.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorCoordinateMapper.java index 210de70daca5..fc340c515ac6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorCoordinateMapper.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorCoordinateMapper.java @@ -172,7 +172,7 @@ class EditorCoordinateMapper { maxVisualColumn = maxColumn; logicalLine = fragment.getEndLogicalLine(); } - return new LogicalPosition(logicalLine, column - maxVisualColumn + maxLogicalColumn, pos.leansRight); + return new LogicalPosition(logicalLine, column - maxVisualColumn + maxLogicalColumn, true); } @NotNull diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorView.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorView.java index de7cdeea888a..5a79feddc3e5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorView.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorView.java @@ -268,9 +268,12 @@ public class EditorView implements Disposable { return layout.isRtlLocation(offset - myDocument.getLineStartOffset(line), leanForward); } - public boolean isDirectionBoundary(int offset) { + public boolean isDirectionBoundary(@NotNull VisualPosition visualPosition) { assertIsDispatchThread(); if (myDocument.getTextLength() == 0) return false; + LogicalPosition logicalPosition = visualToLogicalPosition(visualPosition); + int offset = logicalPositionToOffset(logicalPosition); + if (!visualPosition.equals(offsetToVisualPosition(offset, logicalPosition.leansForward))) return false; int line = myDocument.getLineNumber(offset); LineLayout layout = getLineLayout(line); return layout.isDirectionBoundary(offset - myDocument.getLineStartOffset(line)); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/TabFragment.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/TabFragment.java index 42ae2fca8ac9..1b2f2135572d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/TabFragment.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/TabFragment.java @@ -101,7 +101,7 @@ class TabFragment implements LineFragment { public float visualColumnToX(float startX, int column) { if (column <= 0) return startX; if (column >= getVisualColumnCount(startX)) return getNextTabStop(startX); - return myView.getPlainSpaceWidth() * column; + return startX + myView.getPlainSpaceWidth() * column; } private static int trimOffset(int offset) { diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressDialog.java b/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressDialog.java index 08a78869c87b..54db02350293 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressDialog.java +++ b/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressDialog.java @@ -59,11 +59,9 @@ class ProgressDialog implements Disposable { myTextLabel.setText(text != null && !text.isEmpty() ? text : " "); - if (myProgressBar.isShowing()) { - final int perc = (int)(fraction * 100); - myProgressBar.setIndeterminate(perc == 0 || myProgressWindow.isIndeterminate()); - myProgressBar.setValue(perc); - } + final int perc = (int)(fraction * 100); + myProgressBar.setIndeterminate(perc == 0 || myProgressWindow.isIndeterminate()); + myProgressBar.setValue(perc); myText2Label.setText(getTitle2Text(text2, myText2Label.getWidth())); diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/EncodingManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/EncodingManagerImpl.java index 103f678356a7..7c702ec93313 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/EncodingManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/EncodingManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -63,15 +63,9 @@ import java.lang.ref.Reference; import java.lang.ref.WeakReference; import java.nio.charset.Charset; import java.util.Collection; -import java.util.Set; -@State( - name = "Encoding", - storages = { - @Storage(file = StoragePathMacros.APP_CONFIG + "/encoding.xml") - } -) +@State(name = "Encoding", storages = @Storage(file = StoragePathMacros.APP_CONFIG + "/encoding.xml")) public class EncodingManagerImpl extends EncodingManager implements PersistentStateComponent, Disposable { private static final Equality> REFERENCE_EQUALITY = new Equality>() { @Override @@ -154,7 +148,7 @@ public class EncodingManagerImpl extends EncodingManager implements PersistentSt } @Nullable("returns null if charset set cannot be determined from content") - public Charset computeCharsetFromContent(@NotNull final VirtualFile virtualFile) { + Charset computeCharsetFromContent(@NotNull final VirtualFile virtualFile) { final Document document = FileDocumentManager.getInstance().getDocument(virtualFile); if (document == null) { return null; @@ -183,7 +177,7 @@ public class EncodingManagerImpl extends EncodingManager implements PersistentSt clearDocumentQueue(); } - public void queueUpdateEncodingFromContent(@NotNull Document document) { + void queueUpdateEncodingFromContent(@NotNull Document document) { myChangedDocuments.offerIfAbsent(new WeakReference(document), REFERENCE_EQUALITY); } @@ -206,7 +200,7 @@ public class EncodingManagerImpl extends EncodingManager implements PersistentSt @Override @NotNull public Collection getFavorites() { - Set result = new THashSet(); + Collection result = new THashSet(); Project[] projects = ProjectManager.getInstance().getOpenProjects(); for (Project project : projects) { result.addAll(EncodingProjectManager.getInstance(project).getFavorites()); diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/VfsImplUtil.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/VfsImplUtil.java index 11f95e896a60..834f6282af2f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/VfsImplUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/VfsImplUtil.java @@ -17,7 +17,6 @@ package com.intellij.openapi.vfs.newvfs; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; @@ -191,15 +190,13 @@ public class VfsImplUtil { return getHandler(vfs, localPath, producer); } - //made public for Kotlin @NotNull public static T getHandler(@NotNull ArchiveFileSystem vfs, - @NotNull String localPath, - @NotNull Function producer) { + @NotNull String localPath, + @NotNull Function producer) { checkSubscription(); ArchiveHandler handler; - boolean refresh = false; synchronized (ourLock) { Pair record = ourHandlers.get(localPath); @@ -219,21 +216,10 @@ public class VfsImplUtil { handlers.add(finalRootPath); } }); - refresh = true; } handler = record.second; } - if (refresh) { - final File file = handler.getFile(); - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); - } - }, ModalityState.NON_MODAL); - } - @SuppressWarnings("unchecked") T t = (T)handler; return t; } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InlineProgressIndicator.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InlineProgressIndicator.java index 1a5341f45066..1b7f8fb421d9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InlineProgressIndicator.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/InlineProgressIndicator.java @@ -58,9 +58,6 @@ public class InlineProgressIndicator extends ProgressIndicatorBase implements Di private final TextPanel myProcessName = new TextPanel(); private boolean myDisposed; - private long myLastTimeProgressWasAtZero; - private boolean myLastTimeProgressWasZero; - public InlineProgressIndicator(boolean compact, @NotNull TaskInfo processInfo) { myCompact = compact; myInfo = processInfo; @@ -159,13 +156,7 @@ public class InlineProgressIndicator extends ProgressIndicatorBase implements Di } public void updateProgressNow() { - if (myLastTimeProgressWasAtZero == 0 && getFraction() == 0) { - myLastTimeProgressWasAtZero = System.currentTimeMillis(); - } - - final long delta = System.currentTimeMillis() - myLastTimeProgressWasAtZero; - - boolean indeterminate = isIndeterminate() || getFraction() == 0 && delta > 2000 && !myCompact; + boolean indeterminate = isIndeterminate() || getFraction() == 0; if (indeterminate) { myProgress.setIndeterminate(true); } @@ -187,15 +178,6 @@ public class InlineProgressIndicator extends ProgressIndicatorBase implements Di myCancelButton.setPainting(isCancelable()); - if (getFraction() == 0) { - if (!myLastTimeProgressWasZero) { - myLastTimeProgressWasAtZero = System.currentTimeMillis(); - myLastTimeProgressWasZero = true; - } - } else { - myLastTimeProgressWasZero = false; - } - final boolean isStopping = wasStarted() && (isCanceled() || !isRunning()) && !isFinished(); if (isStopping) { if (myCompact) { diff --git a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties index 30a332f7f583..b1351b8aed78 100644 --- a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties +++ b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties @@ -159,7 +159,7 @@ i18nize.dialog.error.jdk.message=Class 'java.util.ResourceBundle' cannot be foun i18nize.dialog.error.jdk.title=Class Not Found i18nize.dialog.property.file.chooser.title=Choose Properties File i18nize.dialog.template.link.label=Edit I18n template -i18nize.dialog.error.property.already.defined.message=Property ''{0}'' already exists in the file ''{1}'' +i18nize.dialog.error.property.already.defined.message=Property ''{0}'' already exists in the file ''{1}''. Override its value? i18nize.dialog.error.property.already.defined.title=Property Already Exists intention.split.declaration.family=Split Declaration intention.join.declaration.family=Join Declaration and Assignment diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorRtlTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorRtlTest.java index 28878e749fe1..f9d70ae50d43 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorRtlTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorRtlTest.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.editor.impl; +import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.LogicalPosition; import com.intellij.openapi.editor.VisualPosition; import com.intellij.openapi.util.registry.Registry; @@ -69,7 +70,7 @@ public class EditorRtlTest extends AbstractEditorTest { checkVPConversions(vR(3), lB(3), xy(30)); checkVPConversions(vL(4), lF(2), xy(40)); checkVPConversions(vR(4), lF(4), xy(40)); - checkVPConversions(vL(5), lB(5), xy(50)); + checkVPConversions(vL(5), lF(5), xy(50)); checkVPConversions(vR(5), lF(5), xy(50)); checkVPConversions(v(1, 0, false), l(1, 0, false), xy(0, 10)); checkVPConversions(v(1, 0, true), l(1, 0, true), xy(0, 10)); @@ -167,7 +168,7 @@ public class EditorRtlTest extends AbstractEditorTest { checkVPConversions(vR(6), lB(5), xy(60)); checkVPConversions(vL(7), lF(4), xy(70)); checkVPConversions(vR(7), lF(6), xy(70)); - checkVPConversions(vL(8), lB(7), xy(80)); + checkVPConversions(vL(8), lF(7), xy(80)); checkVPConversions(vR(8), lF(7), xy(80)); checkXYConversion(xy(1), vR(0)); @@ -257,6 +258,40 @@ public class EditorRtlTest extends AbstractEditorTest { up(); assertCaretPosition(vR(2)); } + + public void testMovingIntoVirtualSpace() throws Exception { + init("r"); + myEditor.getSettings().setVirtualSpace(true); + assertVisualCaretLocation(0, false); + right(); + assertVisualCaretLocation(0, true); + right(); + assertVisualCaretLocation(1, true); + right(); + assertVisualCaretLocation(1, false); + right(); + assertVisualCaretLocation(2, false); + right(); + assertVisualCaretLocation(3, false); + } + + public void testMovingThroughFoldedRegion() throws Exception { + init("rrr"); + addCollapsedFoldRegion(1, 2, ".."); + assertVisualCaretLocation(0, false); + right(); + assertVisualCaretLocation(0, true); + right(); + assertVisualCaretLocation(1, true); + right(); + assertVisualCaretLocation(1, true); + right(); + assertVisualCaretLocation(2, true); + right(); + assertVisualCaretLocation(3, true); + right(); + assertVisualCaretLocation(4, true); + } private void init(String text) throws IOException { initText(text.replace(RTL_CHAR_REPRESENTATION, RTL_CHAR)); @@ -278,11 +313,11 @@ public class EditorRtlTest extends AbstractEditorTest { Point xyTowardsLargerOffsets) { assertLogicalPositionsEqual("Wrong offset->logicalPosition calculation", logicalPosition, myEditor.offsetToLogicalPosition(offset)); assertVisualPositionsEqual("Wrong beforeOffset->visualPosition calculation", - visualPositionTowardsSmallerOffsets, ((EditorImpl)myEditor).offsetToVisualPosition(offset, false)); + visualPositionTowardsSmallerOffsets, myEditor.offsetToVisualPosition(offset, false)); assertEquals("Wrong beforeOffset->visualLine calculation", visualPositionTowardsSmallerOffsets.line, ((EditorImpl)myEditor).offsetToVisualLine(offset)); assertVisualPositionsEqual("Wrong afterOffset->visualPosition calculation", - visualPositionTowardsLargerOffsets, ((EditorImpl)myEditor).offsetToVisualPosition(offset, true)); + visualPositionTowardsLargerOffsets, myEditor.offsetToVisualPosition(offset, true)); assertEquals("Wrong afterOffset->visualLine calculation", visualPositionTowardsLargerOffsets.line, ((EditorImpl)myEditor).offsetToVisualLine(offset)); assertEquals("Wrong beforeOffset->xy calculation", xyTowardsSmallerOffsets, ((EditorImpl)myEditor).offsetToXY(offset, false)); @@ -326,6 +361,13 @@ public class EditorRtlTest extends AbstractEditorTest { private static void assertCaretPosition(VisualPosition visualPosition) { assertVisualPositionsEqual("Wrong caret position", visualPosition, myEditor.getCaretModel().getVisualPosition()); } + + private static void assertVisualCaretLocation(int visualColumn, boolean reversedDirection) { + assertEquals(1, myEditor.getCaretModel().getCaretCount()); + Caret caret = myEditor.getCaretModel().getPrimaryCaret(); + assertEquals(visualColumn, caret.getVisualPosition().column); + assertEquals(reversedDirection, caret.isAtRtlLocation()); + } // logical position leaning backward private static LogicalPosition lB(int column) { diff --git a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java index fec7abf3a2bc..8f020307e100 100644 --- a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java @@ -51,6 +51,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; import org.intellij.lang.annotations.RegExp; import org.jdom.Element; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -656,6 +657,7 @@ public abstract class UsefulTestCase extends TestCase { } } + @Contract("null, _ -> fail") public static T assertInstanceOf(Object o, Class aClass) { Assert.assertNotNull("Expected instance of: " + aClass.getName() + " actual: " + null, o); Assert.assertTrue("Expected instance of: " + aClass.getName() + " actual: " + o.getClass().getName(), aClass.isInstance(o)); diff --git a/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java b/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java index 58c944e71581..e90699200ab0 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/AbstractTestProxy.java @@ -143,6 +143,7 @@ public abstract class AbstractTestProxy extends CompositePrintable { return null; } + @Deprecated public interface AssertEqualsDiffChain { DiffHyperlink getPrevious(); DiffHyperlink getCurrent(); diff --git a/platform/testRunner/src/com/intellij/execution/testframework/stacktrace/DiffHyperlink.java b/platform/testRunner/src/com/intellij/execution/testframework/stacktrace/DiffHyperlink.java index b05276ae360b..8e9de796ed4a 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/stacktrace/DiffHyperlink.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/stacktrace/DiffHyperlink.java @@ -27,18 +27,11 @@ import com.intellij.execution.testframework.Printable; import com.intellij.execution.testframework.Printer; import com.intellij.execution.testframework.actions.ViewAssertEqualsDiffAction; import com.intellij.execution.ui.ConsoleViewContentType; -import com.intellij.icons.AllIcons; import com.intellij.ide.DataManager; -import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.diff.*; import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import javax.swing.*; import java.io.File; public class DiffHyperlink implements Printable { @@ -66,94 +59,21 @@ public class DiffHyperlink implements Printable { myPrintOneLine = printOneLine; } + /** + * Use {@link ViewAssertEqualsDiffAction#openDiff(DataContext, DiffHyperlink)} + */ + @Deprecated public void openDiff(Project project) { - openMultiDiff(project, null); + ViewAssertEqualsDiffAction.openDiff(DataManager.getInstance().getDataContext(), this); } + /** + * Use {@link ViewAssertEqualsDiffAction#openDiff(DataContext, DiffHyperlink)} + */ + @Deprecated public void openMultiDiff(final Project project, final AbstractTestProxy.AssertEqualsDiffChain chain) { - final SimpleDiffRequest diffData = createRequest(project, chain, myFilePath, myExpected, myActual); - DiffManager.getInstance().getIdeaDiffTool().show(diffData); - } - - private SimpleDiffRequest createRequest(final Project project, - final AbstractTestProxy.AssertEqualsDiffChain chain, - String filePath, String expected, String actual) { - String expectedTitle = ExecutionBundle.message("diff.content.expected.title"); - final DiffContent expectedContent; - final VirtualFile vFile; - if (filePath != null && (vFile = LocalFileSystem.getInstance().findFileByPath(filePath)) != null) { - expectedContent = DiffContent.fromFile(project, vFile); - expectedTitle += " (" + vFile.getPresentableUrl() + ")"; - } else { - expectedContent = new SimpleContent(expected); - } - final SimpleDiffRequest diffData = new SimpleDiffRequest(project, getTitle()); - if (chain != null) { - diffData.setToolbarAddons(new DiffRequest.ToolbarAddons() { - @Override - public void customize(DiffToolbar toolbar) { - toolbar.addAction(new NextPrevAction("Compare Previous Failure", AllIcons.Actions.Prevfile, chain) { - { - registerCustomShortcutSet(ActionManager.getInstance().getAction("PreviousTab").getShortcutSet(), null); - } - - @Override - protected DiffHyperlink getNextId() { - return chain.getPrevious(); - } - }); - toolbar.addAction(new NextPrevAction("Compare Next Failure", AllIcons.Actions.Nextfile, chain) { - { - registerCustomShortcutSet(ActionManager.getInstance().getAction("NextTab").getShortcutSet(), null); - } - - @Override - protected DiffHyperlink getNextId() { - return chain.getNext(); - } - }); - } - }); - } - diffData.setContents(expectedContent, new SimpleContent(actual)); - diffData.setContentTitles(expectedTitle, ExecutionBundle.message("diff.content.actual.title")); - diffData.addHint(DiffTool.HINT_SHOW_FRAME); - diffData.addHint(DiffTool.HINT_DO_NOT_IGNORE_WHITESPACES); - diffData.setGroupKey("#com.intellij.execution.junit2.states.ComparisonFailureState$DiffDialog"); - return diffData; - } - - abstract class NextPrevAction extends AnAction { - - private final AbstractTestProxy.AssertEqualsDiffChain myChain; - - public NextPrevAction(@Nullable String text, @Nullable Icon icon, - final AbstractTestProxy.AssertEqualsDiffChain chain) { - super(text, text, icon); - myChain = chain; - } - - @Override - public void actionPerformed(@NotNull AnActionEvent e) { - final DiffViewer viewer = e.getData(PlatformDataKeys.DIFF_VIEWER); - LOG.assertTrue(viewer != null); - final Project project = e.getData(CommonDataKeys.PROJECT); - final DiffHyperlink nextProvider = getNextId(); - myChain.setCurrent(nextProvider); - final SimpleDiffRequest nextRequest = createRequest(project, myChain, - nextProvider.getFilePath(), nextProvider.getLeft(), nextProvider.getRight()); - viewer.setDiffRequest(nextRequest); - } - - @Override - public void update(@NotNull AnActionEvent e) { - final DiffViewer viewer = e.getData(PlatformDataKeys.DIFF_VIEWER); - final Project project = e.getData(CommonDataKeys.PROJECT); - e.getPresentation().setEnabled(project != null && viewer != null); - } - - protected abstract DiffHyperlink getNextId(); + ViewAssertEqualsDiffAction.openDiff(DataManager.getInstance().getDataContext(), this); } protected String getTitle() { diff --git a/platform/util/src/com/intellij/util/containers/ContainerUtil.java b/platform/util/src/com/intellij/util/containers/ContainerUtil.java index 52ece82f3685..0dfe4f7788d8 100644 --- a/platform/util/src/com/intellij/util/containers/ContainerUtil.java +++ b/platform/util/src/com/intellij/util/containers/ContainerUtil.java @@ -1101,10 +1101,11 @@ public class ContainerUtil extends ContainerUtilRt { public static Iterable iterate(@NotNull final Collection collection, @NotNull final Condition condition) { if (collection.isEmpty()) return emptyIterable(); return new Iterable() { + @NotNull @Override public Iterator iterator() { return new Iterator() { - private Iterator impl = collection.iterator(); + private final Iterator impl = collection.iterator(); private T next = findNext(); @Override @@ -1143,10 +1144,11 @@ public class ContainerUtil extends ContainerUtilRt { @Contract(pure=true) public static Iterable iterateBackward(@NotNull final List list) { return new Iterable() { + @NotNull @Override public Iterator iterator() { return new Iterator() { - private ListIterator it = list.listIterator(list.size()); + private final ListIterator it = list.listIterator(list.size()); @Override public boolean hasNext() { @@ -1269,7 +1271,7 @@ public class ContainerUtil extends ContainerUtilRt { } /** - * @deprecated Use {@link #append(java.util.List, java.lang.Object[])} or {@link #prepend(java.util.List, java.lang.Object[])} instead + * @deprecated Use {@link #append(List, Object[])} or {@link #prepend(List, Object[])} instead * @param appendTail specify whether additional values should be appended in front or after the list * @return read-only list consisting of the elements from specified list with some additional values */ @@ -1338,6 +1340,7 @@ public class ContainerUtil extends ContainerUtilRt { @Contract(pure=true) public static Iterable concat(@NotNull final Iterable... iterables) { return new Iterable() { + @NotNull @Override public Iterator iterator() { Iterator[] iterators = new Iterator[iterables.length]; @@ -1367,12 +1370,13 @@ public class ContainerUtil extends ContainerUtilRt { @Contract(pure=true) public static Iterable concat(@NotNull final T[]... iterables) { return new Iterable() { + @NotNull @Override public Iterator iterator() { Iterator[] iterators = new Iterator[iterables.length]; - for (int i = 0, iterablesLength = iterables.length; i < iterablesLength; i++) { + for (int i = 0; i < iterables.length; i++) { T[] iterable = iterables[i]; - iterators[i] = Arrays.asList(iterable).iterator(); + iterators[i] = iterate(iterable); } @SuppressWarnings("unchecked") Iterator i = concatIterators(iterators); return i; @@ -2134,6 +2138,37 @@ public class ContainerUtil extends ContainerUtilRt { return flatten(Arrays.asList(collections)); } + /** + * Processes the list, remove all duplicates and return the list with unique elements. + * @param list must be sorted (according to the comparator), all elements must be not-null + */ + @NotNull + public static List removeDuplicatesFromSorted(@NotNull List list, @NotNull Comparator comparator) { + T prev = null; + List result = null; + for (int i = 0; i < list.size(); i++) { + T t = list.get(i); + if (t == null) { + throw new IllegalArgumentException("get(" + i + ") = null"); + } + int cmp = prev == null ? -1 : comparator.compare(prev, t); + if (cmp < 0) { + if (result != null) result.add(t); + } + else if (cmp == 0) { + if (result == null) { + result = new ArrayList(list.size()); + result.addAll(list.subList(0, i)); + } + } + else { + throw new IllegalArgumentException("List must be sorted but get(" + (i - 1) + ")=" + list.get(i - 1) + " > get(" + i + ")=" + t); + } + prev = t; + } + return result == null ? list : result; + } + /** * @return read-only list consisting of the elements from all of the collections */ diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/CodeSmellDetector.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/CodeSmellDetector.java index d9c08370263e..163e8271b1cf 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/CodeSmellDetector.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/CodeSmellDetector.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -16,10 +16,11 @@ package com.intellij.openapi.vcs; import com.intellij.codeInsight.CodeSmellInfo; -import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; -import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -36,10 +37,11 @@ public abstract class CodeSmellDetector { * * @param files the files to analyze. * @return the list of problems found during the analysis. - * @throws com.intellij.openapi.progress.ProcessCanceledException if the analysis was cancelled by the user. + * @throws ProcessCanceledException if the analysis was cancelled by the user. * @since 5.1 */ - public abstract List findCodeSmells(List files) throws ProcessCanceledException; + @NotNull + public abstract List findCodeSmells(@NotNull List files) throws ProcessCanceledException; /** * Shows the specified list of problems found during pre-checkin code analysis in a Messages pane. @@ -47,6 +49,6 @@ public abstract class CodeSmellDetector { * @param smells the problems to show. * @since 5.1 */ - public abstract void showCodeSmellErrors(final List smells); + public abstract void showCodeSmellErrors(@NotNull List smells); } \ No newline at end of file diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/CodeSmellDetectorImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/CodeSmellDetectorImpl.java index bc8a731a9750..6cb076692379 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/CodeSmellDetectorImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/CodeSmellDetectorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -60,7 +60,7 @@ public class CodeSmellDetectorImpl extends CodeSmellDetector { } @Override - public void showCodeSmellErrors(final List smellList) { + public void showCodeSmellErrors(@NotNull final List smellList) { Collections.sort(smellList, new Comparator() { @Override public int compare(final CodeSmellInfo o1, final CodeSmellInfo o2) { @@ -104,9 +104,10 @@ public class CodeSmellDetectorImpl extends CodeSmellDetector { } - + @NotNull @Override - public List findCodeSmells(final List filesToCheck) throws ProcessCanceledException { + public List findCodeSmells(@NotNull final List filesToCheck) throws ProcessCanceledException { + ApplicationManager.getApplication().assertIsDispatchThread(); final List result = new ArrayList(); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); if (ApplicationManager.getApplication().isWriteAccessAllowed()) throw new RuntimeException("Must not run under write action"); @@ -137,7 +138,8 @@ public class CodeSmellDetectorImpl extends CodeSmellDetector { } }); if (!exception.isNull()) { - Rethrow.reThrowRuntime(exception.get()); + Exception t = exception.get(); + Rethrow.reThrowRuntime(t); } return result; @@ -145,11 +147,11 @@ public class CodeSmellDetectorImpl extends CodeSmellDetector { @NotNull private List findCodeSmells(@NotNull final VirtualFile file, @NotNull final ProgressIndicator progress) { - final List result = new ArrayList(); + final List result = Collections.synchronizedList(new ArrayList()); final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(myProject); - final DaemonProgressIndicator daemonIndicator = new DaemonProgressIndicator(); - ((ProgressIndicatorEx)progress).addStateDelegate(new AbstractProgressIndicatorExBase(){ + final ProgressIndicator daemonIndicator = new DaemonProgressIndicator(); + ((ProgressIndicatorEx)progress).addStateDelegate(new AbstractProgressIndicatorExBase() { @Override public void cancel() { super.cancel(); @@ -163,13 +165,12 @@ public class CodeSmellDetectorImpl extends CodeSmellDetector { @Override public void run() { final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file); - if (psiFile != null) { - final Document document = FileDocumentManager.getInstance().getDocument(file); - if (document != null) { - List infos = codeAnalyzer.runMainPasses(psiFile, document, daemonIndicator); - collectErrorsAndWarnings(infos, result, document); - } + final Document document = FileDocumentManager.getInstance().getDocument(file); + if (psiFile == null || document == null) { + return; } + List infos = codeAnalyzer.runMainPasses(psiFile, document, daemonIndicator); + convertErrorsAndWarnings(infos, result, document); } }); } @@ -178,10 +179,9 @@ public class CodeSmellDetectorImpl extends CodeSmellDetector { return result; } - private void collectErrorsAndWarnings(final Collection highlights, - final List result, - final Document document) { - if (highlights == null) return; + private void convertErrorsAndWarnings(@NotNull Collection highlights, + @NotNull List result, + @NotNull Document document) { for (HighlightInfo highlightInfo : highlights) { final HighlightSeverity severity = highlightInfo.getSeverity(); if (SeverityRegistrar.getSeverityRegistrar(myProject).compare(severity, HighlightSeverity.WARNING) >= 0) { @@ -191,7 +191,7 @@ public class CodeSmellDetectorImpl extends CodeSmellDetector { } } - private static String getDescription(final HighlightInfo highlightInfo) { + private static String getDescription(@NotNull HighlightInfo highlightInfo) { final String description = highlightInfo.getDescription(); final HighlightInfoType type = highlightInfo.type; if (type instanceof HighlightInfoType.HighlightInfoTypeSeverityByKey) { diff --git a/plugins/java-i18n/src/com/intellij/lang/properties/psi/ResourceBundleManager.java b/plugins/java-i18n/src/com/intellij/lang/properties/psi/ResourceBundleManager.java index a68cd3f31f99..f3243b410a97 100644 --- a/plugins/java-i18n/src/com/intellij/lang/properties/psi/ResourceBundleManager.java +++ b/plugins/java-i18n/src/com/intellij/lang/properties/psi/ResourceBundleManager.java @@ -42,7 +42,7 @@ public abstract class ResourceBundleManager { public abstract PsiClass getResourceBundle(); public List suggestPropertiesFiles(){ - return I18nUtil.defaultGetPropertyFiles(myProject); + return I18nUtil.defaultSuggestPropertiesFiles(myProject); } @Nullable diff --git a/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFXCollapseSubtagToAttributeTest.java b/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFXCollapseSubtagToAttributeTest.java index b1d0a39d5581..82d6587ffce9 100644 --- a/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFXCollapseSubtagToAttributeTest.java +++ b/plugins/javaFX/javaFX-CE/testSrc/org/jetbrains/plugins/javaFX/fxml/JavaFXCollapseSubtagToAttributeTest.java @@ -30,6 +30,12 @@ import org.junit.Assume; import java.util.List; public class JavaFXCollapseSubtagToAttributeTest extends DaemonAnalyzerTestCase { + @Override + protected void setUp() throws Exception { + super.setUp(); + Assume.assumeFalse(SystemInfo.isMac); + } + @Override protected void setUpModule() { super.setUpModule(); @@ -37,7 +43,6 @@ public class JavaFXCollapseSubtagToAttributeTest extends DaemonAnalyzerTestCase } public void testAdditionalSubtags() throws Exception { - Assume.assumeFalse(SystemInfo.isMac); doTest(false); } diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/MavenClasspathsAndSearchScopesTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/MavenClasspathsAndSearchScopesTest.java index 974afc85a436..b7a65592cb83 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/MavenClasspathsAndSearchScopesTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/MavenClasspathsAndSearchScopesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -30,10 +30,13 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.psi.search.DelegatingGlobalSearchScope; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.testFramework.PsiTestUtil; import com.intellij.util.ArrayUtil; +import com.intellij.util.CommonProcessors; import com.intellij.util.PathsList; +import com.intellij.util.ReflectionUtil; import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.maven.MavenImportingTestCase; import org.jetbrains.idea.maven.importing.ArtifactsDownloadingTestCase; @@ -780,15 +783,27 @@ public class MavenClasspathsAndSearchScopesTest extends MavenImportingTestCase { importProjects(m1, m2); assertModules("m1", "m2"); - List modules = Arrays.asList(getModule("m1"), getModule("m2")); - GlobalSearchScope scope = LibraryScopeCache.getInstance(myProject).getScopeForLibraryUsedIn(modules); - String libraryPath = getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar"; - assertSearchScope(scope, + Module m1m = ModuleManager.getInstance(myProject).findModuleByName("m1"); + List modules1 = new ArrayList(); + ModuleRootManager.getInstance(m1m).orderEntries().withoutSdk().withoutModuleSourceEntries().forEach(new CommonProcessors.CollectProcessor(modules1)); + GlobalSearchScope scope1 = LibraryScopeCache.getInstance(myProject).getLibraryScope(modules1); + assertSearchScope(scope1, getProjectPath() + "/m1/src/main/java", getProjectPath() + "/m1/src/test/java", + getProjectPath() + "/m2/src/main/java", + getProjectPath() + "/m2/src/test/java" + ); + + String libraryPath = getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar"; + Module m2m = ModuleManager.getInstance(myProject).findModuleByName("m2"); + List modules2 = new ArrayList(); + ModuleRootManager.getInstance(m2m).orderEntries().withoutSdk().withoutModuleSourceEntries().forEach(new CommonProcessors.CollectProcessor(modules2)); + GlobalSearchScope scope2 = LibraryScopeCache.getInstance(myProject).getLibraryScope(modules2); + assertSearchScope(scope2, getProjectPath() + "/m2/src/main/java", getProjectPath() + "/m2/src/test/java", - libraryPath); + libraryPath + ); } public void testDoNotIncludeConflictingTransitiveDependenciesInTheClasspath() throws Exception { @@ -1132,6 +1147,9 @@ public class MavenClasspathsAndSearchScopesTest extends MavenImportingTestCase { private void assertSearchScope(GlobalSearchScope searchScope, String... expectedPaths) { Collection roots; + if (searchScope instanceof DelegatingGlobalSearchScope) { + searchScope = ReflectionUtil.getField(DelegatingGlobalSearchScope.class, searchScope, GlobalSearchScope.class, "myBaseScope"); + } if (searchScope instanceof ModuleWithDependenciesScope) { roots = ((ModuleWithDependenciesScope)searchScope).getRoots(); } diff --git a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/references/I18nUtil.java b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/references/I18nUtil.java index 10b809997b51..c0fe61293b38 100644 --- a/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/references/I18nUtil.java +++ b/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/references/I18nUtil.java @@ -20,6 +20,7 @@ import com.intellij.lang.properties.IProperty; import com.intellij.lang.properties.PropertiesFileProcessor; import com.intellij.lang.properties.PropertiesReferenceManager; import com.intellij.lang.properties.psi.PropertiesFile; +import com.intellij.lang.properties.xml.XmlPropertiesFile; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectFileIndex; @@ -74,7 +75,7 @@ public class I18nUtil { } } - public static List defaultGetPropertyFiles(Project project) { + public static List defaultSuggestPropertiesFiles(Project project) { final List paths = new ArrayList(); final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); @@ -82,6 +83,9 @@ public class I18nUtil { @Override public boolean process(String baseName, PropertiesFile propertiesFile) { + if (propertiesFile instanceof XmlPropertiesFile) { + return true; + } VirtualFile virtualFile = propertiesFile.getVirtualFile(); if (projectFileIndex.isInContent(virtualFile)) { String path = FileUtil.toSystemDependentName(virtualFile.getPath()); diff --git a/plugins/properties/src/com/intellij/lang/properties/references/I18nizeQuickFixDialog.java b/plugins/properties/src/com/intellij/lang/properties/references/I18nizeQuickFixDialog.java index f044a6db681c..d4a5499e5111 100644 --- a/plugins/properties/src/com/intellij/lang/properties/references/I18nizeQuickFixDialog.java +++ b/plugins/properties/src/com/intellij/lang/properties/references/I18nizeQuickFixDialog.java @@ -64,7 +64,7 @@ import java.util.regex.Pattern; public class I18nizeQuickFixDialog extends DialogWrapper implements I18nizeQuickFixModel { protected static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.i18n.I18nizeQuickFixDialog"); - + private static final Pattern PATTERN = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); private JTextField myValue; @@ -269,7 +269,7 @@ public class I18nizeQuickFixDialog extends DialogWrapper implements I18nizeQuick } protected String defaultSuggestPropertyKey(String value) { - return null; + return null; } private void propertiesFileChanged() { @@ -359,7 +359,7 @@ public class I18nizeQuickFixDialog extends DialogWrapper implements I18nizeQuick } protected List defaultSuggestPropertiesFiles() { - return I18nUtil.defaultGetPropertyFiles(myProject); + return I18nUtil.defaultSuggestPropertiesFiles(myProject); } protected PropertiesFile getPropertiesFile() { @@ -438,10 +438,14 @@ public class I18nizeQuickFixDialog extends DialogWrapper implements I18nizeQuick IProperty existingProperty = propertiesFile.findPropertyByKey(getKey()); final String propValue = myValue.getText(); if (existingProperty != null && !Comparing.strEqual(existingProperty.getValue(), propValue)) { - Messages.showErrorDialog(myProject, CodeInsightBundle.message("i18nize.dialog.error.property.already.defined.message", getKey(), - propertiesFile.getName()), - CodeInsightBundle.message("i18nize.dialog.error.property.already.defined.title")); - return; + final String messageText = CodeInsightBundle.message("i18nize.dialog.error.property.already.defined.message", getKey(), propertiesFile.getName()); + final int code = Messages.showOkCancelDialog(myProject, + messageText, + CodeInsightBundle.message("i18nize.dialog.error.property.already.defined.title"), + null); + if (code == Messages.CANCEL) { + return; + } } } diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/actions/CreateListenerAction.java b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/CreateListenerAction.java index e5bff196ae72..6e112efeaea3 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/actions/CreateListenerAction.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/CreateListenerAction.java @@ -21,7 +21,10 @@ import com.intellij.codeInsight.FileModificationService; import com.intellij.codeInsight.generation.OverrideImplementExploreUtil; import com.intellij.codeInsight.generation.OverrideImplementUtil; import com.intellij.ide.DataManager; -import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.diagnostic.Logger; @@ -40,7 +43,6 @@ import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.util.PsiUtil; import com.intellij.psi.util.PsiUtilCore; import com.intellij.uiDesigner.FormEditingUtil; import com.intellij.uiDesigner.UIDesignerBundle; @@ -211,7 +213,7 @@ public class CreateListenerAction extends AbstractGuiEditorAction { PsiStatement stmt = factory.createStatementFromText(builder.toString(), constructor); stmt = (PsiStatement)body.addAfter(stmt, body.getLastBodyElement()); - JavaCodeStyleManager.getInstance(body.getProject()).shortenClassReferences(stmt); + stmt = (PsiStatement)JavaCodeStyleManager.getInstance(body.getProject()).shortenClassReferences(stmt); if (boundFields.length > 1) { PsiElement anchor = stmt; @@ -224,23 +226,32 @@ public class CreateListenerAction extends AbstractGuiEditorAction { } } - final Ref newClassRef = new Ref(); - stmt.accept(new JavaRecursiveElementWalkingVisitor() { - @Override - public void visitClass(PsiClass aClass) { - newClassRef.set(aClass); - } - }); - final PsiClass newClass = newClassRef.get(); - final SmartPsiElementPointer ptr = SmartPointerManager.getInstance(myClass.getProject()).createSmartPsiElementPointer(newClass); - final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(newClass); + final SmartPsiElementPointer ptr = SmartPointerManager.getInstance(myClass.getProject()).createSmartPsiElementPointer(stmt); + final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(myClass); final FileEditor[] fileEditors = - virtualFile != null ? FileEditorManager.getInstance(newClass.getProject()).openFile(virtualFile, true, true) : null; + virtualFile != null ? FileEditorManager.getInstance(myClass.getProject()).openFile(virtualFile, true, true) : null; IdeFocusManager.findInstance().doWhenFocusSettlesDown(new Runnable() { public void run() { - final PsiClass newClass = (PsiClass)ptr.getElement(); + final PsiElement anonymousClassStatement = ptr.getElement(); + if (anonymousClassStatement == null) { + return; + } + + final Ref newClassRef = new Ref(); + anonymousClassStatement.accept(new JavaRecursiveElementWalkingVisitor() { + @Override + public void visitClass(PsiClass aClass) { + newClassRef.set(aClass); + } + }); + final PsiClass newClass = newClassRef.get(); + final Editor editor = getEditor(); if (editor != null && newClass != null) { + PsiElement brace = newClass.getLBrace(); + if (brace != null) { + editor.getCaretModel().moveToOffset(brace.getTextOffset()); + } CommandProcessor.getInstance().executeCommand(myClass.getProject(), new Runnable() { public void run() { if (!OverrideImplementExploreUtil.getMethodSignaturesToImplement(newClass).isEmpty()) { diff --git a/python/helpers/pycharm/_bdd_utils.py b/python/helpers/pycharm/_bdd_utils.py index 2bfa1be526ef..508fdaacb35f 100644 --- a/python/helpers/pycharm/_bdd_utils.py +++ b/python/helpers/pycharm/_bdd_utils.py @@ -9,7 +9,7 @@ import os import time import abc import tcmessages -from utils import VersionAgnosticUtils +from _jb_utils import VersionAgnosticUtils __author__ = 'Ilya.Kazakevich' diff --git a/python/helpers/pycharm/manage_tasks_provider.py b/python/helpers/pycharm/_jb_manage_tasks_provider.py similarity index 100% rename from python/helpers/pycharm/manage_tasks_provider.py rename to python/helpers/pycharm/_jb_manage_tasks_provider.py diff --git a/python/helpers/pycharm/utils.py b/python/helpers/pycharm/_jb_utils.py similarity index 100% rename from python/helpers/pycharm/utils.py rename to python/helpers/pycharm/_jb_utils.py diff --git a/python/helpers/pycharm/behave_runner.py b/python/helpers/pycharm/behave_runner.py index ea656d8ab8f6..1bafcf7cc7ce 100644 --- a/python/helpers/pycharm/behave_runner.py +++ b/python/helpers/pycharm/behave_runner.py @@ -21,7 +21,7 @@ import re import _bdd_utils from distutils import version from behave import __version__ as behave_version -from utils import VersionAgnosticUtils +from _jb_utils import VersionAgnosticUtils _MAX_STEPS_SEARCH_FEATURES = 5000 # Do not look for features in folder that has more that this number of children _FEATURES_FOLDER = 'features' # "features" folder name. diff --git a/python/helpers/pycharm/django_manage_commands_provider/_parser/parser.py b/python/helpers/pycharm/django_manage_commands_provider/_parser/parser.py index 4eb26f82fc78..ec95aafdfa8e 100644 --- a/python/helpers/pycharm/django_manage_commands_provider/_parser/parser.py +++ b/python/helpers/pycharm/django_manage_commands_provider/_parser/parser.py @@ -7,7 +7,7 @@ from django.core.exceptions import ImproperlyConfigured from django.core.management import ManagementUtility, get_commands, BaseCommand from django_manage_commands_provider._parser import _optparse, _argparse -from utils import VersionAgnosticUtils +from _jb_utils import VersionAgnosticUtils __author__ = 'Ilya.Kazakevich' diff --git a/python/helpers/pycharm/django_manage_commands_provider/_xml.py b/python/helpers/pycharm/django_manage_commands_provider/_xml.py index 1baba3094d36..4b22d9cf1b40 100644 --- a/python/helpers/pycharm/django_manage_commands_provider/_xml.py +++ b/python/helpers/pycharm/django_manage_commands_provider/_xml.py @@ -24,7 +24,7 @@ TODO: Since Django 1.8 we can fetch much more info from argparse like positional """ from xml.dom import minidom from xml.dom.minidom import Element -from utils import VersionAgnosticUtils +from _jb_utils import VersionAgnosticUtils __author__ = 'Ilya.Kazakevich' diff --git a/python/helpers/pycharm/django_manage_commands_provider/readme.txt b/python/helpers/pycharm/django_manage_commands_provider/readme.txt index 0cf93cf0ee81..8ad9af3c11ab 100644 --- a/python/helpers/pycharm/django_manage_commands_provider/readme.txt +++ b/python/helpers/pycharm/django_manage_commands_provider/readme.txt @@ -1,4 +1,4 @@ This helper fetchers manage commands from Django installation. It supports custom commands as well. -Entry point is "provider.py": it exports data in XML format that is described in "_xml.py". +Entry point is "_jb_manage_tasks_provider.py: one level up, it exports data in XML format that is described in "_xml.py". This helper should be used in pair with com.jetbrains.django.manage.RealCommandsProvider \ No newline at end of file