diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/PlaceInDocument.java b/java/debugger/impl/src/com/intellij/debugger/actions/PlaceInDocument.java index 808f226cb68e..611e3933b88d 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/PlaceInDocument.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/PlaceInDocument.java @@ -22,7 +22,20 @@ import com.intellij.openapi.editor.Document; * Date: Oct 7, 2003 * Time: 3:12:54 PM */ -interface PlaceInDocument { - public Document getDocument(); - public int getOffset(); +class PlaceInDocument { + private final Document myDocument; + private final int myOffset; + + PlaceInDocument(Document document, int offset) { + myDocument = document; + myOffset = offset; + } + + public Document getDocument() { + return myDocument; + } + + public int getOffset() { + return myOffset; + } } diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/ToggleLineBreakpointActionHandler.java b/java/debugger/impl/src/com/intellij/debugger/actions/ToggleLineBreakpointActionHandler.java index 4e33a342c0c2..650e7c37cf70 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/ToggleLineBreakpointActionHandler.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/ToggleLineBreakpointActionHandler.java @@ -26,13 +26,14 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.FoldRegion; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiDocumentManager; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; +import com.intellij.psi.*; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.xdebugger.impl.actions.DebuggerActionHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -71,10 +72,14 @@ public class ToggleLineBreakpointActionHandler extends DebuggerActionHandler { return; } - ExpandRegionAction.expandRegionAtCaret(project, event.getData(CommonDataKeys.EDITOR)); + Editor editor = event.getData(CommonDataKeys.EDITOR); + ExpandRegionAction.expandRegionAtCaret(project, editor); Document document = place.getDocument(); int line = document.getLineNumber(place.getOffset()); + if (editor != null && editor.getCaretModel().getVisualPosition().line != line) { + editor.getCaretModel().moveToOffset(place.getOffset()); + } DebuggerManagerEx debugManager = DebuggerManagerEx.getInstanceEx(project); if (debugManager == null) { @@ -100,28 +105,59 @@ public class ToggleLineBreakpointActionHandler extends DebuggerActionHandler { } } + private static boolean containsOnlyDeclarations(int line, Document document, PsiFile file) { + int lineStart = document.getLineStartOffset(line); + int lineEnd = document.getLineEndOffset(line); + PsiElement start = file.findElementAt(lineStart); + PsiElement end = file.findElementAt(lineEnd - 1); + if (start == null || end == null) return false; + + PsiElement commonParent = PsiTreeUtil.findCommonParent(start, end); + for (PsiElement element : PsiTreeUtil.findChildrenOfAnyType(commonParent, PsiStatement.class, PsiExpression.class)) { + if (new TextRange(lineStart, lineEnd).contains(element.getTextRange().getStartOffset())) { + return false; + } + } + return true; + } + @Nullable private static PlaceInDocument getPlace(@NotNull final Project project, AnActionEvent event) { Editor editor = event.getData(CommonDataKeys.EDITOR); if(editor == null) { editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); } - if (editor != null) { - final Document document = editor.getDocument(); - PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document); - if (file != null) { - final Editor editor1 = editor; - return new PlaceInDocument() { - public Document getDocument() { - return document; - } - - public int getOffset() { - return editor1.getCaretModel().getOffset(); - } - }; - } + if (editor == null) { + return null; } - return null; + + final Document document = editor.getDocument(); + PsiDocumentManager.getInstance(project).commitDocument(document); + PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document); + if (file == null) { + return null; + } + + // if several lines are merged into one visual line (using folding), try to find the most appropriate of those lines + int visualLine = editor.getCaretModel().getVisualPosition().getLine(); + int visibleOffset = editor.getCaretModel().getOffset(); + while (editor.offsetToVisualPosition(visibleOffset).line == visualLine) { + int line = document.getLineNumber(visibleOffset); + if (!containsOnlyDeclarations(line, document, file)) { + return new PlaceInDocument(document, visibleOffset); + } + int lineEndOffset = document.getLineEndOffset(line); + FoldRegion region = editor.getFoldingModel().getCollapsedRegionAtOffset(lineEndOffset); + if (region != null) { + int foldEnd = region.getEndOffset(); + if (foldEnd > lineEndOffset) { + visibleOffset = foldEnd; + continue; + } + } + visibleOffset = lineEndOffset + 1; + } + + return new PlaceInDocument(document, editor.getCaretModel().getOffset()); } } \ No newline at end of file diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/ToggleMethodBreakpointAction.java b/java/debugger/impl/src/com/intellij/debugger/actions/ToggleMethodBreakpointAction.java index 25ee5bfaa06a..79cb5c8b3022 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/ToggleMethodBreakpointAction.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/ToggleMethodBreakpointAction.java @@ -122,21 +122,7 @@ public class ToggleMethodBreakpointAction extends AnAction { } } - if(method != null) { - final PsiElement method1 = method; - final Document document1 = document; - - return new PlaceInDocument() { - public Document getDocument() { - return document1; - } - - public int getOffset() { - return method1.getTextOffset(); - } - }; - } - return null; + return method != null ? new PlaceInDocument(document, method.getTextOffset()) : null; } @Nullable diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index 1923092097db..1bcbf3e9954b 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -196,7 +196,7 @@ public class BreakpointManager { offset = editor.getDocument().getLineStartOffset(line); } - ExpandRegionAction.expandRegionAtCaret(myProject, editor); + ExpandRegionAction.expandRegionAtOffset(myProject, editor, offset); Breakpoint breakpoint = findBreakpoint(document, offset, null); if (breakpoint == null) { diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/JavaHighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/JavaHighlightUtil.java index 864798fa1694..722ec3584d7f 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/JavaHighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/JavaHighlightUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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,6 +15,7 @@ */ package com.intellij.codeInsight.daemon.impl.analysis; +import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.util.*; import org.jetbrains.annotations.NonNls; @@ -26,8 +27,8 @@ import java.util.List; public class JavaHighlightUtil { public static boolean isSerializable(@NotNull PsiClass aClass) { - PsiManager manager = aClass.getManager(); - PsiClass serializableClass = JavaPsiFacade.getInstance(manager.getProject()).findClass("java.io.Serializable", aClass.getResolveScope()); + Project project = aClass.getManager().getProject(); + PsiClass serializableClass = JavaPsiFacade.getInstance(project).findClass("java.io.Serializable", aClass.getResolveScope()); return serializableClass != null && aClass.isInheritor(serializableClass, true); } @@ -70,18 +71,13 @@ public class JavaHighlightUtil { @NotNull public static String formatType(@Nullable PsiType type) { - if (type == null) return PsiKeyword.NULL; - String text = type.getInternalCanonicalText(); - return text == null ? PsiKeyword.NULL : text; + return type == null ? PsiKeyword.NULL : type.getInternalCanonicalText(); } @Nullable - private static PsiType getArrayInitializerType(@NotNull final PsiArrayInitializerExpression element) { - final PsiType typeCheckResult = sameType(element.getInitializers()); - if (typeCheckResult != null) { - return typeCheckResult.createArrayType(); - } - return null; + private static PsiType getArrayInitializerType(@NotNull PsiArrayInitializerExpression element) { + PsiType typeCheckResult = sameType(element.getInitializers()); + return typeCheckResult != null ? typeCheckResult.createArrayType() : null; } @Nullable diff --git a/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java b/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java index 10eb7f714fbb..15b3208b7426 100644 --- a/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -185,7 +185,7 @@ public class LambdaUtil { if (psiClass instanceof PsiAnonymousClass) { psiClass = PsiUtil.resolveClassInType(((PsiAnonymousClass)psiClass).getBaseClassType()); } - if (psiClass != null && psiClass.isInterface()) { + if (psiClass != null && psiClass.isInterface() && !psiClass.isAnnotationType()) { final List methods = new ArrayList(); final Collection visibleSignatures = psiClass.getVisibleSignatures(); for (HierarchicalMethodSignature signature : visibleSignatures) { diff --git a/java/java-psi-api/src/com/intellij/psi/PsiPrimitiveType.java b/java/java-psi-api/src/com/intellij/psi/PsiPrimitiveType.java index 6797e84deb80..dd6b0d4d6ef9 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiPrimitiveType.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiPrimitiveType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -31,18 +31,11 @@ import java.util.Map; * Represents primitive types of Java language. */ public class PsiPrimitiveType extends PsiType { + private static final Map ourQNameToUnboxed = new THashMap(); + private static final Map ourUnboxedToQName = new THashMap(); + private final String myName; - public PsiPrimitiveType(@NonNls @NotNull String name, PsiAnnotation[] annotations) { - super(annotations); - myName = name; - } - - @NonNls - private static final Map ourQNameToUnboxed = new THashMap(); - @NonNls - private static final Map ourUnboxedToQName = new THashMap(); - //registering ctor PsiPrimitiveType(@NonNls @NotNull String name, @NonNls String boxedName) { this(name, PsiAnnotation.EMPTY_ARRAY); if (boxedName != null) { @@ -51,6 +44,11 @@ public class PsiPrimitiveType extends PsiType { } } + public PsiPrimitiveType(@NonNls @NotNull String name, @NotNull PsiAnnotation[] annotations) { + super(annotations); + myName = name; + } + @NotNull @Override public String getPresentableText() { diff --git a/java/java-psi-api/src/com/intellij/psi/PsiType.java b/java/java-psi-api/src/com/intellij/psi/PsiType.java index 3b95be0b1cf6..cfbf026067bc 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiType.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -73,21 +73,22 @@ public abstract class PsiType implements PsiAnnotationOwner { } /** - * @return text of the type that can be presented to a user (non-qualified references, with annotations). + * Returns text of the type that can be presented to a user (references normally non-qualified). */ @NonNls @NotNull public abstract String getPresentableText(); /** - * @return text of the type (fully-qualified references, no annotations). + * Returns canonical representation of the type (all references fully-qualified). */ @NonNls @NotNull public abstract String getCanonicalText(); /** - * @return text of the type (fully-qualified references, with annotations). + * Return canonical text of the type with some internal details added for presentational purposes. Use with care. + * todo[r.sh] merge with getPresentableText() */ @NonNls @NotNull diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java index 00b27357fc17..b427f91648ca 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java @@ -543,7 +543,7 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps @NotNull @Override public PsiKeyword createKeyword(@NotNull final String text) throws IncorrectOperationException { - if (!JavaPsiFacade.getInstance(myManager.getProject()).getNameHelper().isKeyword(text)) { + if (!PsiNameHelper.getInstance(myManager.getProject()).isKeyword(text)) { throw new IncorrectOperationException("\"" + text + "\" is not a keyword."); } return new LightKeyword(myManager, text); @@ -579,7 +579,7 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps if (packageName.isEmpty()) { throw new IncorrectOperationException("Cannot create import statement for default package."); } - if (!JavaPsiFacade.getInstance(myManager.getProject()).getNameHelper().isQualifiedName(packageName)) { + if (!PsiNameHelper.getInstance(myManager.getProject()).isQualifiedName(packageName)) { throw new IncorrectOperationException("Incorrect package name: \"" + packageName + "\"."); } @@ -590,30 +590,38 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps @NotNull @Override - public PsiDeclarationStatement createVariableDeclarationStatement(@NotNull final String name, - @NotNull final PsiType type, - final PsiExpression initializer) throws IncorrectOperationException { - if (!JavaPsiFacade.getInstance(myManager.getProject()).getNameHelper().isIdentifier(name)) { + public PsiDeclarationStatement createVariableDeclarationStatement(@NotNull String name, + @NotNull PsiType type, + @Nullable PsiExpression initializer) throws IncorrectOperationException { + if (!isIdentifier(name)) { throw new IncorrectOperationException("\"" + name + "\" is not an identifier."); } if (PsiType.NULL.equals(type)) { throw new IncorrectOperationException("Cannot create variable with type \"null\"."); } - @NonNls final String text = "X " + name + (initializer != null ? " = x" : "") + ";"; + String text = "X " + name + (initializer != null ? " = x" : "") + ";"; + PsiDeclarationStatement statement = (PsiDeclarationStatement)createStatementFromText(text, null); - final PsiDeclarationStatement statement = (PsiDeclarationStatement)createStatementFromText(text, null); - final PsiVariable variable = (PsiVariable)statement.getDeclaredElements()[0]; + PsiVariable variable = (PsiVariable)statement.getDeclaredElements()[0]; replace(variable.getTypeElement(), createTypeElement(type), text); - PsiUtil.setModifierProperty(variable, PsiModifier.FINAL, - JavaCodeStyleSettingsFacade.getInstance(myManager.getProject()).isGenerateFinalLocals()); + + boolean generateFinalLocals = JavaCodeStyleSettingsFacade.getInstance(myManager.getProject()).isGenerateFinalLocals(); + PsiUtil.setModifierProperty(variable, PsiModifier.FINAL, generateFinalLocals); + if (initializer != null) { replace(variable.getInitializer(), initializer, text); } + GeneratedMarkerVisitor.markGenerated(statement); return statement; } + private static void replace(@Nullable PsiElement original, @NotNull PsiElement replacement, @NotNull String message) { + assert original != null : message; + original.replace(replacement); + } + @NotNull @Override public PsiDocTag createParamTag(@NotNull final String parameterName, @NonNls final String description) throws IncorrectOperationException { @@ -718,11 +726,6 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps return statements[0]; } - private static void replace(final PsiElement original, final PsiElement replacement, final String message) { - assert original != null : message; - original.replace(replacement); - } - private static final JavaParserUtil.ParserWrapper CATCH_SECTION = new JavaParserUtil.ParserWrapper() { @Override public void parse(final PsiBuilder builder) { @@ -782,6 +785,6 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps } private boolean isIdentifier(@NotNull String name) { - return JavaPsiFacade.getInstance(myManager.getProject()).getNameHelper().isIdentifier(name); + return PsiNameHelper.getInstance(myManager.getProject()).isIdentifier(name); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/FunctionalInterfaceAnnotation2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/FunctionalInterfaceAnnotation2.java new file mode 100644 index 000000000000..336da5957a5b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/FunctionalInterfaceAnnotation2.java @@ -0,0 +1,3 @@ +@FunctionalInterface +@interface Test { +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/introduceVariable/TypeAnnotations.after.java b/java/java-tests/testData/refactoring/introduceVariable/TypeAnnotations.after.java index 13598a7525ca..965568ae15f8 100644 --- a/java/java-tests/testData/refactoring/introduceVariable/TypeAnnotations.after.java +++ b/java/java-tests/testData/refactoring/introduceVariable/TypeAnnotations.after.java @@ -1,9 +1,7 @@ import java.lang.annotation.*; -@Target({ElementType.TYPE_USE/*, ElementType.TYPE*/}) -@interface TA { - -} +@Target({ElementType.TYPE_USE}) +@interface TA { } class C { void foo () { diff --git a/java/java-tests/testData/refactoring/introduceVariable/TypeAnnotations.java b/java/java-tests/testData/refactoring/introduceVariable/TypeAnnotations.java index bba9d94fa887..7f7db71cdd96 100644 --- a/java/java-tests/testData/refactoring/introduceVariable/TypeAnnotations.java +++ b/java/java-tests/testData/refactoring/introduceVariable/TypeAnnotations.java @@ -1,9 +1,7 @@ import java.lang.annotation.*; -@Target({ElementType.TYPE_USE/*, ElementType.TYPE*/}) -@interface TA { - -} +@Target({ElementType.TYPE_USE}) +@interface TA { } class C { void foo () { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java index 93c629a1498c..cf8f43b5508b 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -77,6 +77,7 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase { public void testIntersectionTypeInCast() { doTest(); } public void testAmbiguitySpecificReturn() { doTest(true); } public void testFunctionalInterfaceAnnotation() { doTest(); } + public void testFunctionalInterfaceAnnotation2() { doTest(); } public void testAmbiguityReturnValueResolution() { doTest(); } public void testAmbiguityReturnValueResolution1() { doTest(); } public void testAmbiguityReturnValueResolution2() { doTest(true); } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java index 09714d4b153e..fcadcd170588 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceVariableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -28,7 +28,6 @@ import com.intellij.refactoring.introduceVariable.IntroduceVariableSettings; import com.intellij.refactoring.ui.TypeSelectorManagerImpl; import com.intellij.testFramework.LightCodeInsightTestCase; import com.intellij.util.containers.MultiMap; -import junit.framework.Assert; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -302,6 +301,7 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase { public void testNonExpression() throws Exception { doTest(new MockIntroduceVariableHandler("sum", true, true, false, "int")); } + public void testTypeAnnotations() throws Exception { doTest(new MockIntroduceVariableHandler("y1", true, false, false, "@TA C")); } @@ -362,8 +362,8 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase { InputValidator validator, PsiElement anchor, final OccurrencesChooser.ReplaceChoice replaceChoice) { final PsiType type = typeSelectorManager.getDefaultType(); - Assert.assertTrue(type.getPresentableText(), type.getPresentableText().equals(expectedTypeName)); - Assert.assertEquals("path", IntroduceVariableBase.getSuggestedName(type, expr).names[0]); + assertTrue(type.getPresentableText(), type.getPresentableText().equals(expectedTypeName)); + assertEquals("path", IntroduceVariableBase.getSuggestedName(type, expr).names[0]); return super.getSettings(project, editor, expr, occurrences, typeSelectorManager, declareFinalIfAll, anyAssignmentLHS, validator, anchor, replaceChoice); } @@ -381,7 +381,7 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase { InputValidator validator, PsiElement anchor, final OccurrencesChooser.ReplaceChoice replaceChoice) { final PsiType type = typeSelectorManager.getDefaultType(); - Assert.assertTrue(type.getPresentableText(), type.getPresentableText().equals("B")); + assertTrue(type.getPresentableText(), type.getPresentableText().equals("B")); return super.getSettings(project, editor, expr, occurrences, typeSelectorManager, declareFinalIfAll, anyAssignmentLHS, validator, anchor, replaceChoice); } @@ -428,7 +428,7 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase { } public void testLambdaExpr() throws Exception { - + doTest(new MockIntroduceVariableHandler("c", false, false, false, "SAM")); } diff --git a/java/java-tests/testSrc/com/intellij/refactoring/MockIntroduceVariableHandler.java b/java/java-tests/testSrc/com/intellij/refactoring/MockIntroduceVariableHandler.java index 008f3f93a53f..9de7ab87c6d6 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/MockIntroduceVariableHandler.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/MockIntroduceVariableHandler.java @@ -1,17 +1,35 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.refactoring; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; -import com.intellij.psi.*; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiExpression; +import com.intellij.psi.PsiType; import com.intellij.refactoring.introduce.inplace.OccurrencesChooser; import com.intellij.refactoring.introduceVariable.InputValidator; import com.intellij.refactoring.introduceVariable.IntroduceVariableBase; import com.intellij.refactoring.introduceVariable.IntroduceVariableSettings; import com.intellij.refactoring.ui.TypeSelectorManagerImpl; import com.intellij.util.containers.MultiMap; -import junit.framework.Assert; import org.jetbrains.annotations.NonNls; +import static org.junit.Assert.assertTrue; + /** * @author dsl */ @@ -26,7 +44,6 @@ class MockIntroduceVariableHandler extends IntroduceVariableBase { public MockIntroduceVariableHandler(@NonNls final String name, final boolean replaceAll, final boolean declareFinal, final boolean replaceLValues, @NonNls final String expectedTypeCanonicalName) { - this(name, replaceAll, declareFinal, replaceLValues, expectedTypeCanonicalName, false); } @@ -52,7 +69,7 @@ class MockIntroduceVariableHandler extends IntroduceVariableBase { PsiElement anchor, final OccurrencesChooser.ReplaceChoice replaceChoice) { final PsiType type = myLookForType ? findType(typeSelectorManager.getTypesForAll(), typeSelectorManager.getDefaultType()) : typeSelectorManager.getDefaultType(); - Assert.assertTrue(type.getInternalCanonicalText(), type.getInternalCanonicalText().equals(myExpectedTypeCanonicalName)); + assertTrue(type.getInternalCanonicalText(), type.getInternalCanonicalText().equals(myExpectedTypeCanonicalName)); IntroduceVariableSettings introduceVariableSettings = new IntroduceVariableSettings() { @Override public String getEnteredName() { @@ -90,7 +107,7 @@ class MockIntroduceVariableHandler extends IntroduceVariableBase { } protected void assertValidationResult(final boolean validationResult) { - Assert.assertTrue(validationResult); + assertTrue(validationResult); } @Override diff --git a/platform/core-impl/src/com/intellij/indentation/IndentationParser.java b/platform/core-impl/src/com/intellij/indentation/IndentationParser.java index 677876834d5b..dc46db89f5f6 100644 --- a/platform/core-impl/src/com/intellij/indentation/IndentationParser.java +++ b/platform/core-impl/src/com/intellij/indentation/IndentationParser.java @@ -54,6 +54,10 @@ public abstract class IndentationParser implements PsiParser { final PsiBuilder.Marker fileMarker = builder.mark(); final PsiBuilder.Marker documentMarker = builder.mark(); + while (builder.getTokenType() == myEolTokenType) { + advanceLexer(builder); + } + final Stack stack = new Stack(); stack.push(new BlockInfo(0, builder.mark(), builder.getTokenType())); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandRegionAction.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandRegionAction.java index e2dbf16cac92..3eadd2e3df95 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandRegionAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/actions/ExpandRegionAction.java @@ -20,12 +20,12 @@ import com.intellij.codeInsight.folding.CodeFoldingManager; import com.intellij.codeInsight.folding.impl.FoldingUtil; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.FoldRegion; import com.intellij.openapi.editor.actionSystem.EditorAction; import com.intellij.openapi.editor.actionSystem.EditorActionHandler; import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class ExpandRegionAction extends EditorAction { @@ -47,10 +47,14 @@ public class ExpandRegionAction extends EditorAction { public static void expandRegionAtCaret(final Project project, @Nullable final Editor editor) { if (editor == null) return; + expandRegionAtOffset(project, editor, editor.getCaretModel().getOffset()); + } + + public static void expandRegionAtOffset(@NotNull Project project, @NotNull final Editor editor, final int offset) { CodeFoldingManager foldingManager = CodeFoldingManager.getInstance(project); foldingManager.updateFoldRegions(editor); - final int line = editor.getCaretModel().getLogicalPosition().line; + final int line = editor.getDocument().getLineNumber(offset); Runnable processor = new Runnable() { @Override public void run() { @@ -59,7 +63,6 @@ public class ExpandRegionAction extends EditorAction { region.setExpanded(true); } else{ - int offset = editor.getCaretModel().getOffset(); FoldRegion[] regions = FoldingUtil.getFoldRegionsAtOffset(editor, offset); for(int i = regions.length - 1; i >= 0; i--){ region = regions[i]; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java index fd433b9e5938..3e0e26424bb5 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/CtrlMouseHandler.java @@ -138,17 +138,20 @@ public class CtrlMouseHandler extends AbstractProjectComponent { BrowseMode browseMode = getBrowseMode(modifiers); if (browseMode != BrowseMode.None) { - if (myTooltipProvider != null) { - if (browseMode != myTooltipProvider.getBrowseMode()) { + TooltipProvider tooltipProvider = myTooltipProvider; + if (tooltipProvider != null) { + if (browseMode != tooltipProvider.getBrowseMode()) { disposeHighlighter(); } myStoredModifiers = modifiers; + cancelPreviousTooltip(); + myTooltipProvider = new TooltipProvider(tooltipProvider.myEditor, tooltipProvider.myPosition); myTooltipProvider.execute(browseMode); } } else { disposeHighlighter(); - myTooltipProvider = null; + cancelPreviousTooltip(); } } }; @@ -157,7 +160,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent { @Override public void selectionChanged(@NotNull FileEditorManagerEvent e) { disposeHighlighter(); - myTooltipProvider = null; + cancelPreviousTooltip(); } }; @@ -165,7 +168,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent { @Override public void visibleAreaChanged(VisibleAreaEvent e) { disposeHighlighter(); - myTooltipProvider = null; + cancelPreviousTooltip(); } }; @@ -173,7 +176,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent { @Override public void mouseReleased(EditorMouseEvent e) { disposeHighlighter(); - myTooltipProvider = null; + cancelPreviousTooltip(); } }; @@ -211,13 +214,10 @@ public class CtrlMouseHandler extends AbstractProjectComponent { myStoredModifiers = mouseEvent.getModifiers(); BrowseMode browseMode = getBrowseMode(myStoredModifiers); - if (myTooltipProvider != null) { - myTooltipProvider.dispose(); - } + cancelPreviousTooltip(); if (browseMode == BrowseMode.None || offset >= selStart && offset < selEnd) { disposeHighlighter(); - myTooltipProvider = null; return; } @@ -226,6 +226,13 @@ public class CtrlMouseHandler extends AbstractProjectComponent { } }; + private void cancelPreviousTooltip() { + if (myTooltipProvider != null) { + myTooltipProvider.dispose(); + myTooltipProvider = null; + } + } + @NotNull private final Alarm myDocAlarm; public CtrlMouseHandler(final Project project, diff --git a/platform/lang-impl/src/com/intellij/execution/console/ConsoleGutterComponent.java b/platform/lang-impl/src/com/intellij/execution/console/ConsoleGutterComponent.java index 38a8a13ea573..f7a1d6cc80fd 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/ConsoleGutterComponent.java +++ b/platform/lang-impl/src/com/intellij/execution/console/ConsoleGutterComponent.java @@ -54,7 +54,7 @@ class ConsoleGutterComponent extends JComponent implements MouseMotionListener { @Override public void mouseClicked(MouseEvent e) { if (!e.isPopupTrigger()) { - gutterContentProvider.doAction(getLineAtPoint(e.getPoint()), editor); + gutterContentProvider.doAction(EditorUtil.yPositionToLogicalLine(editor, e.getPoint()), editor); } } }); @@ -161,7 +161,7 @@ class ConsoleGutterComponent extends JComponent implements MouseMotionListener { @Override public void mouseMoved(MouseEvent e) { - int line = getLineAtPoint(e.getPoint()); + int line = EditorUtil.yPositionToLogicalLine(editor, e.getPoint()); if (line == lastGutterToolTipLine) { return; } @@ -189,10 +189,6 @@ class ConsoleGutterComponent extends JComponent implements MouseMotionListener { } } - private int getLineAtPoint(@NotNull Point clickPoint) { - return editor.yPositionToLogicalLine(clickPoint.y); - } - public void documentCleared() { maxAnnotationWidth = 0; } diff --git a/platform/lang-impl/src/com/intellij/webcore/packaging/InstalledPackagesPanel.java b/platform/lang-impl/src/com/intellij/webcore/packaging/InstalledPackagesPanel.java index f0a427825a79..f394c836475d 100644 --- a/platform/lang-impl/src/com/intellij/webcore/packaging/InstalledPackagesPanel.java +++ b/platform/lang-impl/src/com/intellij/webcore/packaging/InstalledPackagesPanel.java @@ -282,40 +282,35 @@ public class InstalledPackagesPanel extends JPanel { } private void updateUninstallUpgrade() { - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - final int[] selected = myPackagesTable.getSelectedRows(); - boolean upgradeAvailable = false; - boolean canUninstall = selected.length != 0; - boolean canUpgrade = true; - if (myPackageManagementService != null && selected.length != 0) { - for (int i = 0; i != selected.length; ++i) { - final int index = selected[i]; - if (index >= myPackagesTable.getRowCount()) continue; - final Object value = myPackagesTable.getValueAt(index, 0); - if (value instanceof InstalledPackage) { - final InstalledPackage pkg = (InstalledPackage)value; - if (!canUninstallPackage(pkg)) { - canUninstall = false; - } - if (!canUpgradePackage(pkg)) { - canUpgrade = false; - } - final String pyPackageName = pkg.getName(); - final String availableVersion = (String)myPackagesTable.getValueAt(index, 2); - if (!upgradeAvailable) { - upgradeAvailable = PackageVersionComparator.VERSION_COMPARATOR.compare(pkg.getVersion(), availableVersion) < 0 && - !myCurrentlyInstalling.contains(pyPackageName); - } - if (!canUninstall && !canUpgrade) break; - } + final int[] selected = myPackagesTable.getSelectedRows(); + boolean upgradeAvailable = false; + boolean canUninstall = selected.length != 0; + boolean canUpgrade = true; + if (myPackageManagementService != null && selected.length != 0) { + for (int i = 0; i != selected.length; ++i) { + final int index = selected[i]; + if (index >= myPackagesTable.getRowCount()) continue; + final Object value = myPackagesTable.getValueAt(index, 0); + if (value instanceof InstalledPackage) { + final InstalledPackage pkg = (InstalledPackage)value; + if (!canUninstallPackage(pkg)) { + canUninstall = false; } + if (!canUpgradePackage(pkg)) { + canUpgrade = false; + } + final String pyPackageName = pkg.getName(); + final String availableVersion = (String)myPackagesTable.getValueAt(index, 2); + if (!upgradeAvailable) { + upgradeAvailable = PackageVersionComparator.VERSION_COMPARATOR.compare(pkg.getVersion(), availableVersion) < 0 && + !myCurrentlyInstalling.contains(pyPackageName); + } + if (!canUninstall && !canUpgrade) break; } - myUninstallButton.setEnabled(canUninstall); - myUpgradeButton.setEnabled(upgradeAvailable && canUpgrade); } - }, ModalityState.any()); + } + myUninstallButton.setEnabled(canUninstall); + myUpgradeButton.setEnabled(upgradeAvailable && canUpgrade); } protected boolean canUninstallPackage(InstalledPackage pyPackage) { @@ -401,6 +396,7 @@ public class InstalledPackagesPanel extends JPanel { private void onUpdateFinished() { myPackagesTable.setPaintBusy(false); myPackagesTable.getEmptyText().setText(StatusText.DEFAULT_EMPTY_TEXT); + updateUninstallUpgrade(); } public void doUpdatePackages(@NotNull final PackageManagementService packageManagementService) { @@ -472,27 +468,23 @@ public class InstalledPackagesPanel extends JPanel { private void decrement() { if (inProgressPackageCount.decrementAndGet() == 0) { - UIUtil.invokeLaterIfNeeded(new Runnable() { - @Override - public void run() { - onUpdateFinished(); - } - }); + onUpdateFinished(); } } @Override public void consume(Exception e) { - decrement(); + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + decrement(); + } + }); } @Override public void consume(@Nullable final String latestVersion) { - if (latestVersion == null) { - decrement(); - return; - } - ApplicationManager.getApplication().invokeLater(new Runnable() { + UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { if (finalIndex < myPackagesTableModel.getRowCount()) { @@ -503,7 +495,7 @@ public class InstalledPackagesPanel extends JPanel { } decrement(); } - }, ModalityState.any()); + }); } }); } diff --git a/platform/platform-impl/src/com/intellij/execution/impl/ConsoleViewUtil.java b/platform/platform-impl/src/com/intellij/execution/impl/ConsoleViewUtil.java index ae870e29f491..b8f27b43a488 100644 --- a/platform/platform-impl/src/com/intellij/execution/impl/ConsoleViewUtil.java +++ b/platform/platform-impl/src/com/intellij/execution/impl/ConsoleViewUtil.java @@ -133,7 +133,7 @@ public class ConsoleViewUtil { }; } - public static boolean isConsoleViewEditor(Editor editor) { + public static boolean isConsoleViewEditor(@NotNull Editor editor) { return editor.getUserData(EDITOR_IS_CONSOLE_VIEW) == Boolean.TRUE; } diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionManagerImpl.java index ff2a354ebb27..e6a79dd487b3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionManagerImpl.java @@ -691,7 +691,9 @@ public final class ActionManagerImpl extends ActionManagerEx implements Applicat assertActionIsGroupOrStub(action); } - String actionName = action instanceof ActionStub ? ((ActionStub)action).getClassName() : action.getClass().getName(); + String actionName = String.format( + "%s (%s)", action instanceof ActionStub? ((ActionStub)action).getClassName() : action.getClass().getName(), + action instanceof ActionStub ? ((ActionStub)action).getId() : myAction2Id.get(action)); if (!ADD_TO_GROUP_ELEMENT_NAME.equals(element.getName())) { reportActionError(pluginId, "unexpected name of element \"" + element.getName() + "\""); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java index c1f1b5a144c5..012410d34fe3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/EditorUtil.java @@ -36,15 +36,16 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.awt.*; +import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; import java.util.Arrays; import java.util.List; -public class EditorUtil { +public final class EditorUtil { + private static final Logger LOG = Logger.getInstance(EditorUtil.class); - private static final Logger LOG = Logger.getInstance("#" + EditorUtil.class.getName()); - - private EditorUtil() { } + private EditorUtil() { + } public static int getLastVisualLineColumnNumber(@NotNull Editor editor, final int line) { Document document = editor.getDocument(); @@ -191,7 +192,7 @@ public class EditorUtil { if (!filler.isEmpty()) { new WriteAction(){ @Override - protected void run(final Result result) throws Throwable { + protected void run(@NotNull Result result) throws Throwable { editor.getDocument().insertString(offset, filler); editor.getCaretModel().moveToOffset(offset + filler.length()); } @@ -792,6 +793,19 @@ public class EditorUtil { int end = ends.length > 0 ? ends[ends.length - 1] : selection.getSelectionEnd(); return TextRange.create(start, end); } + + public static int yPositionToLogicalLine(@NotNull Editor editor, @NotNull MouseEvent event) { + return yPositionToLogicalLine(editor, event.getY()); + } + + public static int yPositionToLogicalLine(@NotNull Editor editor, @NotNull Point point) { + return yPositionToLogicalLine(editor, point.y); + } + + public static int yPositionToLogicalLine(@NotNull Editor editor, int y) { + int line = y / editor.getLineHeight(); + return line > 0 ? editor.visualToLogicalPosition(new VisualPosition(line, 0)).line : 0; + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java index 2b3ae68232e9..33cebb543c6f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java @@ -1118,7 +1118,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse if (toolTip != null && !toolTip.isEmpty()) { final Ref t = new Ref(e.getPoint()); - int line = myEditor.yPositionToLogicalLine(e.getY()); + int line = EditorUtil.yPositionToLogicalLine(myEditor, e); ArrayList row = myLineToGutterRenderers.get(line); Balloon.Position ballPosition = Balloon.Position.atRight; if (row != null) { @@ -1182,7 +1182,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse } private int getLineNumAtPoint(final Point clickPoint) { - return myEditor.yPositionToLogicalLine(clickPoint.y); + return EditorUtil.yPositionToLogicalLine(myEditor, clickPoint); } @Nullable @@ -1346,7 +1346,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse actionGroup.add(new CloseAnnotationsAction()); final List addActions = new ArrayList(); final Point p = e.getPoint(); - int line = myEditor.yPositionToLogicalLine((int)p.getY()); + int line = EditorUtil.yPositionToLogicalLine(myEditor, p); //if (line >= myEditor.getDocument().getLineCount()) return; for (TextAnnotationGutterProvider gutterProvider : myTextAnnotationGutters) { @@ -1405,7 +1405,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse } private int convertPointToLineNumber(final Point p) { - int line = myEditor.yPositionToLogicalLine((int)p.getY()); + int line = EditorUtil.yPositionToLogicalLine(myEditor, p); if (line >= myEditor.getDocument().getLineCount()) return -1; int startOffset = myEditor.getDocument().getLineStartOffset(line); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index a6701c5f7458..aa04b488cf29 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -1112,15 +1112,6 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi return y / getLineHeight(); } - public int yPositionToLogicalLine(int y) { - int line = yPositionToVisibleLine(y); - if (line <= 0) { - return 0; - } - LogicalPosition logicalPosition = visualToLogicalPosition(new VisualPosition(line, 0)); - return logicalPosition.line; - } - @Override @NotNull public VisualPosition xyToVisualPosition(@NotNull Point p) { @@ -1372,7 +1363,6 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi @NotNull public LogicalPosition xyToLogicalPosition(@NotNull Point p) { Point pp = p.x >= 0 && p.y >= 0 ? p : new Point(Math.max(p.x, 0), Math.max(p.y, 0)); - return visualToLogicalPosition(xyToVisualPosition(pp)); } @@ -2382,7 +2372,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi validateSize(); // Repaint editor to the bottom in order to ensure that its content is shown correctly after new soft wrap introduction. - repaintToScreenBottom(yPositionToLogicalLine(position.y)); + repaintToScreenBottom(EditorUtil.yPositionToLogicalLine(this, position)); // Repaint gutter at all space that is located after active clip in order to ensure that line numbers are correctly redrawn // in accordance with the newly introduced soft wrap(s). @@ -5484,7 +5474,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi putUserData(EditorActionUtil.EXPECTED_CARET_OFFSET, null); if (event.getArea() == EditorMouseEventArea.LINE_MARKERS_AREA) { - myDragOnGutterSelectionStartLine = yPositionToLogicalLine(e.getY()); + myDragOnGutterSelectionStartLine = EditorUtil.yPositionToLogicalLine(EditorImpl.this, e); } // On some systems (for example on Linux) popup trigger is MOUSE_PRESSED event. @@ -6554,8 +6544,8 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi int endToUse = Math.min(lineCount, myLineWidths.size()); if (endToUse > 0 && getSoftWrapModel().isSoftWrappingEnabled()) { Rectangle visibleArea = getScrollingModel().getVisibleArea(); - startToUse = yPositionToLogicalLine(visibleArea.getLocation().y); - endToUse = Math.min(endToUse, yPositionToLogicalLine(visibleArea.y + visibleArea.height)); + startToUse = EditorUtil.yPositionToLogicalLine(EditorImpl.this, visibleArea.getLocation()); + endToUse = Math.min(endToUse, EditorUtil.yPositionToLogicalLine(EditorImpl.this, visibleArea.y + visibleArea.height)); if (endToUse <= startToUse) { // There is a possible case that there is the only soft-wrapped line, i.e. end == start. We still want to update the // size container's width then. diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java index 03b63092d597..aa4e2571838c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java @@ -1299,10 +1299,12 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone private static class JarRoot extends AbstractRoot { private final VirtualFile myParentLocalFile; + private final String myParentPath; private JarRoot(@NotNull NewVirtualFileSystem fs, int rootId, @NotNull VirtualFile parentLocalFile) { super(fs, rootId); myParentLocalFile = parentLocalFile; + myParentPath = myParentLocalFile.getPath(); } @NotNull @@ -1313,9 +1315,8 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone @Override protected char[] appendPathOnFileSystem(int accumulatedPathLength, int[] positionRef) { - String parentPath = myParentLocalFile.getPath(); - char[] chars = new char[parentPath.length() + JarFileSystem.JAR_SEPARATOR.length() + accumulatedPathLength]; - positionRef[0] = copyString(chars, positionRef[0], myParentLocalFile.getPath()); + char[] chars = new char[myParentPath.length() + JarFileSystem.JAR_SEPARATOR.length() + accumulatedPathLength]; + positionRef[0] = copyString(chars, positionRef[0], myParentPath); positionRef[0] = copyString(chars, positionRef[0], JarFileSystem.JAR_SEPARATOR); return chars; } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/MemoryUsagePanel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/MemoryUsagePanel.java index 80aa74b1ce47..26220fb464d7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/MemoryUsagePanel.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/MemoryUsagePanel.java @@ -16,14 +16,12 @@ package com.intellij.openapi.wm.impl.status; import com.intellij.concurrency.JobScheduler; -import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.wm.CustomStatusBarWidget; import com.intellij.openapi.wm.StatusBar; import com.intellij.openapi.wm.StatusBarWidget; import com.intellij.ui.Gray; import com.intellij.ui.JBColor; import com.intellij.ui.UIBundle; -import com.intellij.util.SystemProperties; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -39,10 +37,6 @@ import java.util.concurrent.TimeUnit; public class MemoryUsagePanel extends JButton implements CustomStatusBarWidget { @NonNls public static final String WIDGET_ID = "Memory"; - - // todo: drop unless J. will insist to keep old style look - private static final boolean FRAMED_STYLE = SystemInfo.isMac || !SystemProperties.getBooleanProperty("idea.ui.old.mem.use", false); - private static final int MEGABYTE = 1024 * 1024; @NonNls private static final String SAMPLE_STRING; @@ -113,8 +107,7 @@ public class MemoryUsagePanel extends JButton implements CustomStatusBarWidget { } private static Font getWidgetFont() { - final Font font = UIUtil.getLabelFont(); - return FRAMED_STYLE ? font.deriveFont(11.0f) : font; + return UIUtil.getLabelFont().deriveFont(11.0f); } @Override @@ -130,7 +123,7 @@ public class MemoryUsagePanel extends JButton implements CustomStatusBarWidget { if (myBufferedImage == null || stateChanged) { final Dimension size = getSize(); - final Insets insets = FRAMED_STYLE ? getInsets() : new Insets(0, 0, 0, 0); + final Insets insets = getInsets(); myBufferedImage = UIUtil.createImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = (Graphics2D)myBufferedImage.getGraphics().create(); @@ -144,7 +137,7 @@ public class MemoryUsagePanel extends JButton implements CustomStatusBarWidget { final int totalBarLength = size.width - insets.left - insets.right; final int usedBarLength = (int)(totalBarLength * usedMem / maxMem); final int unusedBarLength = (int)(totalBarLength * unusedMem / maxMem); - final int barHeight = FRAMED_STYLE ? HEIGHT : size.height; + final int barHeight = HEIGHT; final int yOffset = (size.height - barHeight) / 2; final int xOffset = insets.left; @@ -170,7 +163,7 @@ public class MemoryUsagePanel extends JButton implements CustomStatusBarWidget { } // frame - if (FRAMED_STYLE && !UIUtil.isUnderDarcula()) { + if (!UIUtil.isUnderDarcula()) { g2.setColor(USED_COLOR_2); g2.drawRect(xOffset, yOffset, totalBarLength - 1, barHeight - 1); } diff --git a/platform/platform-resources/src/brokenPlugins.txt b/platform/platform-resources/src/brokenPlugins.txt index b58f71889e08..e34b74e756ab 100644 --- a/platform/platform-resources/src/brokenPlugins.txt +++ b/platform/platform-resources/src/brokenPlugins.txt @@ -2,14 +2,14 @@ // Each line contains plugin ID and list of versions that are broken. // If plugin name or version contains a space you can quote it like in command line. -NodeJS 134.1163 134.1145 134.1081 134.1039 134.985 134.680 134.31 134.307 134.262 134.198 134.125 -com.jetbrains.php 133.679 133.51 133.326 131.98 131.374 131.332 131.235 131.205 130.1639 130.1481 130.1176 129.91 129.814 129.672 129.362 127.67 127.100 126.334 123.66 122.875 121.62 121.390 121.215 121.12 +NodeJS 134.1276 134.1163 134.1145 134.1081 134.1039 134.985 134.680 134.31 134.307 134.262 134.198 134.125 +com.jetbrains.php 133.982 133.679 133.51 133.326 131.98 131.374 131.332 131.235 131.205 130.1639 130.1481 130.1176 129.91 129.814 129.672 129.362 127.67 127.100 126.334 123.66 122.875 121.62 121.390 121.215 121.12 com.jetbrains.lang.ejs 131.17 131.12 com.jetbrains.twig 133.51 130.1639 -//org.jetbrains.plugins.ruby 6.0.0.20140207 +org.jetbrains.plugins.ruby 6.0.0.20140207 Pythonid 3.1 -Karma 134.686 134.31 +Karma 134.1163 134.1039 134.686 134.31 org.intellij.scala 0.32.512 org.jetbrains.kannotator 0.2.420 SBT 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.4.0 1.5.0 -"JSTestDriver Plugin" 134.686 134.31 134.307 134.1039 \ No newline at end of file +"JSTestDriver Plugin" 134.1163 134.686 134.31 134.307 134.1039 \ No newline at end of file diff --git a/platform/util/src/com/intellij/util/ArrayUtil.java b/platform/util/src/com/intellij/util/ArrayUtil.java index 1f75e0c78065..1e47adf8fcf1 100644 --- a/platform/util/src/com/intellij/util/ArrayUtil.java +++ b/platform/util/src/com/intellij/util/ArrayUtil.java @@ -441,6 +441,10 @@ public class ArrayUtil extends ArrayUtilRt { return indexOf(src, obj); } + public static int find(@NotNull final T[] src, final T obj) { + return ArrayUtilRt.find(src, obj); + } + public static boolean startsWith(@NotNull byte[] array, @NotNull byte[] prefix) { if (array == prefix) { return true; diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java index e689e30f85f6..3aab9e884b2d 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java @@ -15,6 +15,7 @@ */ package com.intellij.xdebugger.impl.breakpoints; +import com.intellij.execution.impl.ConsoleViewUtil; import com.intellij.ide.startup.StartupManagerEx; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; @@ -25,6 +26,7 @@ import com.intellij.openapi.editor.colors.EditorColorsAdapter; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.event.*; +import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.editor.markup.MarkupEditorFilterFactory; import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.fileEditor.FileDocumentManager; @@ -71,12 +73,9 @@ public class XLineBreakpointManager { myStartupManager = (StartupManagerEx)startupManager; if (!myProject.isDefault()) { - DocumentAdapter documentListener = new MyDocumentListener(); - EditorMouseAdapter editorMouseListener = new MyEditorMouseListener(); - EditorEventMulticaster editorEventMulticaster = EditorFactory.getInstance().getEventMulticaster(); - editorEventMulticaster.addDocumentListener(documentListener,project); - editorEventMulticaster.addEditorMouseListener(editorMouseListener, project); + editorEventMulticaster.addDocumentListener(new MyDocumentListener(), project); + editorEventMulticaster.addEditorMouseListener(new MyEditorMouseListener(), project); final MyDependentBreakpointListener myDependentBreakpointListener = new MyDependentBreakpointListener(); myDependentBreakpointManager.addListener(myDependentBreakpointListener); @@ -248,7 +247,7 @@ public class XLineBreakpointManager { private class MyEditorMouseListener extends EditorMouseAdapter { @Override - public void mouseClicked(final EditorMouseEvent e) { + public void mouseClicked(EditorMouseEvent e) { final Editor editor = e.getEditor(); final MouseEvent mouseEvent = e.getMouseEvent(); if (mouseEvent.isPopupTrigger() @@ -256,6 +255,7 @@ public class XLineBreakpointManager { || mouseEvent.getButton() != MouseEvent.BUTTON1 || MarkupEditorFilterFactory.createIsDiffFilter().avaliableIn(editor) || e.getArea() != EditorMouseEventArea.LINE_MARKERS_AREA + || ConsoleViewUtil.isConsoleViewEditor(editor) ||!isFromMyProject(editor)) { return; } @@ -263,7 +263,7 @@ public class XLineBreakpointManager { PsiDocumentManager.getInstance(myProject).commitAndRunReadAction(new Runnable() { @Override public void run() { - final int line = editor.xyToLogicalPosition(mouseEvent.getPoint()).line; + final int line = EditorUtil.yPositionToLogicalLine(editor, mouseEvent); final Document document = editor.getDocument(); final VirtualFile file = FileDocumentManager.getInstance().getFile(document); if (line >= 0 && line < document.getLineCount() && file != null) { @@ -281,7 +281,11 @@ public class XLineBreakpointManager { } } - private boolean isFromMyProject(Editor editor) { + private boolean isFromMyProject(@NotNull Editor editor) { + if (myProject == editor.getProject()) { + return true; + } + for (FileEditor fileEditor : FileEditorManager.getInstance(myProject).getAllEditors()) { if (fileEditor instanceof TextEditor && ((TextEditor)fileEditor).getEditor().equals(editor)) { return true; diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/classlayout/InterfaceMayBeAnnotatedFunctionalInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/classlayout/InterfaceMayBeAnnotatedFunctionalInspectionTest.java index ab4e3e8f77f5..3d41d4123d97 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/classlayout/InterfaceMayBeAnnotatedFunctionalInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/classlayout/InterfaceMayBeAnnotatedFunctionalInspectionTest.java @@ -44,6 +44,10 @@ public class InterfaceMayBeAnnotatedFunctionalInspectionTest extends LightInspec "}"); } + public void testAnnotationType() { + doTest("@interface A {}"); + } + @Override protected InspectionProfileEntry getInspection() { return new InterfaceMayBeAnnotatedFunctionalInspection(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java index 390121779bea..82cfe11991df 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java @@ -432,6 +432,7 @@ public class GroovyDslFileIndex extends ScalarIndexExtension { } private static final Key>> SCRIPTS_CACHE = Key.create("GdslScriptCache"); + private static List getDslScripts(final Project project) { return CachedValuesManager.getManager(project).getCachedValue(project, SCRIPTS_CACHE, new CachedValueProvider>() { @Override @@ -445,9 +446,6 @@ public class GroovyDslFileIndex extends ScalarIndexExtension { List result = new ArrayList(); List> standardScripts = getStandardScripts(); - if (ourGdslStopped) { - return Result.create(Collections.emptyList(), Collections.emptyList()); - } assert standardScripts != null; for (Pair pair : standardScripts) { result.add(new GroovyDslScript(project, null, pair.second, pair.first.getPath())); @@ -457,7 +455,8 @@ public class GroovyDslFileIndex extends ScalarIndexExtension { new LinkedBlockingQueue>(); final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); - for (VirtualFile vfile : FileBasedIndex.getInstance().getContainingFiles(NAME, OUR_KEY, GlobalSearchScope.allScope(project))) { + final GlobalSearchScope scope = GlobalSearchScope.allScope(project); + for (VirtualFile vfile : FileBasedIndex.getInstance().getContainingFiles(NAME, OUR_KEY, scope)) { if (!vfile.isValid()) { continue; }