diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java index 22713d295929..258b10dcfa0e 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java @@ -496,12 +496,12 @@ public class DebuggerManagerImpl extends DebuggerManagerEx { } private static boolean shouldAddXdebugKey(Sdk jdk) { + if (jdk == null) { + return true; // conservative choice + } if (DebuggerSettings.getInstance().DISABLE_JIT) { return true; } - if (jdk == null) { - return false; // assume newer jdk by default - } //if (ApplicationManager.getApplication().isUnitTestMode()) { // need this in unit tests to avoid false alarms when comparing actual output with expected output @@ -520,7 +520,7 @@ public class DebuggerManagerImpl extends DebuggerManagerEx { private static boolean isJVMTIAvailable(Sdk jdk) { if (jdk == null) { - return true; // assume newer jdk by default + return false; // conservative choice } final String version = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VERSION); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/HeaderHidingTabbedModuleEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/HeaderHidingTabbedModuleEditor.java index 721cc77135de..3a3f04bac551 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/HeaderHidingTabbedModuleEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/HeaderHidingTabbedModuleEditor.java @@ -65,11 +65,16 @@ public abstract class HeaderHidingTabbedModuleEditor extends TabbedModuleEditor } @Override + @Nullable public ModuleConfigurationEditor getEditor(@NotNull String displayName) { ModuleConfigurationEditor singleEditor = getSingleEditor(); if (singleEditor != null) { - assert singleEditor.getDisplayName().equals(displayName); - return singleEditor; + if (displayName.equals(singleEditor.getDisplayName())) { + return singleEditor; + } + else { + return null; + } } else { return super.getEditor(displayName); diff --git a/java/java-impl/src/com/intellij/codeInsight/TailTypes.java b/java/java-impl/src/com/intellij/codeInsight/TailTypes.java index 00c1aa4ff431..e20c3569c198 100644 --- a/java/java-impl/src/com/intellij/codeInsight/TailTypes.java +++ b/java/java-impl/src/com/intellij/codeInsight/TailTypes.java @@ -20,25 +20,26 @@ import com.intellij.codeInsight.completion.simple.ParenthesesTailType; import com.intellij.codeInsight.completion.simple.RParenthTailType; import com.intellij.openapi.editor.Editor; import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; public class TailTypes { public static final TailType CALL_RPARENTH = new RParenthTailType(){ - protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES && editor.getDocument().getCharsSequence().charAt(tailOffset - 1) != '('; } }; public static final TailType IF_RPARENTH = new RParenthTailType(){ - protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_WITHIN_IF_PARENTHESES; } }; public static final TailType WHILE_RPARENTH = new RParenthTailType(){ - protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_WITHIN_WHILE_PARENTHESES; } }; public static final TailType CALL_RPARENTH_SEMICOLON = new RParenthTailType(){ - protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES; } @@ -48,56 +49,56 @@ public class TailTypes { }; public static final TailType SYNCHRONIZED_LPARENTH = new ParenthesesTailType() { - protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_BEFORE_SYNCHRONIZED_PARENTHESES; } - protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_WITHIN_SYNCHRONIZED_PARENTHESES; } }; public static final TailType CATCH_LPARENTH = new ParenthesesTailType() { - protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_BEFORE_CATCH_PARENTHESES; } - protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_WITHIN_CATCH_PARENTHESES; } }; public static final TailType SWITCH_LPARENTH = new ParenthesesTailType() { - protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_BEFORE_SWITCH_PARENTHESES; } - protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_WITHIN_SWITCH_PARENTHESES; } }; public static final TailType WHILE_LPARENTH = new ParenthesesTailType() { - protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_BEFORE_WHILE_PARENTHESES; } - protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_WITHIN_WHILE_PARENTHESES; } }; public static final TailType FOR_LPARENTH = new ParenthesesTailType() { - protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_BEFORE_FOR_PARENTHESES; } - protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_WITHIN_FOR_PARENTHESES; } }; public static final TailType IF_LPARENTH = new ParenthesesTailType() { - protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_BEFORE_IF_PARENTHESES; } - protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { + protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) { return styleSettings.SPACE_WITHIN_IF_PARENTHESES; } }; diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/CastingLookupElementDecorator.java b/java/java-impl/src/com/intellij/codeInsight/completion/CastingLookupElementDecorator.java index 00b8538dcc66..e6e3a05f7b73 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/CastingLookupElementDecorator.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/CastingLookupElementDecorator.java @@ -20,8 +20,7 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.util.ClassConditionKey; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiType; -import com.intellij.psi.codeStyle.CodeStyleSettings; -import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; import org.jetbrains.annotations.Nullable; /** @@ -64,7 +63,7 @@ public class CastingLookupElementDecorator extends LookupElementDecorator { context.getOffsetMap().getOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET)); } - final CodeStyleSettings csSettings = CodeStyleSettingsManager.getSettings(context.getProject()); + final CommonCodeStyleSettings csSettings = context.getCodeStyleSettings(); final int oldTail = context.getTailOffset(); context.setTailOffset(RParenthTailType.addRParenth(editor, oldTail, csSettings.SPACE_WITHIN_CAST_PARENTHESES)); diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/simple/ParenthesesTailType.java b/java/java-impl/src/com/intellij/codeInsight/completion/simple/ParenthesesTailType.java index 8b9952724c3c..935a45b7baef 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/simple/ParenthesesTailType.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/simple/ParenthesesTailType.java @@ -18,20 +18,19 @@ package com.intellij.codeInsight.completion.simple; import com.intellij.codeInsight.TailType; import com.intellij.openapi.editor.Editor; -import com.intellij.psi.codeStyle.CodeStyleSettings; -import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; /** * @author peter */ public abstract class ParenthesesTailType extends TailType { - protected abstract boolean isSpaceBeforeParentheses(CodeStyleSettings styleSettings, Editor editor, final int tailOffset); + protected abstract boolean isSpaceBeforeParentheses(CommonCodeStyleSettings styleSettings, Editor editor, final int tailOffset); - protected abstract boolean isSpaceWithinParentheses(CodeStyleSettings styleSettings, Editor editor, final int tailOffset); + protected abstract boolean isSpaceWithinParentheses(CommonCodeStyleSettings styleSettings, Editor editor, final int tailOffset); public int processTail(final Editor editor, int tailOffset) { - CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(editor.getProject()); + CommonCodeStyleSettings styleSettings = getLocalCodeStyleSettings(editor, tailOffset); if (isSpaceBeforeParentheses(styleSettings, editor, tailOffset)) { tailOffset = insertChar(editor, tailOffset, ' '); } diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/simple/RParenthTailType.java b/java/java-impl/src/com/intellij/codeInsight/completion/simple/RParenthTailType.java index 842bb8c7fc93..d3454b4df778 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/simple/RParenthTailType.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/simple/RParenthTailType.java @@ -24,8 +24,7 @@ import com.intellij.openapi.editor.highlighter.EditorHighlighter; import com.intellij.openapi.editor.highlighter.HighlighterIterator; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; -import com.intellij.psi.codeStyle.CodeStyleSettings; -import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; import com.intellij.psi.impl.source.tree.ElementType; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.java.IJavaElementType; @@ -50,10 +49,10 @@ public abstract class RParenthTailType extends TailType { return element == null ? new TextRange(0, document.getTextLength()) : element.getTextRange(); } - protected abstract boolean isSpaceWithinParentheses(CodeStyleSettings styleSettings, Editor editor, final int tailOffset); + protected abstract boolean isSpaceWithinParentheses(CommonCodeStyleSettings styleSettings, Editor editor, final int tailOffset); public int processTail(final Editor editor, int tailOffset) { - return addRParenth(editor, tailOffset, isSpaceWithinParentheses(CodeStyleSettingsManager.getSettings(editor.getProject()), editor, tailOffset)); + return addRParenth(editor, tailOffset, isSpaceWithinParentheses(getLocalCodeStyleSettings(editor, tailOffset), editor, tailOffset)); } public static int addRParenth(Editor editor, int offset, boolean spaceWithinParens) { diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java index 7a1b3d99a552..d3ffbc9bb33b 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java @@ -353,41 +353,18 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool { } return; } - refElement.accept(new RefJavaVisitor() { - @Override public void visitElement(final RefEntity elem) { - if (elem instanceof RefElement) { - final RefElement element = (RefElement)elem; - if (isEntryPoint(element)) { - getEntryPointsManager().addEntryPoint(element, false); - } - } - } + refElement.accept(new RefJavaVisitor() { @Override public void visitMethod(RefMethod method) { if (isAddMainsEnabled() && method.isAppMain()) { getEntryPointsManager().addEntryPoint(method, false); - } else { - super.visitMethod(method); } } @Override public void visitClass(RefClass aClass) { - final PsiClass psiClass = aClass.getElement(); - if (psiClass == null) return; - if ( - isAddAppletEnabled() && aClass.isApplet() || - isAddServletEnabled() && aClass.isServlet()) { + if (isAddAppletEnabled() && aClass.isApplet() || + isAddServletEnabled() && aClass.isServlet()) { getEntryPointsManager().addEntryPoint(aClass, false); - } else if (psiClass.isAnnotationType()){ - getEntryPointsManager().addEntryPoint(aClass, false); - final PsiMethod[] psiMethods = psiClass.getMethods(); - for (PsiMethod psiMethod : psiMethods) { - getEntryPointsManager().addEntryPoint(getRefManager().getReference(psiMethod), false); - } - } else if (psiClass.isEnum()) { - getEntryPointsManager().addEntryPoint(aClass, false); - } else { - super.visitClass(aClass); } } }); @@ -437,7 +414,7 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool { myPhase = 1; } - private boolean isEntryPoint(final RefElement owner) { + public boolean isEntryPoint(final RefElement owner) { final PsiElement element = owner.getElement(); if (RefUtil.isImplicitUsage(element)) return true; if (element instanceof PsiModifierListOwner) { @@ -907,8 +884,6 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool { @Override public void visitElement(RefEntity refEntity) { if (refEntity instanceof RefJavaElement) { final RefJavaElementImpl refElement = (RefJavaElementImpl)refEntity; - final PsiElement element = refElement.getElement(); - if (element == null) return; if (!getContext().isToCheckMember(refElement, UnusedDeclarationInspection.this)) return; refElement.setReachable(false); } diff --git a/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java b/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java index a3aaf703c3d0..9d7aaeb2ea1b 100644 --- a/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/reference/RefJavaManagerImpl.java @@ -15,14 +15,20 @@ */ package com.intellij.codeInspection.reference; +import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.codeInspection.InspectionsBundle; import com.intellij.codeInspection.SuppressionUtil; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; import com.intellij.codeInspection.ex.EntryPointsManager; import com.intellij.codeInspection.ex.EntryPointsManagerImpl; +import com.intellij.codeInspection.ex.InspectionToolWrapper; +import com.intellij.codeInspection.ex.Tools; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.UserDataCache; import com.intellij.psi.*; import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.javadoc.PsiDocTag; @@ -89,6 +95,41 @@ public class RefJavaManagerImpl extends RefJavaManager { return refPackage; } + + public boolean isEntryPoint(final RefElement element) { + UnusedDeclarationInspection tool = getDeadCodeTool(element); + return tool != null && tool.isEntryPoint(element); + } + + @Nullable + private UnusedDeclarationInspection getDeadCodeTool(RefElement element) { + PsiFile file = ((RefElementImpl)element).getContainingFile(); + if (file == null) return null; + + return getDeadCodeTool(file); + } + + private static final UserDataCache, PsiFile, RefManagerImpl> DEAD_CODE_TOOL = new UserDataCache, PsiFile, RefManagerImpl>("DEAD_CODE_TOOL") { + @Override + protected Ref compute(PsiFile file, RefManagerImpl refManager) { + Tools tools = refManager.getContext().getTools().get(UnusedDeclarationInspection.SHORT_NAME); + InspectionProfileEntry tool = tools != null ? tools.getEnabledTool(file) : null; + if (tool instanceof InspectionToolWrapper) tool = ((InspectionToolWrapper)tool).getTool(); + return Ref.create(tool instanceof UnusedDeclarationInspection ? (UnusedDeclarationInspection)tool : null); + } + }; + + @Nullable + private UnusedDeclarationInspection getDeadCodeTool(PsiElement element) { + PsiFile file = element.getContainingFile(); + return file != null ? DEAD_CODE_TOOL.get(file, myRefManager).get() : null; + } + + public boolean isEntryPoint(PsiElement element) { + UnusedDeclarationInspection tool = getDeadCodeTool(element); + return tool != null && tool.isEntryPoint(element); + } + public RefPackage getDefaultPackage() { if (myDefaultPackage == null) { myDefaultPackage = getPackage(InspectionsBundle.message("inspection.reference.default.package")); @@ -269,6 +310,28 @@ public class RefJavaManagerImpl extends RefJavaManager { } } + @Override + public void onEntityInitialized(RefElement refElement, PsiElement psiElement) { + if (isEntryPoint(refElement)) { + getEntryPointsManager().addEntryPoint(refElement, false); + } + + if (psiElement instanceof PsiClass) { + PsiClass psiClass = (PsiClass)psiElement; + + EntryPointsManager entryPointsManager = getEntryPointsManager(); + if (psiClass.isAnnotationType()){ + entryPointsManager.addEntryPoint(refElement, false); + for (PsiMethod psiMethod : psiClass.getMethods()) { + entryPointsManager.addEntryPoint(myRefManager.getReference(psiMethod), false); + } + } + else if (psiClass.isEnum()) { + entryPointsManager.addEntryPoint(refElement, false); + } + } + } + private static void appendPackageElement(final Element element, final String packageName) { final Element packageElement = new Element("package"); packageElement.addContent(packageName.length() > 0 ? packageName : InspectionsBundle.message("inspection.export.results.default")); diff --git a/java/java-tests/testData/codeInsight/completion/smartType/SpaceAfterCommaInMethodCall-out.java b/java/java-tests/testData/codeInsight/completion/smartType/SpaceAfterCommaInMethodCall-out.java new file mode 100644 index 000000000000..0d32e7b34e77 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/SpaceAfterCommaInMethodCall-out.java @@ -0,0 +1,9 @@ +public static class G { + public static void foo(String s1, String s2) { + } + + public static void main(String[] args) { + String sss1 = "text"; + foo(sss1,); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/smartType/SpaceAfterCommaInMethodCall.java b/java/java-tests/testData/codeInsight/completion/smartType/SpaceAfterCommaInMethodCall.java new file mode 100644 index 000000000000..c6e05ffc2bbc --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/SpaceAfterCommaInMethodCall.java @@ -0,0 +1,9 @@ +public static class G { + public static void foo(String s1, String s2) { + } + + public static void main(String[] args) { + String sss1 = "text"; + foo(ss); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java index d0fcb5e33bdf..703406feddc6 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/CompletionStyleTest.java @@ -5,10 +5,11 @@ import com.intellij.codeInsight.lookup.Lookup; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupManager; import com.intellij.codeInsight.lookup.impl.LookupManagerImpl; +import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.pom.java.LanguageLevel; -import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; import com.intellij.psi.statistics.StatisticsManager; import com.intellij.psi.statistics.impl.StatisticsManagerImpl; import com.intellij.testFramework.LightCodeInsightTestCase; @@ -208,8 +209,9 @@ public class CompletionStyleTest extends LightCodeInsightTestCase{ } public void testParensInSynchronized() throws Exception{ - CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_SYNCHRONIZED_PARENTHESES = false; - CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_SYNCHRONIZED_PARENTHESES = true; + CommonCodeStyleSettings styleSettings = getCodeStyleSettings(); + styleSettings.SPACE_BEFORE_SYNCHRONIZED_PARENTHESES = false; + styleSettings.SPACE_WITHIN_SYNCHRONIZED_PARENTHESES = true; final String path = BASE_PATH; configureByFile(path + "/before22.java"); @@ -254,22 +256,17 @@ public class CompletionStyleTest extends LightCodeInsightTestCase{ public void testCastParensStyle1() throws Exception{ final String path = BASE_PATH; - CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject()); - final boolean space_within_cast_parentheses = styleSettings.SPACE_WITHIN_CAST_PARENTHESES; - final boolean space_after_type_cast = styleSettings.SPACE_AFTER_TYPE_CAST; - styleSettings.SPACE_WITHIN_CAST_PARENTHESES = true; - styleSettings.SPACE_AFTER_TYPE_CAST = false; + getCodeStyleSettings().SPACE_WITHIN_CAST_PARENTHESES = true; + getCodeStyleSettings().SPACE_AFTER_TYPE_CAST = false; configureByFile(path + "/before31.java"); performSmartCompletion(); checkResultByFile(path + "/after31.java"); - styleSettings.SPACE_WITHIN_CAST_PARENTHESES = space_within_cast_parentheses; - styleSettings.SPACE_AFTER_TYPE_CAST = space_after_type_cast; } public void testMethodParensStyle2() throws Exception{ final String path = BASE_PATH; - CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject()); + CommonCodeStyleSettings styleSettings = getCodeStyleSettings(); final boolean space_before_method_call_parentheses = styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES; styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true; configureByFile(path + "/before32.java"); @@ -278,9 +275,14 @@ public class CompletionStyleTest extends LightCodeInsightTestCase{ styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = space_before_method_call_parentheses; } + private static CommonCodeStyleSettings getCodeStyleSettings() { + return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE); + } + + public void testMethodParensStyle3() throws Exception{ final String path = BASE_PATH; - CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject()); + CommonCodeStyleSettings styleSettings = getCodeStyleSettings(); final boolean space_before_method_call_parentheses = styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES; final boolean space_within_method_call_parentheses = styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES; diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index 9327ae8ab7ed..6567b64cd193 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -22,11 +22,12 @@ import com.intellij.codeInsight.lookup.Lookup import com.intellij.codeInsight.lookup.LookupElement import com.intellij.codeInsight.lookup.LookupElementPresentation import com.intellij.codeInsight.lookup.LookupManager +import com.intellij.lang.java.JavaLanguage import com.intellij.openapi.actionSystem.IdeActions import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.fileTypes.StdFileTypes -import com.intellij.psi.codeStyle.CodeStyleSettings import com.intellij.psi.codeStyle.CodeStyleSettingsManager +import com.intellij.psi.codeStyle.CommonCodeStyleSettings import com.intellij.psi.* public class NormalCompletionTest extends LightFixtureCompletionTestCase { @@ -287,12 +288,9 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase { } public void testMethodCallBeforeAnotherStatementWithParen2() throws Exception { - CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings(); - boolean oldvalue = settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE; - settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true; + codeStyleSettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true; configureByFile("MethodLookup2.java"); checkResultByFile("MethodLookup2_After2.java"); - settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = oldvalue; } public void testSwitchEnumLabel() throws Exception { @@ -494,16 +492,14 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase { public void testPrivateInAnonymous() throws Throwable { doTest() } public void testMethodParenthesesSpaces() throws Throwable { - final settings = CodeStyleSettingsManager.getSettings(getProject()) - settings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true - settings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true + codeStyleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true + codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true doTest(); } public void testMethodParenthesesSpacesArgs() throws Throwable { - final settings = CodeStyleSettingsManager.getSettings(getProject()) - settings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true - settings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true + codeStyleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true + codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true doTest(); } @@ -601,23 +597,18 @@ public class ListUtils { } public void testNoSpaceInParensWithoutParams() throws Throwable { - CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = true; + codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true; try { doTest(); } finally { - CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = false; + codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = false; } } public void testTwoSpacesInParensWithParams() throws Throwable { - CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = true; - try { - doTest(); - } - finally { - CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = false; - } + codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true; + doTest(); } public void testFillCommonPrefixOnSecondCompletion() throws Throwable { @@ -1330,6 +1321,10 @@ public class ListUtils { public void testInterfaceImplementationNoCast() { doTest() } public void testStaticallyImportedMethodsBeforeExpression() { doTest() } + private CommonCodeStyleSettings getCodeStyleSettings() { + return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE); + } + public void testCompatibleInterfacesCast() { configure() assert myFixture.lookupElementStrings.containsAll(['foo', 'bar']) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java index 408c85d3bbe3..48510cd073ac 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java @@ -12,10 +12,12 @@ import com.intellij.codeInsight.template.TemplateContextType; import com.intellij.codeInsight.template.TemplateManager; import com.intellij.codeInsight.template.impl.TemplateImpl; import com.intellij.codeInsight.template.impl.TemplateSettings; +import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.util.Condition; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; import com.intellij.util.containers.ContainerUtil; public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { @@ -92,15 +94,9 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { public void testParenAfterCall1_SpaceWithinMethodCallParens() throws Exception { String path = "/parenAfterCall"; - CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject()); myFixture.configureByFile(path + "/before1.java"); - styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true; - try{ - complete(); - } - finally{ - styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = false; - } + getCodeStyleSettings().SPACE_WITHIN_METHOD_CALL_PARENTHESES = true; + complete(); checkResultByFile(path + "/after1_space.java"); } @@ -659,14 +655,8 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { public void testUseIntConstantsInOr() throws Throwable { doTest(); } public void testExtraSemicolonAfterMethodParam() throws Throwable { - CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject()); - styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true; - try{ - doTest(); - } - finally{ - styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = false; - } + getCodeStyleSettings().SPACE_WITHIN_METHOD_CALL_PARENTHESES = true; + doTest(); } public void testAssignFromTheSameFieldOfAnotherObject() throws Throwable { @@ -1132,7 +1122,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { doTest(Lookup.NORMAL_SELECT_CHAR); } - private void doTest(final char c) throws Exception { + private void doTest(final char c) { boolean old = CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION; if (c != Lookup.NORMAL_SELECT_CHAR) { CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = false; @@ -1173,4 +1163,12 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { } } + public void testSpaceAfterCommaInMethodCall() { + getCodeStyleSettings().SPACE_AFTER_COMMA = false; + doTest(','); + } + + private CommonCodeStyleSettings getCodeStyleSettings() { + return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE); + } } diff --git a/platform/bootstrap/src/com/intellij/idea/Main.java b/platform/bootstrap/src/com/intellij/idea/Main.java index 69d9c6648b5a..47ab44e99cda 100644 --- a/platform/bootstrap/src/com/intellij/idea/Main.java +++ b/platform/bootstrap/src/com/intellij/idea/Main.java @@ -20,12 +20,16 @@ import com.intellij.ide.Bootstrap; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.io.StreamUtil; import com.intellij.util.Restarter; import org.jetbrains.annotations.NonNls; import javax.swing.*; import java.awt.*; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -46,39 +50,30 @@ public class Main { System.setProperty("jna.nounpack", "false"); } - // pre-load class before installing the patch to prevent class loader problems - Restarter.isSupported(); + final int[] restartCode = {Restarter.getRestartCode()}; - if (installPatch()) { - boolean restarted = false; - int restartCode = 0; - try { - restarted = Restarter.restart(); - restartCode = Restarter.getRestartCode(); + Runnable restart = new Runnable() { + @Override + public void run() { + if (restartCode[0] == 0) { + try { + if (Restarter.restart()) restartCode[0] = 1; + } + catch (Throwable ignore) { + } + } } - catch (Throwable e) { - // can be either CannotRestartException - // or something like class/method not found if they has been changed during update + }; - //noinspection CallToPrintStackTrace - e.printStackTrace(); - } + if (installPatch(restart)) { + if (restartCode[0] == 0) { + try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Throwable ignore) { } - if (!restarted && restartCode == 0) { - try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ignore) { } - String msg = "The application cannot start right away since some critical files have been changed.\nPlease restart it manually."; + String msg = "Patch has been applied successfully, please restart application."; JOptionPane.showMessageDialog(null, msg, "Update", JOptionPane.INFORMATION_MESSAGE); } - final int finalRestartCode = restartCode; - //noinspection SSBasedInspection - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - System.exit(finalRestartCode); - } - }); - + System.exit(restartCode[0]); return; } @@ -124,7 +119,7 @@ public class Main { return isHeadless; } - private static boolean installPatch() { + private static boolean installPatch(Runnable restart) { try { File ideaHomeDir = getIdeaHomeDir(); if (ideaHomeDir == null) return false; @@ -141,10 +136,12 @@ public class Main { File launcherFile = new File(ideaHomeDir, "bin/vistalauncher.exe"); File launcherCopy = FileUtil.createTempFile("vistalauncher", ".exe"); launcherCopy.deleteOnExit(); - copyFile(launcherFile, launcherCopy); + FileUtil.copy(launcherFile, launcherCopy); args.add(launcherCopy.getPath()); } + restart.run(); + Collections.addAll(args, System.getProperty("java.home") + "/bin/java", "-classpath", @@ -160,13 +157,14 @@ public class Main { errThread.start(); try { - boolean requiresRestart = process.waitFor() == 42; - return requiresRestart; + process.waitFor(); } finally { outThread.join(); errThread.join(); } + + return true; } finally { patchFile.delete(); @@ -189,7 +187,7 @@ public class Main { public void run() { try { - copyStream(myIn, myOut); + StreamUtil.copyStreamContent(myIn, myOut); } catch (IOException e) { e.printStackTrace(); @@ -217,44 +215,4 @@ public class Main { return null; } } - - public static void copyFile(File from, File to) throws IOException { - to.getParentFile().mkdirs(); - - FileInputStream is = null; - FileOutputStream os = null; - try { - is = new FileInputStream(from); - os = new FileOutputStream(to); - - copyStream(is, os); - } - finally { - if (is != null) { - try { - is.close(); - } - catch (IOException e) { - e.printStackTrace(); - } - } - if (os != null) { - try { - os.close(); - } - catch (IOException e) { - e.printStackTrace(); - } - } - } - } - - public static void copyStream(InputStream from, OutputStream to) throws IOException { - byte[] buffer = new byte[65536]; - while (true) { - int read = from.read(buffer); - if (read < 0) break; - to.write(buffer, 0, read); - } - } } diff --git a/platform/lang-api/src/com/intellij/codeInsight/TailType.java b/platform/lang-api/src/com/intellij/codeInsight/TailType.java index a4b31b7eb817..a82827c20b9f 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/TailType.java +++ b/platform/lang-api/src/com/intellij/codeInsight/TailType.java @@ -16,11 +16,16 @@ package com.intellij.codeInsight; import com.intellij.codeInsight.completion.InsertionContext; +import com.intellij.lang.Language; import com.intellij.openapi.editor.CaretModel; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; -import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDocumentManager; +import com.intellij.psi.PsiFile; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; +import com.intellij.psi.util.PsiUtilBase; import org.jetbrains.annotations.NotNull; /** @@ -72,11 +77,11 @@ public abstract class TailType { }; public static final TailType SEMICOLON = new CharTailType(';'); - public static final TailType EXCLAMATION = new CharTailType('!'); + @Deprecated public static final TailType EXCLAMATION = new CharTailType('!'); public static final TailType COMMA = new TailType(){ public int processTail(final Editor editor, int tailOffset) { - CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(editor.getProject()); + CommonCodeStyleSettings styleSettings = getLocalCodeStyleSettings(editor, tailOffset); if (styleSettings.SPACE_BEFORE_COMMA) tailOffset = insertChar(editor, tailOffset, ' '); tailOffset = insertChar(editor, tailOffset, ','); if (styleSettings.SPACE_AFTER_COMMA) tailOffset = insertChar(editor, tailOffset, ' '); @@ -87,6 +92,17 @@ public abstract class TailType { return "COMMA"; } }; + + protected static CommonCodeStyleSettings getLocalCodeStyleSettings(Editor editor, int tailOffset) { + Project project = editor.getProject(); + assert project != null; + PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); + assert psiFile != null; + Language language = PsiUtilBase.getLanguageAtOffset(psiFile, tailOffset); + + return CodeStyleSettingsManager.getSettings(project).getCommonSettings(language); + } + /** * insert a space, overtype if already present */ diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/InsertionContext.java b/platform/lang-api/src/com/intellij/codeInsight/completion/InsertionContext.java index 1a793de71178..f75085af3ec2 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/InsertionContext.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/InsertionContext.java @@ -16,11 +16,15 @@ package com.intellij.codeInsight.completion; import com.intellij.codeInsight.lookup.LookupElement; +import com.intellij.lang.Language; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; +import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; +import com.intellij.psi.util.PsiUtilBase; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -132,4 +136,9 @@ public class InsertionContext { public boolean shouldAddCompletionChar() { return myAddCompletionChar; } + + public CommonCodeStyleSettings getCodeStyleSettings() { + Language lang = PsiUtilBase.getLanguageAtOffset(getFile(), getTailOffset()); + return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(lang); + } } diff --git a/platform/lang-api/src/com/intellij/codeInspection/LocalDummyInspectionTool.java b/platform/lang-api/src/com/intellij/codeInspection/DummyInspectionTool.java similarity index 77% rename from platform/lang-api/src/com/intellij/codeInspection/LocalDummyInspectionTool.java rename to platform/lang-api/src/com/intellij/codeInspection/DummyInspectionTool.java index 6a879de0be24..4772a6d60aae 100644 --- a/platform/lang-api/src/com/intellij/codeInspection/LocalDummyInspectionTool.java +++ b/platform/lang-api/src/com/intellij/codeInspection/DummyInspectionTool.java @@ -18,13 +18,13 @@ package com.intellij.codeInspection; import org.jetbrains.annotations.NotNull; /** - * This class is for the inspections that are gathered by another inspection, + * This interface is for the inspections that are gathered by another inspection, * but should be shown under this inspection in the inspections result view. * This inspection is identified by the problem group, which is stored in the Annotation, HighlightInfo and ProblemDescriptor classes. */ -public abstract class LocalDummyInspectionTool extends LocalInspectionTool { +public interface DummyInspectionTool { @NotNull - public abstract String getProblemGroup(); + String getProblemGroup(); - public abstract boolean shouldBeShownInInspectionProfile(); + boolean shouldBeShownInInspectionProfile(); } diff --git a/platform/lang-api/src/com/intellij/codeInspection/lang/RefManagerExtension.java b/platform/lang-api/src/com/intellij/codeInspection/lang/RefManagerExtension.java index d3ffe275ab6b..d6c267251bf2 100644 --- a/platform/lang-api/src/com/intellij/codeInspection/lang/RefManagerExtension.java +++ b/platform/lang-api/src/com/intellij/codeInspection/lang/RefManagerExtension.java @@ -59,4 +59,6 @@ public interface RefManagerExtension { boolean belongsToScope(final PsiElement psiElement); void export(final RefEntity refEntity, final Element element); -} \ No newline at end of file + + void onEntityInitialized(RefElement refEntity, PsiElement psiElement); +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/EmacsStyleIndentAction.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/EmacsStyleIndentAction.java index 7121fcbcf80e..bf5e65ae1eef 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/EmacsStyleIndentAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/EmacsStyleIndentAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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,7 @@ public class EmacsStyleIndentAction extends BaseCodeInsightAction implements Dum final int newPos = codeStyleManager.adjustLineIndent(file, lineStart); final int newCol = newPos - lineStart; final int lineInc = document.getLineEndOffset(line) - initLineEnd; - if (newCol >= col + lineInc) { + if (newCol >= col + lineInc && newCol >= 0) { final LogicalPosition pos = new LogicalPosition(line, newCol); editor.getCaretModel().moveToLogicalPosition(pos); editor.getSelectionModel().removeSelection(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/AbstractElementSignatureProvider.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/AbstractElementSignatureProvider.java index 3e67a2641213..90abde67a1f7 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/AbstractElementSignatureProvider.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/AbstractElementSignatureProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -36,7 +36,7 @@ public abstract class AbstractElementSignatureProvider implements ElementSignatu @Nullable public PsiElement restoreBySignature(@NotNull PsiFile file, @NotNull String signature, @Nullable StringBuilder processingInfoStorage) { - int semicolonIndex = signature.indexOf(';'); + int semicolonIndex = signature.indexOf(ELEMENTS_SEPARATOR); PsiElement parent; if (semicolonIndex >= 0) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CollapseSelectionHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CollapseSelectionHandler.java index fcf6e1cf7361..91987bde987d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CollapseSelectionHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/CollapseSelectionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -42,6 +42,9 @@ public class CollapseSelectionHandler implements CodeInsightActionHandler { if (editor.getSelectionModel().hasSelection()) { int start = editor.getSelectionModel().getSelectionStart(); int end = editor.getSelectionModel().getSelectionEnd(); + if (start + 1 >= end) { + return; + } Document doc = editor.getDocument(); if (start < end && doc.getCharsSequence().charAt(end-1) == '\n') end--; FoldRegion region; @@ -52,7 +55,7 @@ public class CollapseSelectionHandler implements CodeInsightActionHandler { } } else if (!foldingModel.intersectsRegion(start, end)) { region = foldingModel.addFoldRegion(start, end, ourPlaceHolderText); - LOG.assertTrue(region != null); + LOG.assertTrue(region != null, "Fold region is not created. Folding model: " + foldingModel); region.setExpanded(false); int offset = Math.min(start + ourPlaceHolderText.length(), doc.getTextLength()); editor.getCaretModel().moveToOffset(offset); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/OffsetsElementSignatureProvider.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/OffsetsElementSignatureProvider.java index 0e328c0d32b6..f1e78494c8a7 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/OffsetsElementSignatureProvider.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/OffsetsElementSignatureProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -79,10 +79,21 @@ public class OffsetsElementSignatureProvider extends AbstractElementSignaturePro PsiElement element = file.findElementAt(start); if (element != null) { result = findElement(start, end, index, element, processingInfoStorage); + if (result == null && processingInfoStorage != null) { + processingInfoStorage.append(String.format( + "Failed to find an element by the given offsets. Started by the element '%s' (%s)", element, element.getText() + )); + } } if (result == null) { final PsiElement injectedStartElement = InjectedLanguageUtil.findElementAtNoCommit(file, start); + if (processingInfoStorage != null) { + processingInfoStorage.append(String.format( + "Trying to find injected element starting from the '%s'%s%n", + injectedStartElement, injectedStartElement == null ? "" : String.format("(%s)", injectedStartElement.getText()) + )); + } if (injectedStartElement != null && injectedStartElement != element) { result = findElement(start, end, index, injectedStartElement, processingInfoStorage); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/PsiNamesElementSignatureProvider.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/PsiNamesElementSignatureProvider.java index 3cd125049963..ebde922ddaa5 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/PsiNamesElementSignatureProvider.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/PsiNamesElementSignatureProvider.java @@ -15,6 +15,7 @@ */ package com.intellij.codeInsight.folding.impl; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -67,7 +68,7 @@ public class PsiNamesElementSignatureProvider extends AbstractElementSignaturePr else { if (processingInfoStorage != null) { processingInfoStorage.append(String.format( - "Stopping '%s' provider because it has top level marker but more than one non white-space child: %s", + "Stopping '%s' provider because it has top level marker but more than one non white-space child: %s%n", getClass().getName(), Arrays.toString(file.getChildren()) )); } @@ -77,7 +78,7 @@ public class PsiNamesElementSignatureProvider extends AbstractElementSignaturePr } if (processingInfoStorage != null) { processingInfoStorage.append(String.format( - "Finished processing of '%s' provider because all of its top-level children have been processed: %s", + "Finished processing of '%s' provider because all of its top-level children have been processed: %s%n", getClass().getName(), Arrays.toString(file.getChildren()) )); } @@ -99,10 +100,17 @@ public class PsiNamesElementSignatureProvider extends AbstractElementSignaturePr } if (!tokenizer.hasMoreTokens()) { + if (processingInfoStorage != null) { + processingInfoStorage.append(String.format("Stopping '%s' provider because it has no more data to process%n", getClass().getName())); + } return null; } try { int index = Integer.parseInt(tokenizer.nextToken()); + if (processingInfoStorage != null) { + processingInfoStorage.append(String.format("Looking for the child with a name '%s' # %d at the element '%s'%n", + elementMarker, index, parent)); + } return restoreElementInternal(parent, elementMarker, index, PsiNamedElement.class); } catch (NumberFormatException e) { @@ -172,7 +180,7 @@ public class PsiNamesElementSignatureProvider extends AbstractElementSignaturePr if (element instanceof PsiNamedElement) { PsiNamedElement named = (PsiNamedElement)element; final String name = named.getName(); - if (name == null) { + if (StringUtil.isEmpty(name)) { return null; } int index = getChildIndex(named, element.getParent(), name, (Class)named.getClass()); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java index 3ad2f94584a3..a88aca1d01c9 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -18,6 +18,7 @@ package com.intellij.codeInsight.folding.impl; import com.intellij.lang.folding.FoldingDescriptor; import com.intellij.lang.injection.InjectedLanguageManager; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.FoldRegion; import com.intellij.openapi.editor.FoldingGroup; @@ -41,6 +42,9 @@ import static com.intellij.util.containers.CollectionFactory.newTroveMap; * @author cdr */ class UpdateFoldRegionsOperation implements Runnable { + + private static final Logger LOG = Logger.getInstance("#" + UpdateFoldRegionsOperation.class.getName()); + private final Project myProject; private final Editor myEditor; private final PsiFile myFile; @@ -104,6 +108,11 @@ class UpdateFoldRegionsOperation implements Runnable { FoldingGroup group = descriptor.getGroup(); TextRange range = descriptor.getRange(); String placeholder = descriptor.getPlaceholderText(); + if (range.getEndOffset() > myEditor.getDocument().getTextLength()) { + LOG.error(String.format("Invalid folding descriptor detected (%s). It ends beyond the document range (%d)", + descriptor, myEditor.getDocument().getTextLength())); + continue; + } FoldRegion region = foldingModel.createFoldRegion(range.getStartOffset(), range.getEndOffset(), placeholder == null ? "..." : placeholder, group, diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/CompletionExtender.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/CompletionExtender.java new file mode 100644 index 000000000000..3ff721a98175 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/CompletionExtender.java @@ -0,0 +1,83 @@ +/* + * Copyright 2000-2012 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.codeInsight.lookup.impl; + +import com.intellij.codeInsight.lookup.LookupElement; +import com.intellij.ui.HeavyweightHint; +import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.awt.*; + +/** + * @author Konstantin Bulenkov + */ +public class CompletionExtender extends HeavyweightHint { + private LookupElement myElement; + private LookupImpl myLookup; + private int myIndex; + + public CompletionExtender(@NotNull LookupElement element, @NotNull LookupImpl lookup) { + super(createComponent(element, lookup), false); + myElement = element; + myLookup = lookup; + myIndex = myLookup.getList().getSelectedIndex(); + } + + public LookupElement getLookupElement() { + return myElement; + } + + public boolean sameAsFor(LookupElement item) { + return getLookupElement().equals(item) + && myIndex == myLookup.getList().getSelectedIndex(); + } + + private static JComponent createComponent(LookupElement element, LookupImpl lookup) { + final LookupCellRenderer renderer = new LookupCellRenderer(lookup); + renderer.setFullSize(true); + final JComponent component = (JComponent)renderer.getListCellRendererComponent(lookup.getList(), element, + lookup.getList().getSelectedIndex(), + true, false); + component.setSize(component.getPreferredSize()); + return component; + } + + public boolean show() { + final JList list = myLookup.getList(); + if (getComponent().getWidth() > list.getWidth()) { + final JComponent rootPane = UIUtil.getRootPane(myLookup.getEditor().getContentComponent()); + + final Point p = list.getLocationOnScreen(); + p.y += list.indexToLocation(list.getSelectedIndex()).y; + SwingUtilities.convertPointFromScreen(p, rootPane); + + if (rootPane != null) { + show(rootPane, p); + return true; + } + } + return false; + } + + @Override + public void hide() { + super.hide(); + myLookup = null; + myElement = null; + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index b11b7ef36300..a7c31b5a67dc 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -95,7 +95,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable private final Project myProject; private final Editor myEditor; - private Hint tip; + private CompletionExtender extender; private String myInitialPrefix; private boolean myStableStart; @@ -1029,10 +1029,6 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable public void valueChanged(ListSelectionEvent e){ myHintAlarm.cancelAllRequests(); - if (tip != null && tip.isVisible()) { - tip.hide(); - } - final LookupElement item = getCurrentItem(); if (oldItem != item) { mySelectionInvariant = item == null ? null : myPresentableModel.getItemPresentationInvariant(item); @@ -1043,26 +1039,18 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable } if (item != null) { updateHint(item); - if (myList.getModel().getSize() > 1 && isVisible()) { - final LookupCellRenderer renderer = new LookupCellRenderer(LookupImpl.this); - renderer.setFullSize(true); - final JComponent component = (JComponent)renderer.getListCellRendererComponent(myList, item, - myList - .getSelectedIndex(), - true, false); - component.setSize(component.getPreferredSize()); - if (component.getWidth() > myList.getWidth()) { - tip = new HeavyweightHint(component, false); - final Point p = myList.getLocationOnScreen(); - p.y += myList.indexToLocation(myList.getSelectedIndex()).y; + } + oldItem = item; - final JComponent editor = UIUtil.getRootPane(myEditor.getContentComponent()); - SwingUtilities.convertPointFromScreen(p, editor); - tip.show(editor, p.x, p.y, null, new HintHint(editor, p)); + if (item != null && LookupImpl.this.isVisible()) { + if (extender == null || !extender.isVisible() || !extender.sameAsFor(item)) { + if (extender != null) extender.hide(); + extender = new CompletionExtender(item, LookupImpl.this); + if (!extender.show()) { + extender.hide(); } } } - oldItem = item; } }); @@ -1390,8 +1378,8 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable } Disposer.dispose(myProcessIcon); Disposer.dispose(myHintAlarm); - if (tip != null) { - tip.hide(); + if (extender != null) { + extender.hide(); } myDisposed = true; disposeTrace = DebugUtil.currentStackTrace() + "\n============"; diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/Descriptor.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/Descriptor.java index 49de7ada2039..34a1821b872f 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/Descriptor.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/Descriptor.java @@ -18,8 +18,8 @@ package com.intellij.codeInspection.ex; import com.intellij.codeHighlighting.HighlightDisplayLevel; import com.intellij.codeInsight.daemon.HighlightDisplayKey; +import com.intellij.codeInspection.DummyInspectionTool; import com.intellij.codeInspection.InspectionProfileEntry; -import com.intellij.codeInspection.LocalDummyInspectionTool; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.WriteExternalException; import com.intellij.psi.search.scope.packageSet.NamedScope; @@ -62,8 +62,8 @@ public class Descriptor { if (tool instanceof InspectionToolWrapper) { InspectionProfileEntry inspection = ((InspectionToolWrapper)tool).getTool(); - if (inspection instanceof LocalDummyInspectionTool) { - myShouldBeShown = ((LocalDummyInspectionTool)inspection).shouldBeShownInInspectionProfile(); + if (inspection instanceof DummyInspectionTool) { + myShouldBeShown = ((DummyInspectionTool)inspection).shouldBeShownInInspectionProfile(); } } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java index 61633adec49c..872844b78bbf 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java @@ -354,7 +354,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G public boolean isToCheckFile(PsiFile file, final InspectionProfileEntry tool) { final Tools tools = myTools.get(tool.getShortName()); - if (tools != null) { + if (tools != null && file != null) { for (ScopeToolState state : tools.getTools()) { final NamedScope namedScope = state.getScope(file.getProject()); if (namedScope == null || namedScope.getValue().contains(file, getCurrentProfile().getProfileManager().getScopesManager())) { @@ -636,12 +636,12 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G InspectionToolWrapper toolWrapper = (InspectionToolWrapper)profileEntry; InspectionProfileEntry inspectionTool = toolWrapper.getTool(); - if (inspectionTool instanceof LocalDummyInspectionTool) { + if (inspectionTool instanceof DummyInspectionTool) { if (toolWrappers == null) { toolWrappers = new HashMap(); } - toolWrappers.put(((LocalDummyInspectionTool)inspectionTool).getProblemGroup(), toolWrapper); + toolWrappers.put(((DummyInspectionTool)inspectionTool).getProblemGroup(), toolWrapper); } } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/reference/RefManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/reference/RefManagerImpl.java index 237013f22e76..4595a49ad352 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/reference/RefManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/reference/RefManagerImpl.java @@ -99,6 +99,10 @@ public class RefManagerImpl extends RefManager { } } + public GlobalInspectionContextImpl getContext() { + return myContext; + } + public void iterate(RefVisitor visitor) { myLock.readLock().lock(); try { @@ -440,6 +444,9 @@ public class RefManagerImpl extends RefManager { ApplicationManager.getApplication().runReadAction(new Runnable() { public void run() { refElement.initialize(); + for (RefManagerExtension extension : myExtensions.values()) { + extension.onEntityInitialized(refElement, elem); + } } }); diff --git a/platform/lang-impl/src/com/intellij/psi/formatter/FormattingDocumentModelImpl.java b/platform/lang-impl/src/com/intellij/psi/formatter/FormattingDocumentModelImpl.java index bd39d8877d5f..c177b80b5dee 100644 --- a/platform/lang-impl/src/com/intellij/psi/formatter/FormattingDocumentModelImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/formatter/FormattingDocumentModelImpl.java @@ -84,7 +84,10 @@ public class FormattingDocumentModelImpl implements FormattingDocumentModel { @Override public int getLineNumber(int offset) { - LOG.assertTrue (offset <= myDocument.getTextLength()); + if (offset > myDocument.getTextLength()) { + LOG.error(String.format("Invalid offset detected (%d). Document length: %d. Target file: %s", + offset, myDocument.getTextLength(), myFile)); + } return myDocument.getLineNumber(offset); } diff --git a/platform/platform-api/src/com/intellij/openapi/startup/StartupActivity.java b/platform/platform-api/src/com/intellij/openapi/startup/StartupActivity.java index 4358e1d7878b..3be4959393fe 100644 --- a/platform/platform-api/src/com/intellij/openapi/startup/StartupActivity.java +++ b/platform/platform-api/src/com/intellij/openapi/startup/StartupActivity.java @@ -20,6 +20,8 @@ import com.intellij.openapi.project.Project; /** * @author Dmitry Avdeev + * + * This may implement {@link com.intellij.openapi.project.DumbAware}. */ public interface StartupActivity { diff --git a/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java b/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java index 079b1f756c50..a34ab39eb415 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/Switcher.java @@ -275,8 +275,8 @@ public class Switcher extends AnAction implements DumbAware { toolWindows.addMouseMotionListener(this); toolWindows.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { - if (!toolWindows.getSelectionModel().isSelectionEmpty()) { - files.getSelectionModel().clearSelection(); + if (!toolWindows.isSelectionEmpty() && !files.isSelectionEmpty()) { + files.clearSelection(); } } }); @@ -411,7 +411,7 @@ public class Switcher extends AnAction implements DumbAware { files.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); files.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { - if (!files.getSelectionModel().isSelectionEmpty()) { + if (!files.isSelectionEmpty() && !toolWindows.isSelectionEmpty()) { toolWindows.getSelectionModel().clearSelection(); } } @@ -693,12 +693,20 @@ public class Switcher extends AnAction implements DumbAware { } public JList getSelectedList() { + return getSelectedList(files); + } + + JList getSelectedList(JList preferable) { if (toolWindows.isSelectionEmpty() && files.isSelectionEmpty()) { - if (files.getModel().getSize() > 1) { + if (preferable != null && preferable.getModel().getSize() > 0) { + preferable.setSelectedIndex(0); + return preferable; + } else + + if (files.getModel().getSize() > 0) { files.setSelectedIndex(0); return files; - } - else { + } else { toolWindows.setSelectedIndex(0); return toolWindows; } @@ -709,8 +717,8 @@ public class Switcher extends AnAction implements DumbAware { } void navigate() { - myPopup.closeOk(null); final Object value = getSelectedList().getSelectedValue(); + myPopup.closeOk(null); if (value instanceof ToolWindow) { ((ToolWindow)value).activate(null, true, true); } @@ -847,21 +855,23 @@ public class Switcher extends AnAction implements DumbAware { @Override protected void selectElement(Object element, String selectedText) { if (element instanceof FileInfo) { - toolWindows.getSelectionModel().clearSelection(); + if (!toolWindows.isSelectionEmpty()) toolWindows.clearSelection(); files.setSelectedValue(element, false); } else { - files.clearSelection(); + if (!files.isSelectionEmpty()) files.clearSelection(); toolWindows.setSelectedValue(element, false); } } @Override public void propertyChange(PropertyChangeEvent evt) { + final JList list = getSelectedList(); + final Object value = list.getSelectedValue(); ((NameFilteringListModel)files.getModel()).refilter(); ((NameFilteringListModel)toolWindows.getModel()).refilter(); files.repaint(); toolWindows.repaint(); - getSelectedList(); + getSelectedList(list).setSelectedValue(value, true); } } 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 d0baa08ef94f..4cf9d1dfc587 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 @@ -141,12 +141,14 @@ public class EditorUtil { editorInfo = ((EditorImpl)editor).dumpState(); } else { - editorInfo = "all soft wraps: " + editor.getSoftWrapModel().getSoftWrapsForRange(0, document.getTextLength()) - + ", fold regions: " + Arrays.toString(editor.getFoldingModel().getAllFoldRegions()); + editorInfo = "editor's class: " + editor.getClass() + + ", all soft wraps: " + editor.getSoftWrapModel().getSoftWrapsForRange(0, document.getTextLength()) + + ", fold regions: " + Arrays.toString(editor.getFoldingModel().getAllFoldRegions()); } - LOG.error(String.format( + LogMessageEx.error(LOG, "Can't calculate last visual column", String.format( "Target visual line: %d, mapped logical line: %d, visual lines range for the mapped logical line: [%s]-[%s], soft wraps for " - + "the target logical line: %s. Editor info: %s", line, resultLogLine, resVisStart, resVisEnd, softWraps, editorInfo + + "the target logical line: %s. Editor info: %s", + line, resultLogLine, resVisStart, resVisEnd, softWraps, editorInfo )); return resVisEnd.column; diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java index 2cdabfa5e067..7550c73112b6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java @@ -117,7 +117,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, public void updateFinished(@NotNull Document doc) { if (doc != myEditor.getDocument() || myIsInUpdate) return; if (savedBeforeBulkCaretMarker != null && savedBeforeBulkCaretMarker.isValid() - && savedBeforeBulkCaretMarker.getStartOffset() != myOffset) + && savedBeforeBulkCaretMarker.getStartOffset() != myOffset && !myReportCaretMoves) { moveToOffset(savedBeforeBulkCaretMarker.getStartOffset()); } diff --git a/platform/platform-impl/src/com/intellij/ui/HeavyweightHint.java b/platform/platform-impl/src/com/intellij/ui/HeavyweightHint.java index 374c3fa89a0c..ec886b60103c 100644 --- a/platform/platform-impl/src/com/intellij/ui/HeavyweightHint.java +++ b/platform/platform-impl/src/com/intellij/ui/HeavyweightHint.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -19,6 +19,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.wm.ex.WindowManagerEx; import com.intellij.ui.awt.RelativePoint; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.EventListenerList; @@ -45,7 +46,11 @@ public class HeavyweightHint implements Hint { /** * Shows the hint as the window */ - public void show(@NotNull JComponent parentComponent, int x, int y, JComponent focusBackComponent, @NotNull HintHint hintInfo) { + public void show(@NotNull JComponent parentComponent, int x, int y, @Nullable JComponent focusBackComponent, @Nullable HintHint hintInfo) { + show(parentComponent, new Point(x, y)); + } + + public void show(@NotNull JComponent parentComponent, Point p) { myParentComponent = parentComponent; LOG.assertTrue(parentComponent.isShowing()); @@ -59,10 +64,12 @@ public class HeavyweightHint implements Hint { myWindow.getContentPane().setLayout(new BorderLayout()); myWindow.getContentPane().add(myComponent, BorderLayout.CENTER); - updateBounds(x, y); + updateBounds(p.x, p.y); myWindow.setVisible(true); } + + protected void fireHintHidden() { final EventListener[] listeners = myListenerList.getListeners(HintListener.class); for (EventListener listener1 : listeners) { diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.java index 533f55ef7733..a7fe91bc4b37 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/FileWatcherTest.java @@ -368,9 +368,10 @@ public class FileWatcherTest extends PlatformLangTestCase { } } finally { - VirtualDirectoryImpl.disallowRootAccess(substRoot); delete(targetDir); new GeneralCommandLine("subst", subst + ":", "/d").createProcess().waitFor(); + myFileSystem.refresh(false); + VirtualDirectoryImpl.disallowRootAccess(substRoot); } } diff --git a/platform/util/src/com/intellij/util/Restarter.java b/platform/util/src/com/intellij/util/Restarter.java index 423d1eb7c872..6b0b087a6f23 100644 --- a/platform/util/src/com/intellij/util/Restarter.java +++ b/platform/util/src/com/intellij/util/Restarter.java @@ -17,6 +17,7 @@ package com.intellij.util; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.io.FileUtil; import com.sun.jna.Native; import com.sun.jna.WString; import com.sun.jna.win32.StdCallLibrary; @@ -68,7 +69,13 @@ public class Restarter { int pid = kernel32.GetCurrentProcessId(); try { - String command = "restarter " + Integer.toString(pid) + " " + cline; + // to prevent blocking exe file during update we should copy it + File restarterFile = new File(PathManager.getBinPath(), "restarter.exe"); + File restarterCopy = FileUtil.createTempFile("restarter", ".exe"); + + FileUtil.copy(restarterFile, restarterCopy); + + String command = "\"" + restarterCopy + "\" " + Integer.toString(pid) + " " + cline; Runtime.getRuntime().exec(command, null, new File(PathManager.getBinPath())); } catch (IOException ex) { diff --git a/platform/vcs-api/src/com/intellij/util/ui/VcsBackgroundTask.java b/platform/vcs-api/src/com/intellij/util/ui/VcsBackgroundTask.java index 06cc1a094892..e8542ab37f95 100644 --- a/platform/vcs-api/src/com/intellij/util/ui/VcsBackgroundTask.java +++ b/platform/vcs-api/src/com/intellij/util/ui/VcsBackgroundTask.java @@ -36,11 +36,16 @@ public abstract class VcsBackgroundTask extends Task.ConditionalModal { private final List myExceptions = new ArrayList(); public VcsBackgroundTask(final Project project, @NotNull final String title, @NotNull final PerformInBackgroundOption backgroundOption, - final Collection itemsToProcess) { - super(project, title, false, backgroundOption); + final Collection itemsToProcess, final boolean canBeCanceled) { + super(project, title, canBeCanceled, backgroundOption); myItems = itemsToProcess; } + public VcsBackgroundTask(final Project project, @NotNull final String title, @NotNull final PerformInBackgroundOption backgroundOption, + final Collection itemsToProcess) { + this(project, title, backgroundOption, itemsToProcess, false); + } + public void run(@NotNull ProgressIndicator indicator) { for(T item: myItems) { try { diff --git a/platform/vcs-impl/src/com/intellij/util/ui/VcsBackgroundTaskWithLocalHistory.java b/platform/vcs-impl/src/com/intellij/util/ui/VcsBackgroundTaskWithLocalHistory.java new file mode 100644 index 000000000000..ab2bcb5da8d4 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/util/ui/VcsBackgroundTaskWithLocalHistory.java @@ -0,0 +1,67 @@ +/* + * Copyright 2000-2012 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.util.ui; + +import com.intellij.history.LocalHistory; +import com.intellij.history.LocalHistoryAction; +import com.intellij.openapi.progress.PerformInBackgroundOption; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vcs.VcsException; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; + +/** + * Created with IntelliJ IDEA. + * User: Irina.Chernushina + * Date: 4/13/12 + * Time: 1:59 PM + */ +public abstract class VcsBackgroundTaskWithLocalHistory extends VcsBackgroundTask { + private final String myActionName; + + protected VcsBackgroundTaskWithLocalHistory(Project project, + @NotNull String title, + @NotNull PerformInBackgroundOption backgroundOption, + Collection itemsToProcess, + String actionName) { + super(project, title, backgroundOption, itemsToProcess); + myActionName = actionName; + } + + protected VcsBackgroundTaskWithLocalHistory(Project project, + @NotNull String title, + @NotNull PerformInBackgroundOption backgroundOption, + Collection itemsToProcess, + boolean canBeCanceled, String actionName) { + super(project, title, backgroundOption, itemsToProcess, canBeCanceled); + myActionName = actionName; + } + + @Override + public void run(@NotNull ProgressIndicator indicator) { + LocalHistoryAction action = LocalHistoryAction.NULL; + if (myActionName != null) { + action = LocalHistory.getInstance().startAction(myActionName); + } + try { + super.run(indicator); + } finally { + action.finish(); + } + } +} diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java index b293f37a3829..f7a0e4666fd6 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java @@ -17,6 +17,7 @@ package com.intellij.android.designer.model; import com.android.ide.common.rendering.api.ViewInfo; import com.intellij.designer.model.RadComponent; +import com.intellij.designer.model.RadVisualComponent; import com.intellij.designer.propertyTable.Property; import com.intellij.openapi.application.ApplicationManager; import com.intellij.psi.xml.XmlAttribute; @@ -24,20 +25,15 @@ import com.intellij.psi.xml.XmlTag; import com.intellij.util.containers.hash.HashMap; import org.jdom.Element; -import javax.swing.*; import java.awt.*; -import java.util.ArrayList; import java.util.List; import java.util.Map; /** * @author Alexander Lobas */ -public class RadViewComponent extends RadComponent { - private final List myChildren = new ArrayList(); +public class RadViewComponent extends RadVisualComponent { protected ViewInfo myViewInfo; - private Component myNativeComponent; - private final Rectangle myBounds = new Rectangle(); private Rectangle myMargins; private XmlTag myTag; private List myProperties; @@ -50,11 +46,6 @@ public class RadViewComponent extends RadComponent { myTag = tag; } - @Override - public List getChildren() { - return myChildren; - } - public ViewInfo getViewInfo() { return myViewInfo; } @@ -83,33 +74,6 @@ public class RadViewComponent extends RadComponent { return myMargins; } - @Override - public Rectangle getBounds() { - return myBounds; - } - - @Override - public Rectangle getBounds(Component relativeTo) { - return SwingUtilities.convertRectangle(myNativeComponent, myBounds, relativeTo); - } - - public void setBounds(int x, int y, int width, int height) { - myBounds.setBounds(x, y, width, height); - } - - public Component getNativeComponent() { - return myNativeComponent; - } - - public void setNativeComponent(Component nativeComponent) { - myNativeComponent = nativeComponent; - } - - @Override - public Point convertPoint(Component component, int x, int y) { - return SwingUtilities.convertPoint(component, x, y, myNativeComponent); - } - @Override public void delete() throws Exception { getParent().getChildren().remove(this); diff --git a/plugins/devkit/src/inspections/InspectionDescriptionNotFoundInspection.java b/plugins/devkit/src/inspections/InspectionDescriptionNotFoundInspection.java index 56431bb8e861..c3d2bbc2b4c4 100644 --- a/plugins/devkit/src/inspections/InspectionDescriptionNotFoundInspection.java +++ b/plugins/devkit/src/inspections/InspectionDescriptionNotFoundInspection.java @@ -40,6 +40,7 @@ import java.util.List; */ public class InspectionDescriptionNotFoundInspection extends DevKitInspectionBase{ @NonNls static final String INSPECTION_PROFILE_ENTRY = InspectionProfileEntry.class.getName(); + @NonNls static final String DUMMY_INSPECTION_TOOL = DummyInspectionTool.class.getName(); @NonNls private static final String INSPECTION_DESCRIPTIONS = "inspectionDescriptions"; @Override @@ -51,8 +52,10 @@ public class InspectionDescriptionNotFoundInspection extends DevKitInspectionBas if (nameIdentifier == null || module == null || !PsiUtil.isInstantiatable(aClass)) return null; final PsiClass base = JavaPsiFacade.getInstance(project).findClass(INSPECTION_PROFILE_ENTRY, GlobalSearchScope.allScope(project)); + final PsiClass dummy = JavaPsiFacade.getInstance(project).findClass(DUMMY_INSPECTION_TOOL, GlobalSearchScope.allScope(project)); if (base == null || ! aClass.isInheritor(base, true) || isPathMethodsAreOverridden(aClass)) return null; + if (dummy == null || aClass.isInheritor(dummy, true)) return null; PsiMethod method = findNearestMethod("getShortName", aClass); if (method != null && method.getContainingClass().getQualifiedName().equals(INSPECTION_PROFILE_ENTRY)) { diff --git a/plugins/git4idea/src/git4idea/config/GitVcsPanel.java b/plugins/git4idea/src/git4idea/config/GitVcsPanel.java index f03b9247b4e4..6d869ee727af 100644 --- a/plugins/git4idea/src/git4idea/config/GitVcsPanel.java +++ b/plugins/git4idea/src/git4idea/config/GitVcsPanel.java @@ -37,7 +37,7 @@ import java.awt.event.ActionListener; */ public class GitVcsPanel { - private static final String IDEA_SSH = ApplicationNamesInfo.getInstance().getProductName() + " " + GitBundle.getString("git.vcs.config.ssh.mode.idea"); // IDEA ssh value + private static final String IDEA_SSH = GitBundle.getString("git.vcs.config.ssh.mode.idea"); // IDEA ssh value private static final String NATIVE_SSH = GitBundle.getString("git.vcs.config.ssh.mode.native"); // Native SSH value private static final String CRLF_CONVERT_TO_PROJECT = GitBundle.getString("git.vcs.config.convert.project"); private static final String CRLF_DO_NOT_CONVERT = GitBundle.getString("git.vcs.config.convert.do.not.convert"); diff --git a/plugins/git4idea/src/git4idea/i18n/GitBundle.properties b/plugins/git4idea/src/git4idea/i18n/GitBundle.properties index 50dff3b2c277..51be87b34d77 100644 --- a/plugins/git4idea/src/git4idea/i18n/GitBundle.properties +++ b/plugins/git4idea/src/git4idea/i18n/GitBundle.properties @@ -144,7 +144,7 @@ git.vcs.config.convert.tooltip=Specify what to do if line separators in a Note that this setting has nothing common with Git autocrlf and other Git settings.\ git.vcs.config.path.label=Path to &Git Executable: -git.vcs.config.ssh.mode.idea=ssh +git.vcs.config.ssh.mode.idea=Built-in git.vcs.config.ssh.mode.native=Native git.vcs.config.ssh.mode.tooltip=Specify which version of SSH to be used with Git.
  • Native means that the native SSH will be used.
  • {0} SSH means that the implementation provided by the {0} will be used.
The native implementation might cause hangups on some platforms. In native case, you also might need to configure ssh-askpass for your platform to receive GUI prompts for passwords. git.vcs.config.ssh.mode=&SSH Executable: diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/AddAction.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/AddAction.java index c9cb2b633278..965ec210a591 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/AddAction.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/AddAction.java @@ -19,12 +19,16 @@ package org.jetbrains.idea.svn.actions; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.AbstractVcs; +import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vcs.changes.BackgroundFromStartOption; import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.util.ui.VcsBackgroundTaskWithLocalHistory; import org.jetbrains.idea.svn.SvnBundle; import org.jetbrains.idea.svn.SvnStatusUtil; import org.jetbrains.idea.svn.SvnVcs; @@ -40,6 +44,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; public class AddAction extends BasicAction { static final Logger log = Logger.getInstance("org.jetbrains.idea.svn.action.AddAction"); @@ -57,22 +62,47 @@ public class AddAction extends BasicAction { return true; } - protected void batchPerform(final Project project, SvnVcs activeVcs, VirtualFile[] files, DataContext context) + protected void batchPerform(final Project project, final SvnVcs activeVcs, final VirtualFile[] files, DataContext context) throws VcsException { log.debug("enter: batchPerform"); - SvnVcs vcs = SvnVcs.getInstance(project); - SVNWCClient wcClient = vcs.createWCClient(); - wcClient.setEventHandler(new AddEventListener(project)); + addFiles(project, activeVcs, files); + } - Collection exceptions = SvnCheckinEnvironment.scheduleUnversionedFilesForAddition(wcClient, Arrays.asList(files), true); - if (! exceptions.isEmpty()) { - final Collection messages = new ArrayList(exceptions.size()); - for (SVNException exception : exceptions) { - messages.add(exception.getMessage()); - } - throw new VcsException(messages); - } + private void addFiles(final Project project, final SvnVcs activeVcs, final VirtualFile[] files) { + // passed parameter serves only for "" + VcsBackgroundTaskWithLocalHistory taskWithLocalHistory = + new VcsBackgroundTaskWithLocalHistory(project, getActionName(activeVcs), BackgroundFromStartOption.getInstance(), + Collections.singleton(files), true, SvnBundle.message("action.Subversion.Add.text")) { + @Override + protected void process(VirtualFile[] items) throws VcsException { + ProjectLevelVcsManager manager = ProjectLevelVcsManager.getInstance(project); + manager.startBackgroundVcsOperation(); + try { + + SVNWCClient wcClient = activeVcs.createWCClient(); + wcClient.setEventHandler(new AddEventListener(project)); + + Collection exceptions = + SvnCheckinEnvironment.scheduleUnversionedFilesForAddition(wcClient, Arrays.asList(items), true); + if (!exceptions.isEmpty()) { + final Collection messages = new ArrayList(exceptions.size()); + for (SVNException exception : exceptions) { + messages.add(exception.getMessage()); + } + throw new VcsException(messages); + } + } finally { + manager.stopBackgroundVcsOperation(); + } + } + }; + ProgressManager.getInstance().run(taskWithLocalHistory); + } + + @Override + protected boolean witeLocalHistory() { + return false; } protected boolean isBatchAction() { @@ -82,16 +112,7 @@ public class AddAction extends BasicAction { protected void perform(Project project, SvnVcs activeVcs, VirtualFile file, DataContext context) throws VcsException { - try { - SVNWCClient wcClient = activeVcs.createWCClient(); - wcClient.setEventHandler(new AddEventListener(project)); - wcClient.doAdd(new File(file.getPath()), false, false, true, true); - } - catch (SVNException e) { - VcsException ve = new VcsException(e); - ve.setVirtualFile(file); - throw ve; - } + addFiles(project, activeVcs, new VirtualFile[] {file}); } private static class AddEventListener implements ISVNEventHandler { diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/BasicAction.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/BasicAction.java index 4bfd8ec4a527..35f360f4755a 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/BasicAction.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/actions/BasicAction.java @@ -61,7 +61,7 @@ public abstract class BasicAction extends AnAction implements DumbAware { final AbstractVcsHelper helper = AbstractVcsHelper.getInstance(project); LocalHistoryAction action = LocalHistoryAction.NULL; - if (actionName != null) { + if (witeLocalHistory() && actionName != null) { action = LocalHistory.getInstance().startAction(actionName); } @@ -95,6 +95,10 @@ public abstract class BasicAction extends AnAction implements DumbAware { } } + protected boolean witeLocalHistory() { + return true; + } + public void update(AnActionEvent e) { //LOG.debug("enter: update class:"+getClass().getName()); super.update(e); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/checkin/SvnCheckinEnvironment.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/checkin/SvnCheckinEnvironment.java index c265a4969d3f..e58f6ca2b57f 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/checkin/SvnCheckinEnvironment.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/checkin/SvnCheckinEnvironment.java @@ -392,6 +392,26 @@ public class SvnCheckinEnvironment implements CheckinEnvironment { Collections.sort(files, FilePathComparator.getInstance()); + wcClient.setEventHandler(new ISVNEventHandler() { + @Override + public void handleEvent(SVNEvent event, double progress) throws SVNException { + final ProgressManager pm = ProgressManager.getInstance(); + final ProgressIndicator pi = pm.getProgressIndicator(); + if (pi != null && event.getFile() != null) { + File file = event.getFile(); + pi.setText(SvnBundle.message("progress.text2.adding", file.getName() + " (" + file.getParent() + ")")); + } + } + + @Override + public void checkCancelled() throws SVNCancelException { + final ProgressManager pm = ProgressManager.getInstance(); + final ProgressIndicator pi = pm.getProgressIndicator(); + if (pi != null) { + if (pi.isCanceled()) throw new SVNCancelException(); + } + } + }); for (VirtualFile file : files) { try { wcClient.doAdd(new File(FileUtil.toSystemDependentName(file.getPath())), true, false, true, recursive); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/BunchFactory.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/BunchFactory.java index 63c4915d07f9..1e4760b487a4 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/BunchFactory.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/BunchFactory.java @@ -15,6 +15,7 @@ */ package org.jetbrains.idea.svn.history; +import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.util.Ref; import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList; import org.tmatesoft.svn.core.SVNException; @@ -88,6 +89,7 @@ public class BunchFactory { if (defender == 0) { return; } + ProgressManager.checkCanceled(); final Fragment fragment = myCurrentProvider.getEarliestBunchInInterval(myYoungest, 0, (myYoungest == -1) ? myBunchSize : (myBunchSize + 1), (myYoungest == -1), true); if ((fragment == null) || (fragment.getList().isEmpty())) { @@ -95,6 +97,7 @@ public class BunchFactory { break; } + ProgressManager.checkCanceled(); final List bunchLists = fragment.getList(); if (! fragment.isConsistentWithYounger()) { final long endRevision = bunchLists.get(0).getNumber(); diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/CommonEditActionsProvider.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/CommonEditActionsProvider.java index 8376b2faadf3..fbc4d9e370aa 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/CommonEditActionsProvider.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/CommonEditActionsProvider.java @@ -51,6 +51,11 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider, public CommonEditActionsProvider(DesignerEditorPanel designer) { myDesigner = designer; } + + protected EditableArea getArea() { + return myDesigner.getActionsArea(); + } + ////////////////////////////////////////////////////////////////////////////////////////// // // Delete @@ -60,7 +65,7 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider, @Override public boolean canDeleteElement(@NotNull DataContext dataContext) { // TODO: InplaceEditing - List selection = myDesigner.getActionsArea().getSelection(); + List selection = getArea().getSelection(); if (selection.isEmpty()) { return false; } @@ -77,7 +82,7 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider, myDesigner.getToolProvider().execute(new ThrowableRunnable() { @Override public void run() throws Exception { - EditableArea area = myDesigner.getActionsArea(); + EditableArea area = getArea(); List selection = area.getSelection(); List components = RadComponent.getPureSelection(selection); RadComponent newSelection = getNewSelection(components.get(0), selection); @@ -128,7 +133,7 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider, @Override public boolean isCopyEnabled(@NotNull DataContext dataContext) { // TODO: InplaceEditing - return !myDesigner.getActionsArea().getSelection().isEmpty(); + return !getArea().getSelection().isEmpty(); } @Override @@ -141,7 +146,7 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider, Element root = new Element("designer"); root.setAttribute("target", myDesigner.getPlatformTarget()); - List components = RadComponent.getPureSelection(myDesigner.getActionsArea().getSelection()); + List components = RadComponent.getPureSelection(getArea().getSelection()); for (RadComponent component : components) { component.copyTo(root); } diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/CaptionPanel.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/CaptionPanel.java index 248e0cb3396f..91c942b7f508 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/CaptionPanel.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/CaptionPanel.java @@ -15,22 +15,130 @@ */ package com.intellij.designer.designSurface; +import com.intellij.designer.actions.CommonEditActionsProvider; +import com.intellij.designer.designSurface.tools.InputTool; +import com.intellij.designer.model.FindComponentVisitor; +import com.intellij.designer.model.RadComponent; +import com.intellij.designer.model.RadVisualComponent; +import com.intellij.ide.DeleteProvider; +import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.DataProvider; +import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.SideBorder; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import java.awt.*; +import java.util.List; /** * @author Alexander Lobas */ -public class CaptionPanel extends JComponent implements DataProvider { +public class CaptionPanel extends JLayeredPane implements DataProvider, DeleteProvider, ComponentSelectionListener { + private final boolean myHorizontal; + private final EditableArea myArea; + private final DecorationLayer myDecorationLayer; + private final FeedbackLayer myFeedbackLayer; + private final CommonEditActionsProvider myActionsProvider; + private final RadVisualComponent myRootComponent; + public CaptionPanel(DesignerEditorPanel designer, boolean horizontal) { setBorder(IdeBorderFactory.createBorder(horizontal ? SideBorder.BOTTOM : SideBorder.RIGHT)); - setFocusable(true); + + myHorizontal = horizontal; + + myRootComponent = new RadVisualComponent() { + @Override + public boolean canDelete() { + return false; + } + }; + myRootComponent.setNativeComponent(this); + myRootComponent.setBounds(0, 0, 100000, 100000); + + myArea = new ComponentEditableArea(this) { + @Override + protected void fireSelectionChanged() { + super.fireSelectionChanged(); + revalidate(); + repaint(); + } + + @Override + public RadComponent findTarget(int x, int y, @Nullable ComponentTargetFilter filter) { + FindComponentVisitor visitor = new FindComponentVisitor(CaptionPanel.this, filter, x, y); + myRootComponent.accept(visitor, false); + return visitor.getResult(); + } + + @Override + public InputTool findTargetTool(int x, int y) { + return myDecorationLayer.findTargetTool(x, y); + } + + @Override + public void showSelection(boolean value) { + myDecorationLayer.showSelection(value); + } + + @Override + public ComponentDecorator getRootSelectionDecorator() { + return EmptyComponentDecorator.INSTANCE; + } + + @Override + public EditOperation processRootOperation(OperationContext context) { + return null; + } + + @Override + public FeedbackLayer getFeedbackLayer() { + return myFeedbackLayer; + } + + @Override + public RadComponent getRootComponent() { + return myRootComponent; + } + }; + + add(new GlassLayer(designer.getToolProvider(), myArea), DesignerEditorPanel.LAYER_GLASS); + + myDecorationLayer = new DecorationLayer(myArea); + add(myDecorationLayer, DesignerEditorPanel.LAYER_DECORATION); + + myFeedbackLayer = new FeedbackLayer(); + add(myFeedbackLayer, DesignerEditorPanel.LAYER_FEEDBACK); + + myActionsProvider = new CommonEditActionsProvider(designer) { + @Override + protected EditableArea getArea() { + return myArea; + } + }; + + designer.getSurfaceArea().addSelectionListener(this); + } + + public void attachToScrollPane(JScrollPane scrollPane) { + scrollPane.getViewport().addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + repaint(); + } + }); + } + + public void doLayout() { + for (int i = getComponentCount() - 1; i >= 0; i--) { + Component component = getComponent(i); + component.setBounds(0, 0, getWidth(), getHeight()); + } } @Override @@ -45,6 +153,56 @@ public class CaptionPanel extends JComponent implements DataProvider { @Override public Object getData(@NonNls String dataId) { - return null; // TODO: Auto-generated method stub + if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) { + return this; + } + return null; + } + + @Override + public boolean canDeleteElement(@NotNull DataContext dataContext) { + return myActionsProvider.canDeleteElement(dataContext); + } + + @Override + public void deleteElement(@NotNull DataContext dataContext) { + myActionsProvider.deleteElement(dataContext); + } + + @Override + public void selectionChanged(EditableArea area) { + List selection = area.getSelection(); + if (selection.size() != 1) { + return; + } + + List children = myRootComponent.getChildren(); + boolean update = !children.isEmpty(); + + children.clear(); + myRootComponent.setLayout(null); + + ICaption caption = null; + RadComponent component = selection.get(0); + RadComponent parent = component.getParent(); + + if (parent != null && parent.getLayout() instanceof ICaption) { + caption = (ICaption)parent.getLayout(); + } + + if (caption == null && component instanceof ICaption) { + caption = (ICaption)component; + } + + if (caption != null) { + myRootComponent.setLayout(caption.getCaptionLayout(area, myHorizontal)); + caption.addCaptionChildren(area, myHorizontal, children); + update = true; + } + + if (update) { + revalidate(); + repaint(); + } } } \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DesignerEditorPanel.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DesignerEditorPanel.java index 4a849b99303a..5677ec154726 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DesignerEditorPanel.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DesignerEditorPanel.java @@ -21,8 +21,8 @@ import com.intellij.designer.actions.DesignerActionPanel; import com.intellij.designer.componentTree.TreeComponentDecorator; import com.intellij.designer.componentTree.TreeEditableArea; import com.intellij.designer.designSurface.tools.*; +import com.intellij.designer.model.FindComponentVisitor; import com.intellij.designer.model.RadComponent; -import com.intellij.designer.model.RadComponentVisitor; import com.intellij.designer.palette.Item; import com.intellij.designer.propertyTable.Property; import com.intellij.diagnostic.LogMessageEx; @@ -70,12 +70,10 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider private static final Logger LOG = Logger.getInstance("#com.intellij.designer.designSurface.DesignerEditorPanel"); protected static final Integer LAYER_COMPONENT = JLayeredPane.DEFAULT_LAYER; - protected static final Integer LAYER_STATIC_DECORATION = JLayeredPane.POPUP_LAYER; - protected static final Integer LAYER_DECORATION = JLayeredPane.DRAG_LAYER; - protected static final Integer LAYER_FEEDBACK = LAYER_DECORATION + 100; + protected static final Integer LAYER_DECORATION = JLayeredPane.POPUP_LAYER; + protected static final Integer LAYER_FEEDBACK = JLayeredPane.DRAG_LAYER; protected static final Integer LAYER_GLASS = LAYER_FEEDBACK + 100; - protected static final Integer LAYER_BUTTONS = LAYER_GLASS + 100; - protected static final Integer LAYER_INPLACE_EDITING = LAYER_BUTTONS + 100; + protected static final Integer LAYER_INPLACE_EDITING = LAYER_GLASS + 100; private static final Integer LAYER_PROGRESS = LAYER_INPLACE_EDITING + 100; private final static String DESIGNER_CARD = "designer"; @@ -134,24 +132,6 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider } private void createDesignerCard() { - JPanel content = new JPanel(new GridBagLayout()); - - GridBagConstraints gbc = new GridBagConstraints(); - - gbc.gridx = 0; - gbc.gridy = 1; - gbc.fill = GridBagConstraints.VERTICAL; - - myVerticalCaption = new CaptionPanel(this, false); - content.add(myVerticalCaption, gbc); - - gbc.gridx = 1; - gbc.gridy = 0; - gbc.fill = GridBagConstraints.HORIZONTAL; - - myHorizontalCaption = new CaptionPanel(this, true); - content.add(myHorizontalCaption, gbc); - myLayeredPane = new MyLayeredPane(); mySurfaceArea = new ComponentEditableArea(myLayeredPane) { @@ -165,7 +145,7 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider @Override public RadComponent findTarget(int x, int y, @Nullable ComponentTargetFilter filter) { if (myRootComponent != null) { - FindComponentVisitor visitor = new FindComponentVisitor(filter, x, y); + FindComponentVisitor visitor = new FindComponentVisitor(myLayeredPane, filter, x, y); myRootComponent.accept(visitor, false); return visitor.getResult(); } @@ -267,6 +247,24 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider myFeedbackLayer = new FeedbackLayer(); myLayeredPane.add(myFeedbackLayer, LAYER_FEEDBACK); + JPanel content = new JPanel(new GridBagLayout()); + + GridBagConstraints gbc = new GridBagConstraints(); + + gbc.gridx = 0; + gbc.gridy = 1; + gbc.fill = GridBagConstraints.VERTICAL; + + myVerticalCaption = new CaptionPanel(this, false); + content.add(myVerticalCaption, gbc); + + gbc.gridx = 1; + gbc.gridy = 0; + gbc.fill = GridBagConstraints.HORIZONTAL; + + myHorizontalCaption = new CaptionPanel(this, true); + content.add(myHorizontalCaption, gbc); + gbc.gridx = 1; gbc.gridy = 1; gbc.weightx = 1; @@ -277,6 +275,9 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider myScrollPane.setBackground(Color.WHITE); content.add(myScrollPane, gbc); + myHorizontalCaption.attachToScrollPane(myScrollPane); + myVerticalCaption.attachToScrollPane(myScrollPane); + myActionPanel = new DesignerActionPanel(this, myGlassLayer); myDesignerCard = new JPanel(new FillLayout()); @@ -768,37 +769,6 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider } } - private class FindComponentVisitor extends RadComponentVisitor { - @Nullable private final ComponentTargetFilter myFilter; - private RadComponent myResult; - private final int myX; - private final int myY; - - public FindComponentVisitor(@Nullable ComponentTargetFilter filter, int x, int y) { - myFilter = filter; - myX = x; - myY = y; - } - - public RadComponent getResult() { - return myResult; - } - - @Override - public boolean visit(RadComponent component) { - return myResult == null && - component.getBounds(myLayeredPane).contains(myX, myY) && - (myFilter == null || myFilter.preFilter(component)); - } - - @Override - public void endVisit(RadComponent component) { - if (myResult == null && (myFilter == null || myFilter.resultFilter(component))) { - myResult = component; - } - } - } - public static final class ErrorInfo { public String myMessage; public String myDisplayMessage; diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/EmptyComponentDecorator.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/EmptyComponentDecorator.java new file mode 100644 index 000000000000..0f8a8dfe539f --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/EmptyComponentDecorator.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2012 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.designer.designSurface; + +import com.intellij.designer.designSurface.tools.InputTool; +import com.intellij.designer.model.RadComponent; + +import java.awt.*; + +/** + * @author Alexander Lobas + */ +public final class EmptyComponentDecorator extends ComponentDecorator { + public static final ComponentDecorator INSTANCE = new EmptyComponentDecorator(); + + private EmptyComponentDecorator() { + } + + @Override + public InputTool findTargetTool(DecorationLayer layer, RadComponent component, int x, int y) { + return null; + } + + @Override + public void decorate(DecorationLayer layer, Graphics2D host, RadComponent component) { + } + + @Override + protected void paint(DecorationLayer layer, Graphics2D g, RadComponent component) { + } +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/ICaption.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/ICaption.java new file mode 100644 index 000000000000..8afb291a40d3 --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/ICaption.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2012 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.designer.designSurface; + +import com.intellij.designer.model.RadComponent; +import com.intellij.designer.model.RadLayout; + +import java.util.List; + +/** + * @author Alexander Lobas + */ +public interface ICaption { + RadLayout getCaptionLayout(EditableArea mainArea, boolean horizontal); + + void addCaptionChildren(EditableArea mainArea, boolean horizontal, List children); +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/FindComponentVisitor.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/FindComponentVisitor.java new file mode 100644 index 000000000000..c966055d3423 --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/FindComponentVisitor.java @@ -0,0 +1,58 @@ +/* + * Copyright 2000-2012 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.designer.model; + +import com.intellij.designer.designSurface.ComponentTargetFilter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +/** + * @author Alexander Lobas + */ +public class FindComponentVisitor extends RadComponentVisitor { + private final JComponent myComponent; + private final ComponentTargetFilter myFilter; + private RadComponent myResult; + private final int myX; + private final int myY; + + public FindComponentVisitor(@NotNull JComponent component, @Nullable ComponentTargetFilter filter, int x, int y) { + myComponent = component; + myFilter = filter; + myX = x; + myY = y; + } + + public RadComponent getResult() { + return myResult; + } + + @Override + public boolean visit(RadComponent component) { + return myResult == null && + component.getBounds(myComponent).contains(myX, myY) && + (myFilter == null || myFilter.preFilter(component)); + } + + @Override + public void endVisit(RadComponent component) { + if (myResult == null && (myFilter == null || myFilter.resultFilter(component))) { + myResult = component; + } + } +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java index 38eddd7d53b3..fa9bd75b84ed 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java @@ -115,7 +115,7 @@ public abstract class RadComponent { } ////////////////////////////////////////////////////////////////////////////////////////// // - // layout + // Layout // ////////////////////////////////////////////////////////////////////////////////////////// @@ -123,9 +123,11 @@ public abstract class RadComponent { return myLayout; } - public void setLayout(RadLayout layout) { + public void setLayout(@Nullable RadLayout layout) { myLayout = layout; - myLayout.setContainer(this); + if (myLayout != null) { + myLayout.setContainer(this); + } } @Nullable diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadVisualComponent.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadVisualComponent.java new file mode 100644 index 000000000000..c72a16301536 --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadVisualComponent.java @@ -0,0 +1,67 @@ +/* + * Copyright 2000-2012 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.designer.model; + +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Alexander Lobas + */ +public abstract class RadVisualComponent extends RadComponent { + protected final List myChildren = new ArrayList(); + + private Component myNativeComponent; + private final Rectangle myBounds = new Rectangle(); + + @Override + public List getChildren() { + return myChildren; + } + + @Override + public Rectangle getBounds() { + return myBounds; + } + + @Override + public Rectangle getBounds(Component relativeTo) { + return myNativeComponent == relativeTo + ? new Rectangle(myBounds) : + SwingUtilities.convertRectangle(myNativeComponent, myBounds, relativeTo); + } + + public void setBounds(int x, int y, int width, int height) { + myBounds.setBounds(x, y, width, height); + } + + @Override + public Point convertPoint(Component relativeFrom, int x, int y) { + return myNativeComponent == relativeFrom + ? myBounds.getLocation() : + SwingUtilities.convertPoint(relativeFrom, x, y, myNativeComponent); + } + + public Component getNativeComponent() { + return myNativeComponent; + } + + public void setNativeComponent(Component nativeComponent) { + myNativeComponent = nativeComponent; + } +} \ No newline at end of file diff --git a/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java b/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java index 701113edbc02..76a786182ce8 100644 --- a/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java +++ b/xml/impl/src/com/intellij/javaee/ExternalResourceManagerImpl.java @@ -35,6 +35,7 @@ import com.intellij.psi.xml.XmlFile; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.CollectionFactory; import com.intellij.util.containers.HashMap; +import com.intellij.xml.Html5SchemaProvider; import com.intellij.xml.XmlSchemaProvider; import com.intellij.xml.util.XmlUtil; import org.jdom.Element; @@ -75,7 +76,7 @@ public class ExternalResourceManagerImpl extends ExternalResourceManagerEx imple } }; - private String myDefaultHtmlDoctype = XmlUtil.XHTML_URI; + private String myDefaultHtmlDoctype = Html5SchemaProvider.HTML5_SCHEMA_LOCATION; protected Map> computeStdResources() { ResourceRegistrarImpl registrar = new ResourceRegistrarImpl(); diff --git a/xml/impl/src/com/intellij/lang/xml/XMLExternalAnnotator.java b/xml/impl/src/com/intellij/lang/xml/XMLExternalAnnotator.java index 98a87ba4bde9..75a8da529a32 100644 --- a/xml/impl/src/com/intellij/lang/xml/XMLExternalAnnotator.java +++ b/xml/impl/src/com/intellij/lang/xml/XMLExternalAnnotator.java @@ -27,7 +27,6 @@ import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.psi.xml.XmlToken; import com.intellij.xml.XmlNSDescriptor; -import com.intellij.xml.util.HtmlUtil; import com.intellij.xml.util.XmlTagUtil; /** @@ -42,7 +41,7 @@ public class XMLExternalAnnotator extends ExternalAnnotator { XmlTag rootTag = document.getRootTag(); XmlNSDescriptor nsDescriptor = rootTag == null ? null : rootTag.getNSDescriptor(rootTag.getNamespace(), false); - if (nsDescriptor instanceof Validator && !HtmlUtil.isHtml5Document(document)) { + if (nsDescriptor instanceof Validator) { //noinspection unchecked ((Validator)nsDescriptor).validate(document, new MyHost(holder)); } diff --git a/xml/impl/src/com/intellij/psi/impl/source/html/HtmlConditionalCommentInjector.java b/xml/impl/src/com/intellij/psi/impl/source/html/HtmlConditionalCommentInjector.java index 38086bdcabc8..bcd6f5a0a64e 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/html/HtmlConditionalCommentInjector.java +++ b/xml/impl/src/com/intellij/psi/impl/source/html/HtmlConditionalCommentInjector.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -88,7 +88,9 @@ public class HtmlConditionalCommentInjector implements MultiHostInjector { ASTNode conditionalStart = pair.first; ASTNode conditionalEnd = pair.second; TextRange range = new TextRange(conditionalStart.getTextRange().getEndOffset() - startOffset, conditionalEnd.getStartOffset() - startOffset); - registrar.startInjecting(language).addPlace(null, null, (PsiLanguageInjectionHost)host, range).doneInjecting(); + if (range.getStartOffset() < range.getEndOffset()) { + registrar.startInjecting(language).addPlace(null, null, (PsiLanguageInjectionHost)host, range).doneInjecting(); + } } @NotNull diff --git a/xml/impl/src/com/intellij/xml/impl/dtd/XmlElementsGroupImpl.java b/xml/impl/src/com/intellij/xml/impl/dtd/XmlElementsGroupImpl.java index 0dff86734971..9f734164b9c6 100644 --- a/xml/impl/src/com/intellij/xml/impl/dtd/XmlElementsGroupImpl.java +++ b/xml/impl/src/com/intellij/xml/impl/dtd/XmlElementsGroupImpl.java @@ -39,7 +39,7 @@ public class XmlElementsGroupImpl implements XmlElementsGroup { return ContainerUtil.map(myParticle.getSubParticles(), new Function() { @Override public XmlElementsGroup fun(XmlContentParticle xmlContentParticle) { - return new XmlElementsGroupImpl(xmlContentParticle, XmlElementsGroupImpl.this); + return new XmlElementsGroupImpl(xmlContentParticle, XmlElementsGroupImpl.this); } }); } diff --git a/xml/impl/src/com/intellij/xml/impl/schema/XmlNSDescriptorImpl.java b/xml/impl/src/com/intellij/xml/impl/schema/XmlNSDescriptorImpl.java index 27d9abab7f57..8784e6a26fad 100644 --- a/xml/impl/src/com/intellij/xml/impl/schema/XmlNSDescriptorImpl.java +++ b/xml/impl/src/com/intellij/xml/impl/schema/XmlNSDescriptorImpl.java @@ -37,6 +37,7 @@ import com.intellij.util.ArrayUtil; import com.intellij.xml.XmlAttributeDescriptor; import com.intellij.xml.XmlElementDescriptor; import com.intellij.xml.XmlNSDescriptor; +import com.intellij.xml.XmlNSDescriptorEx; import com.intellij.xml.impl.ExternalDocumentValidator; import com.intellij.xml.util.XmlUtil; import gnu.trove.THashSet; @@ -50,7 +51,7 @@ import java.util.*; * @author Mike */ @SuppressWarnings({"HardCodedStringLiteral"}) -public class XmlNSDescriptorImpl implements XmlNSDescriptor,Validator, DumbAware, XmlNSTypeDescriptorProvider { +public class XmlNSDescriptorImpl implements XmlNSDescriptorEx,Validator, DumbAware, XmlNSTypeDescriptorProvider { private static final Logger LOG = Logger.getInstance("#com.intellij.xml.impl.schema.XmlNSDescriptorImpl"); @NonNls private static final Set STD_TYPES = new HashSet(); private static final Set UNDECLARED_STD_TYPES = new HashSet(); diff --git a/xml/openapi/src/com/intellij/xml/XmlNSDescriptorEx.java b/xml/openapi/src/com/intellij/xml/XmlNSDescriptorEx.java new file mode 100644 index 000000000000..bfd463f4d894 --- /dev/null +++ b/xml/openapi/src/com/intellij/xml/XmlNSDescriptorEx.java @@ -0,0 +1,8 @@ +package com.intellij.xml; + +/** + * @author Eugene.Kudelevsky + */ +public interface XmlNSDescriptorEx extends XmlNSDescriptor { + XmlElementDescriptor getElementDescriptor(String localName, String namespace); +} diff --git a/xml/relaxng/src/org/intellij/plugins/relaxNG/model/descriptors/RngNsDescriptor.java b/xml/relaxng/src/org/intellij/plugins/relaxNG/model/descriptors/RngNsDescriptor.java index da137bca4554..5e455aecfc57 100644 --- a/xml/relaxng/src/org/intellij/plugins/relaxNG/model/descriptors/RngNsDescriptor.java +++ b/xml/relaxng/src/org/intellij/plugins/relaxNG/model/descriptors/RngNsDescriptor.java @@ -35,7 +35,8 @@ import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.HashMap; import com.intellij.xml.XmlElementDescriptor; -import com.intellij.xml.XmlNSDescriptor; +import com.intellij.xml.XmlNSDescriptorEx; +import com.intellij.xml.impl.schema.AnyXmlElementDescriptor; import org.intellij.plugins.relaxNG.ApplicationLoader; import org.intellij.plugins.relaxNG.model.resolve.RelaxIncludeIndex; import org.intellij.plugins.relaxNG.validation.RngParser; @@ -48,17 +49,17 @@ import org.kohsuke.rngom.digested.DPattern; import org.kohsuke.rngom.nc.NameClass; import javax.xml.namespace.QName; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Created by IntelliJ IDEA. * User: sweinreuter * Date: 18.07.2007 */ -public class RngNsDescriptor implements XmlNSDescriptor, Validator { +public class RngNsDescriptor implements XmlNSDescriptorEx, Validator { + private final Map> myDescriptorsMap = + Collections.synchronizedMap(new HashMap>()); + private static final Key> ROOT_KEY = Key.create("ROOT_DESCRIPTOR"); private XmlFile myFile; @@ -95,7 +96,7 @@ public class RngNsDescriptor implements XmlNSDescriptor, Validator { } } - if (desc == null) { + if (desc == null || desc instanceof AnyXmlElementDescriptor) { return findRootDescriptor(tag); } @@ -124,6 +125,11 @@ public class RngNsDescriptor implements XmlNSDescriptor, Validator { return descriptor != null ? descriptor : findDescriptor(tag, ChildElementFinder.find(myPattern)); } + private XmlElementDescriptor findRootDescriptorInner(QName qName) { + return findDescriptor(qName, ContainerUtil.findAll( + ChildElementFinder.find(-1, myPattern), NamedPatternFilter.INSTANCE)); + } + public XmlElementDescriptor findDescriptor(XmlTag tag, List list) { final QName qName = new QName(tag.getNamespace(), tag.getLocalName()); @@ -279,4 +285,23 @@ public class RngNsDescriptor implements XmlNSDescriptor, Validator { XmlInstanceValidator.doValidation(doc, host, getDescriptorFile()); } } + + //@Override + public XmlElementDescriptor getElementDescriptor(String localName, String namespace) { + final QName qName = new QName(namespace, localName); + CachedValue cachedValue = myDescriptorsMap.get(qName); + if (cachedValue == null) { + cachedValue = + CachedValuesManager.getManager(myElement.getProject()).createCachedValue(new CachedValueProvider() { + public Result compute() { + final XmlElementDescriptor descriptor = findRootDescriptorInner(qName); + return descriptor != null + ? new Result(descriptor, descriptor.getDependences()) + : new Result(null, getDependences()); + } + }, false); + myDescriptorsMap.put(qName, cachedValue); + } + return cachedValue.getValue(); + } }