diff --git a/java/idea-ui/src/com/intellij/framework/library/FrameworkSupportWithLibrary.java b/java/idea-ui/src/com/intellij/framework/library/FrameworkSupportWithLibrary.java index dce7da5e3f85..9ca15ad45ee5 100644 --- a/java/idea-ui/src/com/intellij/framework/library/FrameworkSupportWithLibrary.java +++ b/java/idea-ui/src/com/intellij/framework/library/FrameworkSupportWithLibrary.java @@ -16,14 +16,14 @@ package com.intellij.framework.library; import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; -import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author nik */ public interface FrameworkSupportWithLibrary { - @NotNull + @Nullable CustomLibraryDescription createLibraryDescription(); boolean isLibraryOnly(); diff --git a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/FieldInColumnsPreFormatProcessor.java b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/FieldInColumnsPreFormatProcessor.java new file mode 100644 index 000000000000..72b27ee31286 --- /dev/null +++ b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/FieldInColumnsPreFormatProcessor.java @@ -0,0 +1,120 @@ +/* + * 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.psi.impl.source.codeStyle; + +import com.intellij.lang.ASTNode; +import com.intellij.lang.java.JavaLanguage; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.TextRange; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiField; +import com.intellij.psi.PsiFile; +import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; +import com.intellij.psi.impl.source.tree.ElementType; +import com.intellij.psi.impl.source.tree.JavaJspElementType; +import com.intellij.psi.util.PsiTreeUtil; +import org.jetbrains.annotations.NotNull; + +/** + * There is a possible case that the project is configured to keep fields in columns: + *
+ *   class Test {
+ *     int i                 = 1;
+ *     int fieldWithLongName = 2;
+ *   }
+ * 
+ * Suppose that one of the fields is renamed. We want to reformat the whole fields group then in order to keep that 'field columns'. + *

+ * Current extension checks if given range intersects with a field from a field group and expands its boundaries to contain + * the whole group. + *

+ * Thread-safe. + * + * @author Denis Zhdanov + * @since 5/9/12 4:54 PM + */ +public class FieldInColumnsPreFormatProcessor implements PreFormatProcessor { + + @NotNull + @Override + public TextRange process(@NotNull ASTNode element, @NotNull TextRange range) { + //region Checking that everything is ready to expand the range for the 'fields in columns'. + final PsiElement psi = element.getPsi(); + if (psi == null) { + return range; + } + + final PsiFile file = psi.getContainingFile(); + if (file == null) { + return range; + } + + final Project project = psi.getProject(); + final CommonCodeStyleSettings settings + = CodeStyleSettingsManager.getInstance(project).getCurrentSettings().getCommonSettings(JavaLanguage.INSTANCE); + if (!settings.ALIGN_GROUP_FIELD_DECLARATIONS) { + return range; + } + + final PsiElement startElement = file.findElementAt(range.getStartOffset()); + if (startElement == null) { + return range; + } + + final PsiField parent = PsiTreeUtil.getParentOfType(startElement, PsiField.class); + if (parent == null) { + return range; + } + //endregion + + //region Calculating start offset to use by the start offset of the first sibling white space or field to the left of the current field. + int startToUse = range.getStartOffset(); + for (PsiElement f = parent; f != null; f = f.getPrevSibling()) { + final ASTNode node = f.getNode(); + if (node == null) { + break; + } + if (JavaJspElementType.WHITE_SPACE_BIT_SET.contains(node.getElementType()) || f instanceof PsiField) { + startToUse = f.getTextRange().getStartOffset(); + } + else if (!ElementType.JAVA_COMMENT_BIT_SET.contains(node.getElementType())) { + break; + } + } + //endregion + + //region Calculating end offset to use by the end offset of the last field in a group located to the right of the current field. + int endToUse = range.getEndOffset(); + for (PsiElement f = parent; f != null; f = f.getPrevSibling()) { + final ASTNode node = f.getNode(); + if (node == null) { + break; + } + if (f instanceof PsiField) { + endToUse = f.getTextRange().getEndOffset(); + } + else if (!JavaJspElementType.WHITE_SPACE_BIT_SET.contains(node.getElementType()) && + !ElementType.JAVA_COMMENT_BIT_SET.contains(node.getElementType())) + { + break; + } + } + //endregion + + return TextRange.from(startToUse, endToUse); + } +} diff --git a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/FormatCommentsProcessor.java b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/FormatCommentsProcessor.java index 4efb46a4b4bd..5c80f43240d7 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/FormatCommentsProcessor.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/FormatCommentsProcessor.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. @@ -25,10 +25,12 @@ import com.intellij.psi.codeStyle.CodeStyleSettingsManager; import com.intellij.psi.impl.source.SourceTreeToPsiMap; import com.intellij.psi.impl.source.codeStyle.javadoc.CommentFormatter; import com.intellij.psi.javadoc.PsiDocComment; +import org.jetbrains.annotations.NotNull; public class FormatCommentsProcessor implements PreFormatProcessor { + @NotNull @Override - public TextRange process(final ASTNode element, final TextRange range) { + public TextRange process(@NotNull final ASTNode element, @NotNull final TextRange range) { final Project project = SourceTreeToPsiMap.treeElementToPsi(element).getProject(); if (!CodeStyleSettingsManager.getSettings(project).ENABLE_JAVADOC_FORMATTING || element.getPsi().getContainingFile().getLanguage() != StdLanguages.JAVA) { diff --git a/java/java-tests/testData/refactoring/renameField/afterFieldInColumns.java b/java/java-tests/testData/refactoring/renameField/afterFieldInColumns.java new file mode 100644 index 000000000000..b2f73979881e --- /dev/null +++ b/java/java-tests/testData/refactoring/renameField/afterFieldInColumns.java @@ -0,0 +1,23 @@ +/* + * 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. + */ +class Test { + int jj = 1; + int fieldWithLongName = 2; + + void test() { + jj = 3; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/renameField/beforeFieldInColumns.java b/java/java-tests/testData/refactoring/renameField/beforeFieldInColumns.java new file mode 100644 index 000000000000..9e214201346c --- /dev/null +++ b/java/java-tests/testData/refactoring/renameField/beforeFieldInColumns.java @@ -0,0 +1,23 @@ +/* + * 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. + */ +class Test { + int i = 1; + int fieldWithLongName = 2; + + void test() { + i = 3; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/RenameFieldTest.java b/java/java-tests/testSrc/com/intellij/refactoring/RenameFieldTest.java index d5d7f02d317e..656156bfde98 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/RenameFieldTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/RenameFieldTest.java @@ -1,3 +1,19 @@ +/* + * 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. + */ + /* * Created by IntelliJ IDEA. * User: dsl @@ -10,7 +26,9 @@ package com.intellij.refactoring; import com.intellij.JavaTestUtil; import com.intellij.codeInsight.TargetElementUtilBase; +import com.intellij.lang.java.JavaLanguage; import com.intellij.psi.PsiElement; +import com.intellij.psi.codeStyle.CodeStyleSettingsManager; import com.intellij.refactoring.rename.RenameProcessor; import com.intellij.refactoring.rename.RenameWrongRefHandler; import org.jetbrains.annotations.NonNls; @@ -66,6 +84,13 @@ public class RenameFieldTest extends LightRefactoringTestCase { assertFalse(RenameWrongRefHandler.isAvailable(getProject(), getEditor(), getFile())); } + public void testFieldInColumns() throws Exception { + // Assuming that test infrastructure setups temp settings (CodeStyleSettingsManager.setTemporarySettings()) and we don't + // need to perform explicit clean-up at the test level. + CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE).ALIGN_GROUP_FIELD_DECLARATIONS = true; + doTest("jj", "java"); + } + protected static void perform(String newName) { PsiElement element = TargetElementUtilBase.findTargetElement(myEditor, TargetElementUtilBase .ELEMENT_NAME_ACCEPTED | TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED); diff --git a/platform/lang-api/src/com/intellij/navigation/GotoRelatedItem.java b/platform/lang-api/src/com/intellij/navigation/GotoRelatedItem.java index 0ecc556d0d3e..4dbbd81a4146 100644 --- a/platform/lang-api/src/com/intellij/navigation/GotoRelatedItem.java +++ b/platform/lang-api/src/com/intellij/navigation/GotoRelatedItem.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. @@ -27,22 +27,26 @@ import java.util.List; /** * @author Dmitry Avdeev + * @author Konstantin Bulenkov */ public class GotoRelatedItem { + private final String myGroup; private final int myMnemonic; private final PsiElement myElement; + public static final String DEFAULT_GROUP_NAME = ""; - protected GotoRelatedItem(@Nullable PsiElement element, final int mnemonic) { + protected GotoRelatedItem(@Nullable PsiElement element, String group, final int mnemonic) { myElement = element; + myGroup = group; myMnemonic = mnemonic; } - public GotoRelatedItem(@NotNull PsiElement element) { - this(element, -1); + public GotoRelatedItem(@NotNull PsiElement element, String group) { + this(element, group, -1); } - protected GotoRelatedItem() { - this(null, -1); + public GotoRelatedItem(@NotNull PsiElement element) { + this(element, DEFAULT_GROUP_NAME); } public void navigate() { @@ -67,11 +71,14 @@ public class GotoRelatedItem { public int getMnemonic() { return myMnemonic; } - public static List createItems(@NotNull Collection elements) { + return createItems(elements, DEFAULT_GROUP_NAME); + } + + public static List createItems(@NotNull Collection elements, String group) { List items = new ArrayList(elements.size()); for (PsiElement element : elements) { - items.add(new GotoRelatedItem(element)); + items.add(new GotoRelatedItem(element, group)); } return items; } @@ -88,6 +95,10 @@ public class GotoRelatedItem { return true; } + public String getGroup() { + return myGroup; + } + @Override public int hashCode() { return myElement != null ? myElement.hashCode() : 0; diff --git a/platform/lang-impl/src/com/intellij/formatting/AbstractBlockWrapper.java b/platform/lang-impl/src/com/intellij/formatting/AbstractBlockWrapper.java index e79d7e17c076..77908a96df12 100644 --- a/platform/lang-impl/src/com/intellij/formatting/AbstractBlockWrapper.java +++ b/platform/lang-impl/src/com/intellij/formatting/AbstractBlockWrapper.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. @@ -236,14 +236,15 @@ public abstract class AbstractBlockWrapper { else { return childIndent.add(myParent.getChildOffset(this, options, targetBlockStartOffset)); } - } else if (!getWhiteSpace().containsLineFeeds()) { - if (isIndentAffectedAlignment(child)) { - return createAlignmentIndent(childIndent, child); - } - else { - return childIndent.add(myParent.getChildOffset(this, options, targetBlockStartOffset)); - } - } else { + } + else if (!getWhiteSpace().containsLineFeeds()) { + final IndentData indent = createAlignmentIndent(childIndent, child); + if (indent != null) { + return indent; + } + return childIndent.add(myParent.getChildOffset(this, options, targetBlockStartOffset)); + } + else { if (myParent == null) return childIndent.add(getWhiteSpace()); if (getIndent().isAbsolute()) { if (myParent.myParent != null) { @@ -254,12 +255,11 @@ public abstract class AbstractBlockWrapper { } } if ((myFlags & CAN_USE_FIRST_CHILD_INDENT_AS_BLOCK_INDENT) != 0) { - if (isIndentAffectedAlignment(child)) { - return createAlignmentIndent(childIndent, child); - } - else { - return childIndent.add(getWhiteSpace()); + final IndentData indent = createAlignmentIndent(childIndent, child); + if (indent != null) { + return indent; } + return childIndent.add(getWhiteSpace()); } else { return childIndent.add(myParent.getChildOffset(this, options, targetBlockStartOffset)); @@ -343,29 +343,8 @@ public abstract class AbstractBlockWrapper { } /** - * Allows to answer if indent for the given child block should be calculated taking into consideration alignment - * of the text at current block start. - * - * @param child child block to check - * @return true if indent should be calculated taking into consideration alignment of the text at current - * block start; false otherwise - */ - private boolean isIndentAffectedAlignment(AbstractBlockWrapper child) { - if (!child.getWhiteSpace().containsLineFeeds()) { - return false; - } - AlignmentImpl alignment = getAlignmentAtStartOffset(); - if (alignment == null || alignment == child.getAlignment()) { - return false; - } - - LeafBlockWrapper anchorOffsetBlock = alignment.getOffsetRespBlockBefore(child); - return anchorOffsetBlock == null || anchorOffsetBlock.getStartOffset() >= getStartOffset(); - } - - /** - * Allows to construct indent for the block that is affected by aligning rules. E.g. there is a possible case that the user - * configures method call arguments to be aligned and single parameter expression spans more than one line: + * Check if it's possible to construct indent for the block that is affected by aligning rules. E.g. there is a possible case + * that the user configures method call arguments to be aligned and single parameter expression spans more than one line: *

*

    *     public void test(String s1, String s2) {}
@@ -383,15 +362,41 @@ public abstract class AbstractBlockWrapper {
    * sub-blocks that are located on new lines should also be indented to the point of composite block start.
    * 

* This method takes care about constructing target absolute indent of the given child block assuming that it's parent - * (referenced by 'this') or it's ancestor that starts at the same offset is aligned. I.e. it assumes - * that {@link #isIndentAffectedAlignment(AbstractBlockWrapper)} returns true for the given child block. + * (referenced by 'this') or it's ancestor that starts at the same offset is aligned. * * @param indentFromParent basic indent of given child from the current parent block * @param child child block of the current aligned composite block - * @return absolute indent to use for the given child block of the current composite block + * @return absolute indent to use for the given child block of the current composite block if alignment-affected + * indent should be used for it; + * null otherwise */ + @Nullable private IndentData createAlignmentIndent(IndentData indentFromParent, AbstractBlockWrapper child) { + if (!child.getWhiteSpace().containsLineFeeds()) { + return null; + } + + AlignmentImpl alignment = getAlignmentAtStartOffset(); + if (alignment == null || alignment == child.getAlignment()) { + return null; + } + AbstractBlockWrapper previous = child.getPreviousBlock(); + LeafBlockWrapper anchorOffsetBlock = alignment.getOffsetRespBlockBefore(child); + if (anchorOffsetBlock != null && anchorOffsetBlock.getStartOffset() != getStartOffset()) { + // Located on different lines. + boolean onDifferentLines = false; + for (LeafBlockWrapper b = anchorOffsetBlock.getNextBlock(); b != null && b.getStartOffset() < getStartOffset(); b = b.getNextBlock()) { + if (b.getWhiteSpace().containsLineFeeds()) { + onDifferentLines = true; + break; + } + } + + if (!onDifferentLines) { + return null; + } + } // There is no point in continuing processing if given child is the first block, i.e. there is no alignment-implied // offset to add to the given 'indent from parent'. @@ -399,7 +404,13 @@ public abstract class AbstractBlockWrapper { return indentFromParent; } - IndentData symbolsBeforeCurrent = getNumberOfSymbolsBeforeBlock(); + IndentData symbolsBeforeCurrent; + if (anchorOffsetBlock == null) { + symbolsBeforeCurrent = getNumberOfSymbolsBeforeBlock(); + } + else { + symbolsBeforeCurrent = anchorOffsetBlock.getNumberOfSymbolsBeforeBlock(); + } // Result is calculated as a number of symbols between the current composite parent block plus given 'indent from parent'. int indentSpaces = symbolsBeforeCurrent.getIndentSpaces() + indentFromParent.getSpaces() + indentFromParent.getIndentSpaces(); diff --git a/platform/lang-impl/src/com/intellij/ide/actions/GotoRelatedFileAction.java b/platform/lang-impl/src/com/intellij/ide/actions/GotoRelatedFileAction.java index 79c9b76eb08e..c6e22e785a23 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/GotoRelatedFileAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/GotoRelatedFileAction.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. @@ -26,11 +26,14 @@ import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.openapi.ui.popup.util.BaseListPopupStep; import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.ui.ColoredListCellRenderer; +import com.intellij.ui.SeparatorWithText; import com.intellij.ui.SimpleTextAttributes; import com.intellij.ui.popup.list.ListPopupImpl; +import com.intellij.ui.popup.list.PopupListElementRenderer; import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -97,6 +100,8 @@ public class GotoRelatedFileAction extends AnAction { final String title, final Processor processor) { final Ref hasMnemonic = Ref.create(false); + final Ref rendererRef = Ref.create(null); + final DefaultPsiElementCellRenderer renderer = new DefaultPsiElementCellRenderer() { { setFocusBorderEnabled(false); @@ -190,12 +195,55 @@ public class GotoRelatedFileAction extends AnAction { return super.onChosen(selectedValue, finalChoice); } }) { - @Override - protected ListCellRenderer getListElementRenderer() { - return renderer; - } }; + popup.getList().setCellRenderer(new PopupListElementRenderer(popup) { + Map separators = new HashMap(); + { + final ListModel model = popup.getList().getModel(); + String current = null; + boolean hasTitle = false; + for (int i = 0; i < model.getSize(); i++) { + final Object element = model.getElementAt(i); + final GotoRelatedItem item = itemsMap.get(element); + if (!StringUtil.equals(current, item.getGroup())) { + current = item.getGroup(); + separators.put(element, current); + if (!hasTitle && !StringUtil.isEmpty(current)) { + hasTitle = true; + } + } + } + + if (!hasTitle) { + separators.remove(model.getElementAt(0)); + } + } + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + final Component component = renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + final String separator = separators.get(value); + + if (separator != null) { + JPanel panel = new JPanel(new BorderLayout()); + panel.add(component, BorderLayout.CENTER); + final SeparatorWithText sep = new SeparatorWithText() { + @Override + protected void paintComponent(Graphics g) { + g.setColor(Color.WHITE); + g.fillRect(0,0,getWidth(), getHeight()); + super.paintComponent(g); + } + }; + sep.setCaption(separator); + panel.add(sep, BorderLayout.NORTH); + return panel; + } + return component; + } + }); + popup.setMinimumSize(new Dimension(200, -1)); + for (Object item : elements) { final int mnemonic = getMnemonic(item, itemsMap); if (mnemonic != -1) { @@ -226,9 +274,32 @@ public class GotoRelatedFileAction extends AnAction { items.addAll(provider.getItems(dataContext)); } } + sortByGroupNames(items); return new ArrayList(items); } + private static void sortByGroupNames(Set items) { + Map> map = new HashMap>(); + for (GotoRelatedItem item : items) { + final String key = item.getGroup(); + if (!map.containsKey(key)) { + map.put(key, new ArrayList()); + } + map.get(key).add(item); + } + final List keys = new ArrayList(map.keySet()); + Collections.sort(keys, new Comparator() { + @Override + public int compare(String o1, String o2) { + return StringUtil.isEmpty(o1) ? 1 : StringUtil.isEmpty(o2) ? -1 : o1.compareTo(o2); + } + }); + items.clear(); + for (String key : keys) { + items.addAll(map.get(key)); + } + } + @Override public void update(AnActionEvent e) { e.getPresentation().setEnabled(LangDataKeys.PSI_FILE.getData(e.getDataContext()) != null); diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/PreFormatProcessor.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/PreFormatProcessor.java index c4f243e4300d..f746b33cac31 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/PreFormatProcessor.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/PreFormatProcessor.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 @@ package com.intellij.psi.impl.source.codeStyle; import com.intellij.lang.ASTNode; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.util.TextRange; +import org.jetbrains.annotations.NotNull; /** * @author yole @@ -26,5 +27,6 @@ import com.intellij.openapi.util.TextRange; public interface PreFormatProcessor { ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.preFormatProcessor"); - TextRange process(ASTNode element, TextRange range); + @NotNull + TextRange process(@NotNull ASTNode element, @NotNull TextRange range); } diff --git a/platform/lang-impl/src/com/intellij/testIntegration/GotoTestRelatedProvider.java b/platform/lang-impl/src/com/intellij/testIntegration/GotoTestRelatedProvider.java index 531eee55d427..d618fa60d0ab 100644 --- a/platform/lang-impl/src/com/intellij/testIntegration/GotoTestRelatedProvider.java +++ b/platform/lang-impl/src/com/intellij/testIntegration/GotoTestRelatedProvider.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. @@ -35,15 +35,17 @@ public class GotoTestRelatedProvider extends GotoRelatedProvider { public List getItems(@NotNull DataContext context) { final PsiFile file = LangDataKeys.PSI_FILE.getData(context); List result; - if (TestFinderHelper.isTest(file)) { + final boolean isTest = TestFinderHelper.isTest(file); + if (isTest) { result = TestFinderHelper.findClassesForTest(file); } else { result = TestFinderHelper.findTestsForClass(file); } + if (!result.isEmpty()) { final List items = new ArrayList(); for (PsiElement element : result) { - items.add(new GotoRelatedItem(element)); + items.add(new GotoRelatedItem(element, isTest ? "Tests" : "Testee classes")); } return items; } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java b/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java index a0e42f63198d..ad0c20902d73 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesUpdater.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. diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/jar/JarFileSystemImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/jar/JarFileSystemImpl.java index 12337975ee83..e6181140a387 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/jar/JarFileSystemImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/jar/JarFileSystemImpl.java @@ -89,7 +89,6 @@ public class JarFileSystemImpl extends JarFileSystem implements ApplicationCompo SystemInfo.isFileSystemCaseSensitive)) { VirtualFile jarRootToRefresh = markDirty(jarPath); if (jarRootToRefresh != null) { - LOG.info(jarPath + " will be refreshed due to " + event); rootsToRefresh.add(jarRootToRefresh); } } diff --git a/platform/platform-impl/src/com/intellij/ui/popup/list/ListPopupImpl.java b/platform/platform-impl/src/com/intellij/ui/popup/list/ListPopupImpl.java index 64213cc37d00..ba29b515cea4 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/list/ListPopupImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/list/ListPopupImpl.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. @@ -183,6 +183,10 @@ public class ListPopupImpl extends WizardPopup implements ListPopup { return count; } + public JList getList() { + return myList; + } + protected JComponent createContent() { myMouseMotionListener = new MyMouseMotionListener(); myMouseListener = new MyMouseListener(); diff --git a/platform/platform-resources-en/src/messages/ApplicationBundle.properties b/platform/platform-resources-en/src/messages/ApplicationBundle.properties index dbf3f5ba5a6d..decd52299ae1 100644 --- a/platform/platform-resources-en/src/messages/ApplicationBundle.properties +++ b/platform/platform-resources-en/src/messages/ApplicationBundle.properties @@ -340,7 +340,7 @@ checkbox.collapse.xml.tags=XML tags checkbox.collapse.anonymous.classes=Anonymous classes checkbox.collapse.closures="Closures" (anonymous classes implementing one method) checkbox.collapse.generic.constructor.parameters=Generic constructor and method parameters -checkbox.collapse.i18n.messages=I18n Strings +checkbox.collapse.i18n.messages=I18n strings checkbox.collapse.annotations=Annotations checkbox.collapse.inner.classes=Inner classes checkbox.collapse.simple.property.accessors=Simple property accessors diff --git a/platform/platform-resources-en/src/messages/ExecutionBundle.properties b/platform/platform-resources-en/src/messages/ExecutionBundle.properties index 4321036ede15..c0c60bb80bb0 100644 --- a/platform/platform-resources-en/src/messages/ExecutionBundle.properties +++ b/platform/platform-resources-en/src/messages/ExecutionBundle.properties @@ -287,7 +287,7 @@ logs.tab.title=Logs before.launch.panel.title=Before Launch before.launch.panel.empty=There are no tasks to run before launch before.launch.panel.cyclic_dependency_warning=''{0}'' has already configured to be launched before {1}.\nSuch cyclic dependencies are not allowed. -before.launch.run.another.configuration=Run another Configuration +before.launch.run.another.configuration=Run Another Configuration before.launch.run.certain.configuration=Run ''{0}'' before.launch.run.unknown.task=Unknown task action.name.save.as.configuration=Save As diff --git a/platform/testFramework/src/com/intellij/TestCaseLoader.java b/platform/testFramework/src/com/intellij/TestCaseLoader.java index cc5aed395f84..a64d838c5643 100644 --- a/platform/testFramework/src/com/intellij/TestCaseLoader.java +++ b/platform/testFramework/src/com/intellij/TestCaseLoader.java @@ -36,6 +36,7 @@ import java.io.*; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.*; +import java.util.List; @SuppressWarnings({"HardCodedStringLiteral", "UseOfSystemOutOrSystemErr", "CallToPrintStackTrace", "TestOnlyProblems"}) public class TestCaseLoader { @@ -98,7 +99,9 @@ public class TestCaseLoader { * shouldLoadTestCase () to determine that. */ void addClassIfTestCase(final Class testCaseClass) { - if (shouldAddTestCase(testCaseClass, true) && testCaseClass != myFirstTestClass && testCaseClass != myLastTestClass) { + if (shouldAddTestCase(testCaseClass, true) && testCaseClass != myFirstTestClass && testCaseClass != myLastTestClass + && PlatformTestUtil.canRunTest(testCaseClass)) + { myClassList.add(testCaseClass); } } diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index 0ab4905a7ca2..95f715bd7854 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.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. @@ -448,6 +448,18 @@ public class PlatformTestUtil { return total/(n / part); } + public static boolean canRunTest(@NotNull Class testCaseClass) { + if (GraphicsEnvironment.isHeadless()) { + for (Class clazz = testCaseClass; clazz != null; clazz = clazz.getSuperclass()) { + if (clazz.getAnnotation(SkipInHeadlessEnvironment.class) != null) { + System.out.println("Class '" + testCaseClass.getName() + "' is skipped because it requires working UI environment"); + return false; + } + } + } + return true; + } + public static class TestInfo { private final ThrowableRunnable test; // runnable to measure private final int expected; // millis the test is expected to run diff --git a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java index 98067ba583dc..576b80af610b 100644 --- a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.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. @@ -258,17 +258,7 @@ public abstract class UsefulTestCase extends TestCase { } protected boolean shouldRunTest() { - if (isInHeadlessEnvironment()) { - Class aClass = getClass(); - while (aClass != null) { - if (aClass.getAnnotation(SkipInHeadlessEnvironment.class) != null) { - System.out.println("Test '" + getClass().getName() + "." + getName() + "' is skipped because it requires working UI environment"); - return false; - } - aClass = aClass.getSuperclass(); - } - } - return true; + return PlatformTestUtil.canRunTest(getClass()); } public static void edt(Runnable r) { diff --git a/plugins/IdeaTestAssistant/src/com/intellij/testAssistant/TestDataRelatedItem.java b/plugins/IdeaTestAssistant/src/com/intellij/testAssistant/TestDataRelatedItem.java index 871808e97279..900279214ac5 100644 --- a/plugins/IdeaTestAssistant/src/com/intellij/testAssistant/TestDataRelatedItem.java +++ b/plugins/IdeaTestAssistant/src/com/intellij/testAssistant/TestDataRelatedItem.java @@ -1,3 +1,18 @@ +/* + * 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.testAssistant; import com.intellij.navigation.GotoRelatedItem; @@ -22,7 +37,7 @@ public class TestDataRelatedItem extends GotoRelatedItem{ private final PsiMethod myMethod; public TestDataRelatedItem(@NotNull PsiMethod method, @NotNull Editor editor, @NotNull Collection testDataFiles) { - super(method); + super(method, "Test Data"); myMethod = method; myEditor = editor; myTestDataFiles.addAll(testDataFiles); diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/ui/TemplateCommentPanel.form b/plugins/copyright/src/com/maddyhome/idea/copyright/ui/TemplateCommentPanel.form index c4fe5a943446..6eaac456e205 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/ui/TemplateCommentPanel.form +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/ui/TemplateCommentPanel.form @@ -180,7 +180,7 @@ - + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java index 98358c2d2891..ca1e094f3b91 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java @@ -265,6 +265,12 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator { GrExpression qualifier = referenceExpression.getQualifierExpression(); if (qualifier == null && isDeclarationAssignment(referenceExpression)) return; + if (qualifier != null && referenceExpression.getDotTokenType() == GroovyTokenTypes.mMEMBER_POINTER) { + if (results.length > 0) { + return; + } + } + // If it is reference to map.key we shouldn't highlight key unresolved if (!(parent instanceof GrCall) && ResolveUtil.isKeyOfMap(referenceExpression)) { PsiElement refNameElement = referenceExpression.getReferenceNameElement(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyAssignabilityCheckInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyAssignabilityCheckInspection.java index d12ed7428ad5..6551ffc30a0c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyAssignabilityCheckInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyAssignabilityCheckInspection.java @@ -46,6 +46,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArg import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrThrowStatement; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.*; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty; @@ -349,6 +350,16 @@ public class GroovyAssignabilityCheckInspection extends BaseInspection { } } + @Override + public void visitThrowStatement(GrThrowStatement throwStatement) { + super.visitThrowStatement(throwStatement); + + final GrExpression exception = throwStatement.getException(); + if (exception != null) { + checkAssignability(PsiType.getJavaLangThrowable(throwStatement.getManager(), throwStatement.getResolveScope()), exception, exception); + } + } + private boolean checkLiteralConstructorApplicability(GroovyResolveResult result, GrListOrMap listOrMap, boolean checkUnknownArgs) { final PsiElement element = result.getElement(); LOG.assertTrue(element instanceof PsiMethod && ((PsiMethod)element).isConstructor()); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/projectView/MvcProjectViewPane.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/projectView/MvcProjectViewPane.java index 871ec1048af0..747e3399e63d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/projectView/MvcProjectViewPane.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/projectView/MvcProjectViewPane.java @@ -89,19 +89,6 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id myDescriptor = descriptor; myId = descriptor.getToolWindowId(); - myAutoScrollFromSourceHandler = new MyAutoScrollFromSourceHandler(); - myAutoScrollToSourceHandler = new AutoScrollToSourceHandler() { - @Override - protected boolean isAutoScrollMode() { - return myAutoScrollToSource; - } - - @Override - protected void setAutoScrollMode(boolean state) { - myAutoScrollToSource = state; - } - }; - class TreeUpdater implements Runnable, PsiModificationTracker.Listener { private volatile boolean myInQueue; @@ -127,6 +114,23 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id myComponent = createComponent(); DataManager.registerDataProvider(myComponent, this); + myAutoScrollFromSourceHandler = new MyAutoScrollFromSourceHandler(); + myAutoScrollToSourceHandler = new AutoScrollToSourceHandler() { + @Override + protected boolean isAutoScrollMode() { + return myAutoScrollToSource; + } + + @Override + protected void setAutoScrollMode(boolean state) { + myAutoScrollToSource = state; + } + }; + + myAutoScrollFromSourceHandler.install(); + myAutoScrollToSourceHandler.install(getTree()); + myAutoScrollToSourceHandler.onMouseClicked(getTree()); + myCopyPasteDelegator = new CopyPasteDelegator(project, myComponent) { @NotNull @Override @@ -166,15 +170,6 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id toolWindow.setTitleActions(new AnAction[]{new ScrollFromSourceAction(), collapseAction}); } - @Override - public JComponent createComponent() { - JComponent component = super.createComponent(); - myAutoScrollFromSourceHandler.install(); - myAutoScrollToSourceHandler.install(getTree()); - myAutoScrollToSourceHandler.onMouseClicked(getTree()); - return component; - } - public String getTitle() { throw new UnsupportedOperationException(); } @@ -462,7 +457,7 @@ public class MvcProjectViewPane extends AbstractProjectViewPSIPane implements Id private class MyAutoScrollFromSourceHandler extends AutoScrollFromSourceHandler { protected MyAutoScrollFromSourceHandler() { - super(MvcProjectViewPane.this.myProject, getTree(), MvcProjectViewPane.this); + super(MvcProjectViewPane.this.myProject, myComponent, MvcProjectViewPane.this); } @Override diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy index 40b5b5007a4b..2e24f7a14738 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy @@ -867,7 +867,7 @@ C< } public void testRawClosureReturnType() { - myFixture.configureByText('_.groovy', '''\ + testHighlighting('''\ class A { A(T t) {this.t = t} @@ -880,17 +880,17 @@ class A { def a = new A(new Date()) Date d = a.cl() -''') - testHighlighting(GroovyUncheckedAssignmentOfMemberOfRawTypeInspection) +''', GroovyUncheckedAssignmentOfMemberOfRawTypeInspection) } - private void testHighlighting(Class... inspections) { + private void testHighlighting(String text, Class... inspections) { + myFixture.configureByText('_.groovy', text) myFixture.enableInspections(inspections) myFixture.testHighlighting(true, false, true) } void testMethodRefs1() { - myFixture.configureByText('_.groovy', '''\ + testHighlighting('''\ class A { int foo(){2} @@ -903,12 +903,11 @@ int i = foo() int i2 = foo(2) Date d = foo(2) Date d2 = foo() -''') - testHighlighting(GroovyAssignabilityCheckInspection) +''', GroovyAssignabilityCheckInspection) } void testMethodRefs2() { - myFixture.configureByText('_.groovy', '''\ + testHighlighting('''\ class Bar { def foo(int i, String s2) {s2} def foo(int i, int i2) {i2} @@ -920,8 +919,21 @@ String s = cl("2") int s2 = cl("2") int i = cl(3) String i2 = cl(3) -''') - testHighlighting(GroovyAssignabilityCheckInspection) +''', GroovyAssignabilityCheckInspection) } + void testThrowObject() { + testHighlighting('''\ +def foo() { + throw new RuntimeException() +} +def bar () { + throw new Object() +} + +def test() { + throw new Throwable() +} +''', GroovyAssignabilityCheckInspection) + } } \ No newline at end of file diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.java index bcc84b3b09b0..b49a9a36c7dd 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.java @@ -236,7 +236,7 @@ public class FormatterTest extends GroovyFormatterTestCase { public void testGeese8() {doGeeseTest();} public void testMapInArgumentList() {doTest();} - public void testMapInArgumentList2() { + public void testMapInArgList2() { myTempSettings.getCustomSettings(GroovyCodeStyleSettings.class).ALIGN_NAMED_ARGS_IN_MAP = true; doTest(); } diff --git a/plugins/groovy/testdata/groovy/formatter/MapInArgumentList2.test b/plugins/groovy/testdata/groovy/formatter/mapInArgList2.test similarity index 100% rename from plugins/groovy/testdata/groovy/formatter/MapInArgumentList2.test rename to plugins/groovy/testdata/groovy/formatter/mapInArgList2.test diff --git a/plugins/java-i18n/src/com/intellij/codeInspection/i18n/JavaCreatePropertyFix.java b/plugins/java-i18n/src/com/intellij/codeInspection/i18n/JavaCreatePropertyFix.java index d32b9507e744..ff765b3736bc 100644 --- a/plugins/java-i18n/src/com/intellij/codeInspection/i18n/JavaCreatePropertyFix.java +++ b/plugins/java-i18n/src/com/intellij/codeInspection/i18n/JavaCreatePropertyFix.java @@ -18,11 +18,15 @@ package com.intellij.codeInspection.i18n; import com.intellij.lang.properties.psi.PropertiesFile; import com.intellij.lang.properties.references.CreatePropertyFix; import com.intellij.lang.properties.references.I18nizeQuickFixDialog; +import com.intellij.lang.properties.references.I18nizeQuickFixModel; +import com.intellij.openapi.application.AccessToken; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiLiteralExpression; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.*; +import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -32,19 +36,47 @@ import java.util.List; * @author Maxim.Mossienko */ public class JavaCreatePropertyFix extends CreatePropertyFix { + private static final Logger LOG = Logger.getInstance(JavaCreatePropertyFix.class); + public JavaCreatePropertyFix() {} public JavaCreatePropertyFix(PsiElement element, String key, final List propertiesFiles) { super(element, key, propertiesFiles); } + @Override + protected Pair doAction(Project project, PsiElement psiElement, I18nizeQuickFixModel model) { + final Pair result = super.doAction(project, psiElement, model); + if (result != null && psiElement instanceof PsiLiteralExpression) { + final String key = result.first; + + final StringBuilder buffer = new StringBuilder(); + buffer.append('"'); + StringUtil.escapeStringCharacters(key.length(), key, buffer); + buffer.append('"'); + + final AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(JavaCreatePropertyFix.class); + try { + final PsiExpression newKeyLiteral = JavaPsiFacade.getElementFactory(project).createExpressionFromText(buffer.toString(), null); + psiElement.replace(newKeyLiteral); + } + catch (IncorrectOperationException e) { + LOG.error(e); + } + finally { + token.finish(); + } + } + return result; + } + @Nullable - protected static Pair invokeAction(@NotNull final Project project, - @NotNull PsiFile file, - @NotNull PsiElement psiElement, - @Nullable final String suggestedKey, - @Nullable String suggestedValue, - @Nullable final List propertiesFiles) { + protected Pair invokeAction(@NotNull final Project project, + @NotNull PsiFile file, + @NotNull PsiElement psiElement, + @Nullable final String suggestedKey, + @Nullable String suggestedValue, + @Nullable final List propertiesFiles) { final PsiLiteralExpression literalExpression = psiElement instanceof PsiLiteralExpression ? (PsiLiteralExpression)psiElement : null; final String propertyValue = suggestedValue == null ? "" : suggestedValue; @@ -59,5 +91,4 @@ public class JavaCreatePropertyFix extends CreatePropertyFix { ); return doAction(project, psiElement, dialog); } - } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenProblemFileHighlighter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenProblemFileHighlighter.java index 3df60f79db24..20b2b3293c0b 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenProblemFileHighlighter.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenProblemFileHighlighter.java @@ -15,6 +15,8 @@ */ package org.jetbrains.idea.maven.utils; +import com.intellij.openapi.application.AccessToken; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Condition; import com.intellij.openapi.vfs.VirtualFile; @@ -30,7 +32,13 @@ public class MavenProblemFileHighlighter implements Condition { } public boolean value(final VirtualFile file) { - PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file); - return psiFile != null && MavenDomUtil.isMavenFile(psiFile); + AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); + try { + PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file); + return psiFile != null && MavenDomUtil.isMavenFile(psiFile); + } + finally { + accessToken.finish(); + } } } diff --git a/plugins/properties/src/com/intellij/lang/properties/references/CreatePropertyFix.java b/plugins/properties/src/com/intellij/lang/properties/references/CreatePropertyFix.java index b875f857999b..0a3fc8ef7b0d 100644 --- a/plugins/properties/src/com/intellij/lang/properties/references/CreatePropertyFix.java +++ b/plugins/properties/src/com/intellij/lang/properties/references/CreatePropertyFix.java @@ -88,11 +88,11 @@ public class CreatePropertyFix implements IntentionAction, LocalQuickFix { } @Nullable - private static Pair invokeAction(@NotNull final Project project, - @NotNull PsiFile file, - @NotNull PsiElement psiElement, - @Nullable final String suggestedKey, - @Nullable final List propertiesFiles) { + private Pair invokeAction(@NotNull final Project project, + @NotNull PsiFile file, + @NotNull PsiElement psiElement, + @Nullable final String suggestedKey, + @Nullable final List propertiesFiles) { final I18nizeQuickFixModel model; final I18nizeQuickFixDialog.DialogCustomization dialogCustomization = createDefaultCustomization(suggestedKey, propertiesFiles); @@ -128,8 +128,7 @@ public class CreatePropertyFix implements IntentionAction, LocalQuickFix { return new I18nizeQuickFixDialog.DialogCustomization(NAME, false, true, propertiesFiles, suggestedKey == null ? "" : suggestedKey); } - protected static Pair doAction(Project project, PsiElement psiElement, - I18nizeQuickFixModel model) { + protected Pair doAction(Project project, PsiElement psiElement, I18nizeQuickFixModel model) { if (!model.hasValidData()) { return null; } diff --git a/plugins/testng/src/com/theoryinpractice/testng/TestNGRelatedFilesProvider.java b/plugins/testng/src/com/theoryinpractice/testng/TestNGRelatedFilesProvider.java index abb1fa704081..927a81dbc402 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/TestNGRelatedFilesProvider.java +++ b/plugins/testng/src/com/theoryinpractice/testng/TestNGRelatedFilesProvider.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. @@ -84,7 +84,7 @@ public class TestNGRelatedFilesProvider extends GotoRelatedProvider { } if (!tags.isEmpty()) { - return GotoRelatedItem.createItems(tags); + return GotoRelatedItem.createItems(tags, "TestNG"); } } psiClass = PsiTreeUtil.getParentOfType(psiClass, PsiClass.class); diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormRelatedFilesProvider.java b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormRelatedFilesProvider.java index d4c5be1f7407..7918ace54c1d 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormRelatedFilesProvider.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/binding/FormRelatedFilesProvider.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. @@ -44,7 +44,7 @@ public class FormRelatedFilesProvider extends GotoRelatedProvider { while (psiClass != null) { List forms = FormClassIndex.findFormsBoundToClass(psiClass); if (!forms.isEmpty()) { - return GotoRelatedItem.createItems(forms); + return GotoRelatedItem.createItems(forms, "UI Forms"); } psiClass = PsiTreeUtil.getParentOfType(psiClass, PsiClass.class); } @@ -58,7 +58,7 @@ public class FormRelatedFilesProvider extends GotoRelatedProvider { Project project = file.getProject(); PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project)); if (aClass != null) { - return Collections.singletonList(new GotoRelatedItem(aClass)); + return Collections.singletonList(new GotoRelatedItem(aClass, "Java")); } } } diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index de479ae10723..cb3175edc39c 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -888,6 +888,7 @@ + diff --git a/xml/dom-openapi/src/com/intellij/codeInsight/navigation/DomGotoRelatedItem.java b/xml/dom-openapi/src/com/intellij/codeInsight/navigation/DomGotoRelatedItem.java index 9b699716ab0b..f58e0bc4f454 100644 --- a/xml/dom-openapi/src/com/intellij/codeInsight/navigation/DomGotoRelatedItem.java +++ b/xml/dom-openapi/src/com/intellij/codeInsight/navigation/DomGotoRelatedItem.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. @@ -17,7 +17,6 @@ package com.intellij.codeInsight.navigation; import com.intellij.navigation.GotoRelatedItem; import com.intellij.util.xml.DomElement; -import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -28,7 +27,15 @@ public class DomGotoRelatedItem extends GotoRelatedItem { private final DomElement myElement; public DomGotoRelatedItem(DomElement element) { - super(element.getXmlElement()); + this(element, "XML"); + } + + public DomGotoRelatedItem(DomElement element, String group) { + this(element, group, -1); + } + + public DomGotoRelatedItem(DomElement element, String group, int mnemonic) { + super(element.getXmlElement(), group, mnemonic); myElement = element; } diff --git a/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconBuilder.java b/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconBuilder.java index 60efe1dec69c..23324548e9f6 100644 --- a/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconBuilder.java +++ b/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 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. @@ -93,7 +93,7 @@ public class NavigationGutterIconBuilder { @NotNull @Override public Collection fun(PsiElement dom) { - return Collections.singletonList(new GotoRelatedItem(dom)); + return Collections.singletonList(new GotoRelatedItem(dom, "XML")); } }; diff --git a/xml/impl/src/com/intellij/navigation/HtmlGotoRelatedProvider.java b/xml/impl/src/com/intellij/navigation/HtmlGotoRelatedProvider.java index 5f4d850a5d94..7cb752134e56 100644 --- a/xml/impl/src/com/intellij/navigation/HtmlGotoRelatedProvider.java +++ b/xml/impl/src/com/intellij/navigation/HtmlGotoRelatedProvider.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. @@ -24,9 +24,9 @@ import com.intellij.psi.xml.XmlFile; import com.intellij.util.containers.HashSet; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Set; /** * Created by IntelliJ IDEA. @@ -44,10 +44,7 @@ public class HtmlGotoRelatedProvider extends GotoRelatedProvider { return Collections.emptyList(); } - HashSet resultSet = new HashSet(); - fillRelatedFiles(file, resultSet); - - return GotoRelatedItem.createItems(resultSet); + return getRelatedFiles(file); } private static boolean isAvailable(@NotNull PsiFile psiFile) { @@ -60,15 +57,22 @@ public class HtmlGotoRelatedProvider extends GotoRelatedProvider { return false; } - private static void fillRelatedFiles(@NotNull PsiFile file, @NotNull Set resultSet) { + private static List getRelatedFiles(@NotNull PsiFile file) { + List items = new ArrayList(); + for (PsiFile psiFile : file.getViewProvider().getAllFiles()) { if (psiFile instanceof XmlFile) { final XmlFile xmlFile = (XmlFile)psiFile; for (RelatedToHtmlFilesContributor contributor : RelatedToHtmlFilesContributor.EP_NAME.getExtensions()) { + HashSet resultSet = new HashSet(); contributor.fillRelatedFiles(xmlFile, resultSet); + for (PsiFile f: resultSet) { + items.add(new GotoRelatedItem(f, contributor.getGroupName())); + } } } } + return items; } } diff --git a/xml/impl/src/com/intellij/navigation/LinkedToHtmlFilesContributor.java b/xml/impl/src/com/intellij/navigation/LinkedToHtmlFilesContributor.java index 276171b544a5..86f83e98b48f 100644 --- a/xml/impl/src/com/intellij/navigation/LinkedToHtmlFilesContributor.java +++ b/xml/impl/src/com/intellij/navigation/LinkedToHtmlFilesContributor.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. @@ -67,4 +67,9 @@ public class LinkedToHtmlFilesContributor extends RelatedToHtmlFilesContributor } }); } + + @Override + public String getGroupName() { + return "Linked files"; + } } diff --git a/xml/impl/src/com/intellij/navigation/RelatedToHtmlFilesContributor.java b/xml/impl/src/com/intellij/navigation/RelatedToHtmlFilesContributor.java index dc27a3a7e019..5aef333823e7 100644 --- a/xml/impl/src/com/intellij/navigation/RelatedToHtmlFilesContributor.java +++ b/xml/impl/src/com/intellij/navigation/RelatedToHtmlFilesContributor.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. @@ -30,4 +30,5 @@ public abstract class RelatedToHtmlFilesContributor { ExtensionPointName.create("com.intellij.xml.relatedToHtmlFilesContributor"); public abstract void fillRelatedFiles(@NotNull XmlFile xmlFile, @NotNull Set resultSet); + public abstract String getGroupName(); }