From 7c8825d74f12e5411acfec1ced1d5d9851eebb6f Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Wed, 30 Jun 2010 15:55:48 +0400 Subject: [PATCH 01/18] common shortcuts - ctrl-n for insert on macs --- .../src/com/intellij/openapi/actionSystem/CommonShortcuts.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java index 92839d4c3540..115fa90883b9 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java @@ -32,7 +32,8 @@ public class CommonShortcuts { SystemInfo.isMac ? KeyEvent.META_DOWN_MASK : KeyEvent.CTRL_DOWN_MASK)); - public static final ShortcutSet INSERT = new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0)); + public static final ShortcutSet INSERT = new CustomShortcutSet(SystemInfo.isMac ? KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK) + : KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0)); public static final ShortcutSet DELETE = new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); public static final ShortcutSet ESCAPE = new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)); From f095abb770a9e77bf50fb3c25b0f02528ca79645 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Wed, 30 Jun 2010 16:54:11 +0400 Subject: [PATCH 02/18] tool window borders update --- .../platform-api/src/com/intellij/ui/tabs/impl/TabsBorder.java | 3 +-- .../com/intellij/ui/tabs/impl/singleRow/SingleRowLayout.java | 1 + .../src/com/intellij/ui/tabs/impl/table/TableLayout.java | 2 ++ .../src/com/intellij/openapi/wm/impl/InternalDecorator.java | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/TabsBorder.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/TabsBorder.java index 24ab9afb0239..284b5af47d20 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/TabsBorder.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/TabsBorder.java @@ -45,7 +45,7 @@ public class TabsBorder { myEffectiveBorder = null; - myTabs.revalidateAndRepaint(false); + myTabs.relayout(true, false); return myTabs; } @@ -77,7 +77,6 @@ public class TabsBorder { myPosition == JBTabsPosition.bottom ? myTabBorderSize : myBorderSize.bottom, myPosition == JBTabsPosition.right ? myTabBorderSize : myBorderSize.right ); - return (Insets)myEffectiveBorder.clone(); } } diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/SingleRowLayout.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/SingleRowLayout.java index d2f8096a0b84..876b06f794e2 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/SingleRowLayout.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/SingleRowLayout.java @@ -17,6 +17,7 @@ package com.intellij.ui.tabs.impl.singleRow; import com.intellij.ui.tabs.TabInfo; import com.intellij.ui.tabs.impl.*; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/table/TableLayout.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/table/TableLayout.java index b710c582b7dc..2efd1ec0d6b3 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/table/TableLayout.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/table/TableLayout.java @@ -128,6 +128,8 @@ public class TableLayout extends TabLayout { toAjust = true; } + toAjust |= myTabs.myForcedRelayout; + for (int i = 0; i < eachRow.myColumns.size(); i++) { TabInfo tabInfo = eachRow.myColumns.get(i); final TabLabel label = myTabs.myInfo2Label.get(tabInfo); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java index 2c59cb33fc98..f86abc0c1b11 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java @@ -463,7 +463,7 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa } if (insets.bottom > 0) { - UIUtil.drawLine(g, x + 1, y + height - 1, x + width - 1, y + height - 1); + UIUtil.drawLine(g, x, y + height - 1, x + width - 1, y + height - 1); } } From 7dc7a55f86134498ea6ce9e9b54a3524c7d4b33c Mon Sep 17 00:00:00 2001 From: "Kirill.Safonov" Date: Wed, 30 Jun 2010 17:38:28 +0400 Subject: [PATCH 03/18] trying not to loose history of renamed file - step 1 --- .../ExtractSuperBaseDialog.java | 22 ++++ .../JavaExtractSuperBaseDialog.java | 111 ------------------ 2 files changed, 22 insertions(+), 111 deletions(-) create mode 100644 java/java-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperBaseDialog.java delete mode 100644 java/java-impl/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java diff --git a/java/java-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperBaseDialog.java b/java/java-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperBaseDialog.java new file mode 100644 index 000000000000..eabd6e15b687 --- /dev/null +++ b/java/java-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperBaseDialog.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2009 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.refactoring.extractSuperclass; + +public class ExtractSuperBaseDialog { + // this is just a dummy content different enough from JavaExtractSuperBaseDialog, + // so that Git does not think that this class is a rename + +} diff --git a/java/java-impl/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java b/java/java-impl/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java deleted file mode 100644 index 9692c7ab597d..000000000000 --- a/java/java-impl/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.refactoring.extractSuperclass; - -import com.intellij.ide.util.PackageUtil; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.ProjectFileIndex; -import com.intellij.openapi.roots.ProjectRootManager; -import com.intellij.openapi.ui.ComponentWithBrowseButton; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.*; -import com.intellij.refactoring.RefactoringBundle; -import com.intellij.refactoring.ui.PackageNameReferenceEditorCombo; -import com.intellij.refactoring.util.RefactoringMessageUtil; -import com.intellij.refactoring.util.classMembers.MemberInfo; -import com.intellij.ui.EditorComboBox; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.List; - -/** - * @author dsl - */ -public abstract class JavaExtractSuperBaseDialog extends ExtractSuperBaseDialog { - private static final String DESTINATION_PACKAGE_RECENT_KEY = "ExtractSuperBase.RECENT_KEYS"; - - - public JavaExtractSuperBaseDialog(Project project, PsiClass sourceClass, List members, String refactoringName) { - super(project, sourceClass, members, refactoringName); - } - - protected ComponentWithBrowseButton createPackageNameField() { - String name = ""; - PsiFile file = mySourceClass.getContainingFile(); - if (file instanceof PsiJavaFile) { - name = ((PsiJavaFile)file).getPackageName(); - } - return new PackageNameReferenceEditorCombo(name, myProject, DESTINATION_PACKAGE_RECENT_KEY, - RefactoringBundle.message("choose.destination.package")); - } - - protected JTextField createSourceClassField() { - JTextField result = new JTextField(); - result.setEditable(false); - result.setText(mySourceClass.getQualifiedName()); - return result; - } - - private PsiDirectory getDirUnderSameSourceRoot(final PsiDirectory[] directories) { - final VirtualFile sourceFile = mySourceClass.getContainingFile().getVirtualFile(); - if (sourceFile != null) { - final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); - final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(sourceFile); - if (sourceRoot != null) { - for (PsiDirectory dir : directories) { - if (fileIndex.getSourceRootForFile(dir.getVirtualFile()) == sourceRoot) { - return dir; - } - } - } - } - return directories[0]; - } - - @Override - protected void preparePackage() throws OperationFailedException { - final PsiPackage aPackage = JavaPsiFacade.getInstance(myProject).findPackage(getTargetPackageName()); - if (aPackage != null) { - final PsiDirectory[] directories = aPackage.getDirectories(mySourceClass.getResolveScope()); - if (directories.length >= 1) { - myTargetDirectory = getDirUnderSameSourceRoot(directories); - } - } - myTargetDirectory - = PackageUtil.findOrCreateDirectoryForPackage(myProject, getTargetPackageName(), myTargetDirectory, true); - if (myTargetDirectory == null) { - throw new OperationFailedException(""); // message already reported by PackageUtil - } - String error = RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getExtractedSuperName()); - if (error != null) { - throw new OperationFailedException(error); - } - } - - @Override - protected String getDestinationPackageRecentKey() { - return DESTINATION_PACKAGE_RECENT_KEY; - } - - @Nullable - @Override - protected String validateName(String name) { - return JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(name) - ? null - : RefactoringMessageUtil.getIncorrectIdentifierMessage(name); - } -} From c103d24c6d4ebb7c5c122e66b2650b895acfb2c8 Mon Sep 17 00:00:00 2001 From: "Kirill.Safonov" Date: Wed, 30 Jun 2010 17:50:22 +0400 Subject: [PATCH 04/18] trying not to loose history of renamed file - step 2 --- ...xtractSuperBaseDialog.java => JavaExtractSuperBaseDialog.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename java/java-impl/src/com/intellij/refactoring/extractSuperclass/{ExtractSuperBaseDialog.java => JavaExtractSuperBaseDialog.java} (100%) diff --git a/java/java-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperBaseDialog.java b/java/java-impl/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java similarity index 100% rename from java/java-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperBaseDialog.java rename to java/java-impl/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java From 09357a9e373331cbda4c3cc1131565544a87b7aa Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Wed, 30 Jun 2010 18:30:04 +0400 Subject: [PATCH 05/18] splitter cursor fixes --- .../openapi/ui/ThreeComponentsSplitter.java | 24 ++++++++++++------- .../openapi/wm/impl/IdeGlassPaneImpl.java | 9 +++++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/ThreeComponentsSplitter.java b/platform/platform-api/src/com/intellij/openapi/ui/ThreeComponentsSplitter.java index 9215dff4a070..3df31fa81e07 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/ThreeComponentsSplitter.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/ThreeComponentsSplitter.java @@ -455,19 +455,27 @@ public class ThreeComponentsSplitter extends JPanel { } private boolean isInside(Point p) { + if (!isVisible()) return false; + if (myVerticalSplit) { - if (getHeight() > 0) { - return p.y >= 0 && p.y < getHeight(); - } else { - return p.y >= -myDividerZone / 2 && p.y <= myDividerZone / 2; + if (p.x >= 0 && p.x < getWidth()) { + if (getHeight() > 0) { + return p.y >= 0 && p.y < getHeight(); + } else { + return p.y >= -myDividerZone / 2 && p.y <= myDividerZone / 2; + } } } else { - if (getWidth() > 0) { - return p.x >= 0 && p.x < getWidth(); - } else { - return p.x >= -myDividerZone / 2 && p.x <= myDividerZone / 2; + if (p.y >= 0 && p.y < getHeight()) { + if (getWidth() > 0) { + return p.x >= 0 && p.x < getWidth(); + } else { + return p.x >= -myDividerZone / 2 && p.x <= myDividerZone / 2; + } } } + + return false; } private void init() { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java index 87938804d619..e6b386221a79 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeGlassPaneImpl.java @@ -136,9 +136,14 @@ public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEvent if (target != null) { if (myLastCursorComponent != target) { myLastCursorComponent = target; - myLastOriginalCursor = target.getCursor(); + if (target.isCursorSet()) { + myLastOriginalCursor = target.getCursor(); + } + } + + if (cursor != null && !cursor.equals(target.getCursor())) { + target.setCursor(cursor); } - target.setCursor(cursor); } getRootPane().setCursor(cursor); From 4b8e6adebd85dfea9cb3d77c9b2f76150c3d424c Mon Sep 17 00:00:00 2001 From: "Kirill.Safonov" Date: Wed, 30 Jun 2010 18:36:39 +0400 Subject: [PATCH 06/18] trying not to loose history of renamed file - step 3 --- .../JavaExtractSuperBaseDialog.java | 98 ++++++++++++++++++- 1 file changed, 94 insertions(+), 4 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java b/java/java-impl/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java index eabd6e15b687..c63f2d2c3988 100644 --- a/java/java-impl/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/extractSuperclass/JavaExtractSuperBaseDialog.java @@ -15,8 +15,98 @@ */ package com.intellij.refactoring.extractSuperclass; -public class ExtractSuperBaseDialog { - // this is just a dummy content different enough from JavaExtractSuperBaseDialog, - // so that Git does not think that this class is a rename +import com.intellij.ide.util.PackageUtil; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ProjectFileIndex; +import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.openapi.ui.ComponentWithBrowseButton; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.*; +import com.intellij.refactoring.RefactoringBundle; +import com.intellij.refactoring.ui.PackageNameReferenceEditorCombo; +import com.intellij.refactoring.util.RefactoringMessageUtil; +import com.intellij.refactoring.util.classMembers.MemberInfo; +import com.intellij.ui.EditorComboBox; +import org.jetbrains.annotations.Nullable; -} +import javax.swing.*; +import java.util.List; + +/** + * @author dsl + */ +public abstract class JavaExtractSuperBaseDialog extends ExtractSuperBaseDialog { + private static final String DESTINATION_PACKAGE_RECENT_KEY = "ExtractSuperBase.RECENT_KEYS"; + + + public JavaExtractSuperBaseDialog(Project project, PsiClass sourceClass, List members, String refactoringName) { + super(project, sourceClass, members, refactoringName); + } + + protected ComponentWithBrowseButton createPackageNameField() { + String name = ""; + PsiFile file = mySourceClass.getContainingFile(); + if (file instanceof PsiJavaFile) { + name = ((PsiJavaFile)file).getPackageName(); + } + return new PackageNameReferenceEditorCombo(name, myProject, DESTINATION_PACKAGE_RECENT_KEY, + RefactoringBundle.message("choose.destination.package")); + } + + protected JTextField createSourceClassField() { + JTextField result = new JTextField(); + result.setEditable(false); + result.setText(mySourceClass.getQualifiedName()); + return result; + } + + private PsiDirectory getDirUnderSameSourceRoot(final PsiDirectory[] directories) { + final VirtualFile sourceFile = mySourceClass.getContainingFile().getVirtualFile(); + if (sourceFile != null) { + final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); + final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(sourceFile); + if (sourceRoot != null) { + for (PsiDirectory dir : directories) { + if (fileIndex.getSourceRootForFile(dir.getVirtualFile()) == sourceRoot) { + return dir; + } + } + } + } + return directories[0]; + } + + + @Override + protected void preparePackage() throws OperationFailedException { + final PsiPackage aPackage = JavaPsiFacade.getInstance(myProject).findPackage(getTargetPackageName()); + if (aPackage != null) { + final PsiDirectory[] directories = aPackage.getDirectories(mySourceClass.getResolveScope()); + if (directories.length >= 1) { + myTargetDirectory = getDirUnderSameSourceRoot(directories); + } + } + myTargetDirectory + = PackageUtil.findOrCreateDirectoryForPackage(myProject, getTargetPackageName(), myTargetDirectory, true); + if (myTargetDirectory == null) { + throw new OperationFailedException(""); // message already reported by PackageUtil + } + String error = RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getExtractedSuperName()); + if (error != null) { + throw new OperationFailedException(error); + } + } + + @Override + protected String getDestinationPackageRecentKey() { + return DESTINATION_PACKAGE_RECENT_KEY; + } + + @Nullable + @Override + protected String validateName(String name) { + return JavaPsiFacade.getInstance(myProject).getNameHelper().isIdentifier(name) + ? null + : RefactoringMessageUtil.getIncorrectIdentifierMessage(name); + } +} \ No newline at end of file From 20818d3433c70cf32f4555d766784c29cf20594b Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Wed, 30 Jun 2010 18:51:28 +0400 Subject: [PATCH 07/18] JBScrollPane viewport border insets --- .../src/com/intellij/ui/components/JBScrollPane.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java b/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java index d91f1555447f..13a91ca6d0ad 100644 --- a/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java +++ b/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java @@ -18,6 +18,7 @@ package com.intellij.ui.components; import com.intellij.util.ui.ButtonlessScrollBarUI; import javax.swing.*; +import javax.swing.border.EmptyBorder; import javax.swing.plaf.ScrollPaneUI; import java.awt.*; @@ -46,6 +47,9 @@ public class JBScrollPane extends JScrollPane { */ public void setUI(ScrollPaneUI ui) { super.setUI(ui); + + setViewportBorder(new EmptyBorder(1, 1, 1, 1)); + // We need to set color of viewport later because UIManager // updates UI of scroll pane and only after that updates UI // of its children. To be the last in this sequence we need From ee0ae51110969fc25c2338e8f632f041838bf75a Mon Sep 17 00:00:00 2001 From: Gregory Shrago Date: Wed, 30 Jun 2010 20:45:15 +0400 Subject: [PATCH 08/18] ref search optimization --- .../PropertyReferenceViaLastWordSearcher.java | 63 +++++++------------ 1 file changed, 21 insertions(+), 42 deletions(-) diff --git a/plugins/properties/src/com/intellij/psi/impl/search/PropertyReferenceViaLastWordSearcher.java b/plugins/properties/src/com/intellij/psi/impl/search/PropertyReferenceViaLastWordSearcher.java index 34dea465eb47..54dd87a04e46 100644 --- a/plugins/properties/src/com/intellij/psi/impl/search/PropertyReferenceViaLastWordSearcher.java +++ b/plugins/properties/src/com/intellij/psi/impl/search/PropertyReferenceViaLastWordSearcher.java @@ -16,66 +16,45 @@ package com.intellij.psi.impl.search; import com.intellij.lang.properties.psi.Property; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.QueryExecutorBase; import com.intellij.openapi.fileTypes.StdFileTypes; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiManager; import com.intellij.psi.PsiReference; -import com.intellij.psi.ReferenceRange; -import com.intellij.psi.search.*; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.SearchScope; +import com.intellij.psi.search.UsageSearchContext; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.util.Processor; -import com.intellij.util.QueryExecutor; import java.util.List; /** * @author ven */ -public class PropertyReferenceViaLastWordSearcher implements QueryExecutor { +public class PropertyReferenceViaLastWordSearcher extends QueryExecutorBase { + public PropertyReferenceViaLastWordSearcher() { + super(true); + } + // add to the search results occurences in JSPs of the last word in the property name, since this stuff is possible: // q = ReferencesSearch.search(target, new LocalSearchScope(attr.getParent())); return !q.forEach(new Processor() { public boolean process(PsiReference psiReference) { @@ -71,4 +71,4 @@ public final class XsltImplicitUsagesProvider implements ImplicitUsageProvider { public boolean isImplicitWrite(PsiElement element) { return false; } -} \ No newline at end of file +} diff --git a/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefix.java b/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefix.java index 6d2edf4e65cd..ea463ed5c450 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefix.java +++ b/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefix.java @@ -18,6 +18,7 @@ package com.intellij.psi.impl.source.xml; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import com.intellij.psi.impl.RenameableFakePsiElement; +import com.intellij.psi.xml.XmlAttribute; import com.intellij.psi.xml.XmlElement; import com.intellij.util.Icons; @@ -26,47 +27,53 @@ import javax.swing.*; /** * @author Konstantin Bulenkov */ - public class SchemaPrefix extends RenameableFakePsiElement { - private final XmlElement myParent; - private final TextRange myRange; - private final String myName; +public class SchemaPrefix extends RenameableFakePsiElement { + private final XmlElement myParent; + private final TextRange myRange; + private final String myName; + private final XmlAttribute myDeclaration; - public SchemaPrefix(final XmlElement parent, TextRange range, String name) { - super(parent); - myParent = parent; - myRange = range; - myName = name; - } - - public String getTypeName() { - return "XML Namespace Prefix"; - } - - public Icon getIcon() { - return Icons.VARIABLE_ICON; - } - - @Override - public int getTextOffset() { - return myParent.getTextRange().getStartOffset() + myRange.getStartOffset(); - } - - @Override - public int getTextLength() { - return myName.length(); - } - - @Override - public String getName() { - return myName; - } - - public PsiElement getParent() { - return myParent; - } - - @Override - public TextRange getTextRange() { - return TextRange.from(getTextOffset(), getTextLength()); - } + public SchemaPrefix(final XmlElement parent, TextRange range, String name, XmlAttribute nsDeclaration) { + super(parent); + myParent = parent; + myRange = range; + myName = name; + myDeclaration = nsDeclaration; } + + public String getTypeName() { + return "XML Namespace Prefix"; + } + + public Icon getIcon() { + return Icons.VARIABLE_ICON; + } + + @Override + public int getTextOffset() { + return myParent.getTextRange().getStartOffset() + myRange.getStartOffset(); + } + + @Override + public int getTextLength() { + return myName.length(); + } + + @Override + public String getName() { + return myName; + } + + public PsiElement getParent() { + return myParent; + } + + public XmlAttribute getDeclaration() { + return myDeclaration; + } + + @Override + public TextRange getTextRange() { + return TextRange.from(getTextOffset(), getTextLength()); + } +} diff --git a/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefixReference.java b/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefixReference.java index b5bedaba0587..4a2d8ee29fc3 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefixReference.java +++ b/xml/impl/src/com/intellij/psi/impl/source/xml/SchemaPrefixReference.java @@ -33,20 +33,23 @@ public class SchemaPrefixReference extends PsiReferenceBase { private final SchemaPrefix myPrefix; private final PsiElement myElement; private final String myName; + private XmlElement myDeclaration = null; public SchemaPrefixReference(XmlElement element, TextRange range, String name) { super(element, range, true); myElement = element; myName = name; if (myElement instanceof XmlAttribute && ((XmlAttribute)myElement).isNamespaceDeclaration()) { - myPrefix = new SchemaPrefix(element, range, name); + myPrefix = new SchemaPrefix(element, range, name, (XmlAttribute)element); + myDeclaration = element; } else { - final PsiElement declaration = XmlUtil.findNamespaceDeclaration(element.getContainingFile(), name); + final PsiElement declaration = XmlUtil.findNamespaceDeclaration(element, name); if (declaration instanceof XmlAttribute) { final XmlAttribute attribute = (XmlAttribute)declaration; final String prefix = attribute.getNamespacePrefix(); final TextRange textRange = TextRange.from(prefix.length() + 1, name.length()); - myPrefix = new SchemaPrefix(attribute, textRange, name); + myPrefix = new SchemaPrefix(attribute, textRange, name, (XmlAttribute)declaration); + myDeclaration = (XmlElement)declaration; } else { myPrefix = null; } @@ -66,6 +69,7 @@ public class SchemaPrefixReference extends PsiReferenceBase { public boolean isReferenceTo(PsiElement element) { return element instanceof SchemaPrefix && element.getContainingFile() == myElement.getContainingFile() + && ((SchemaPrefix)element).getDeclaration() == myDeclaration && myName.equals(((SchemaPrefix)element).getName()) && myName.length() > 0; } diff --git a/xml/impl/src/com/intellij/xml/util/XmlUtil.java b/xml/impl/src/com/intellij/xml/util/XmlUtil.java index 503d5c09874d..4ee3c87690ee 100644 --- a/xml/impl/src/com/intellij/xml/util/XmlUtil.java +++ b/xml/impl/src/com/intellij/xml/util/XmlUtil.java @@ -530,18 +530,21 @@ public class XmlUtil { } @Nullable - public static PsiElement findNamespaceDeclaration(PsiFile xmlFile, String nsName) { - if (xmlFile instanceof XmlFile) { - final XmlDocument document = ((XmlFile)xmlFile).getDocument(); - if (document != null) { - final XmlTag rootTag = document.getRootTag(); - if (rootTag != null) { - for (XmlAttribute attribute : rootTag.getAttributes()) { - if (attribute.isNamespaceDeclaration() && attribute.getLocalName().equals(nsName)) { - return attribute; - } + public static PsiElement findNamespaceDeclaration(XmlElement xmlElement, String nsName) { + while (! (xmlElement instanceof XmlTag) && xmlElement != null) { + final PsiElement parent = xmlElement.getParent(); + if (!(parent instanceof XmlElement)) return null; + xmlElement = (XmlElement)parent; + } + if (xmlElement != null) { + XmlTag tag = (XmlTag)xmlElement; + while (tag != null) { + for (XmlAttribute attribute : tag.getAttributes()) { + if (attribute.isNamespaceDeclaration() && attribute.getLocalName().equals(nsName)) { + return attribute; } } + tag = tag.getParentTag(); } } return null; From 746facad4b16e626cb8bebc3242f3eef54799843 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 30 Jun 2010 20:20:50 +0400 Subject: [PATCH 10/18] AspectJ support for @interfaces in aspects AspectJ type parameters in aspects --- .../psi/impl/source/parsing/DeclarationParsing.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/java/java-impl/src/com/intellij/psi/impl/source/parsing/DeclarationParsing.java b/java/java-impl/src/com/intellij/psi/impl/source/parsing/DeclarationParsing.java index 2c15cf9eacae..95219c560609 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/parsing/DeclarationParsing.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/parsing/DeclarationParsing.java @@ -592,6 +592,19 @@ public class DeclarationParsing extends Parsing { return pair; } + public TreeElement parseAnnotationMemberValue(PsiManager manager, CharSequence text) { + Lexer originalLexer = new JavaLexer(myContext.getLanguageLevel()); + FilterLexer lexer = new FilterLexer(originalLexer, new FilterLexer.SetFilter(StdTokenSets.WHITE_SPACE_OR_COMMENT_BIT_SET)); + lexer.start(text); + final TreeElement result = parseAnnotationMemberValue(lexer); + + final FileElement dummyRoot = DummyHolderFactory.createHolder(manager, null, myContext.getCharTable()).getTreeElement(); + dummyRoot.rawAddChildren(result); + ParseUtil.insertMissingTokens(dummyRoot, originalLexer, 0, text.length(), -1, WhiteSpaceAndCommentsProcessor.INSTANCE, myContext); + + return result; + } + private TreeElement parseAnnotationMemberValue(Lexer lexer) { TreeElement result; if (lexer.getTokenType() == JavaTokenType.AT) { From bcd3dbc7c049823eab50f346ab361b3a9d064de2 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Wed, 30 Jun 2010 21:58:38 +0400 Subject: [PATCH 11/18] fixed bug in django formatter (PY-1160) --- .../formatter/xml/AbstractSyntheticBlock.java | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/xml/impl/src/com/intellij/psi/formatter/xml/AbstractSyntheticBlock.java b/xml/impl/src/com/intellij/psi/formatter/xml/AbstractSyntheticBlock.java index 055093e59822..5bb57c207c35 100644 --- a/xml/impl/src/com/intellij/psi/formatter/xml/AbstractSyntheticBlock.java +++ b/xml/impl/src/com/intellij/psi/formatter/xml/AbstractSyntheticBlock.java @@ -29,7 +29,7 @@ import com.intellij.psi.xml.XmlTag; import java.util.List; -public abstract class AbstractSyntheticBlock implements Block{ +public abstract class AbstractSyntheticBlock implements Block { protected final Indent myIndent; protected final XmlFormattingPolicy myXmlFormattingPolicy; protected final ASTNode myEndTreeNode; @@ -41,7 +41,15 @@ public abstract class AbstractSyntheticBlock implements Block{ myStartTreeNode = getFirstNode(subBlocks); myIndent = indent; myXmlFormattingPolicy = policy; - myTag = ((AbstractXmlBlock)parent).getTag(); + if (parent instanceof AbstractXmlBlock) { + myTag = ((AbstractXmlBlock)parent).getTag(); + } + else if (parent instanceof AbstractSyntheticBlock) { + myTag = ((AbstractSyntheticBlock)parent).getTag(); + } else { + throw new IllegalStateException("Parent should be AbstractXmlBlock or AbstractSyntheticBlock, but it is " + parent.getClass()); + } + } private static final Logger LOG = Logger.getInstance("#com.intellij.psi.formatter.xml.AbstractSyntheticBlock"); @@ -51,7 +59,8 @@ public abstract class AbstractSyntheticBlock implements Block{ final Block firstBlock = subBlocks.get(0); if (firstBlock instanceof AbstractBlock) { return ((AbstractBlock)firstBlock).getNode(); - } else { + } + else { return getFirstNode(firstBlock.getSubBlocks()); } } @@ -61,7 +70,8 @@ public abstract class AbstractSyntheticBlock implements Block{ final Block lastBlock = subBlocks.get(subBlocks.size() - 1); if (lastBlock instanceof AbstractBlock) { return ((AbstractBlock)lastBlock).getNode(); - } else { + } + else { return getLastNode(lastBlock.getSubBlocks()); } } @@ -90,7 +100,8 @@ public abstract class AbstractSyntheticBlock implements Block{ } public boolean endsWithText() { - return myEndTreeNode.getElementType() == XmlElementType.XML_TEXT || myEndTreeNode.getElementType() == XmlElementType.XML_DATA_CHARACTERS; + return myEndTreeNode.getElementType() == XmlElementType.XML_TEXT || + myEndTreeNode.getElementType() == XmlElementType.XML_DATA_CHARACTERS; } public boolean isTagDescription() { @@ -99,11 +110,13 @@ public abstract class AbstractSyntheticBlock implements Block{ } private static boolean isTagDescription(final ASTNode startTreeNode) { - return startTreeNode.getElementType() == XmlElementType.XML_START_TAG_START || startTreeNode.getElementType() == XmlElementType.XML_END_TAG_START; + return startTreeNode.getElementType() == XmlElementType.XML_START_TAG_START || + startTreeNode.getElementType() == XmlElementType.XML_END_TAG_START; } public boolean startsWithText() { - return myStartTreeNode.getElementType() == XmlElementType.XML_TEXT || myStartTreeNode.getElementType() == XmlElementType.XML_DATA_CHARACTERS; + return myStartTreeNode.getElementType() == XmlElementType.XML_TEXT || + myStartTreeNode.getElementType() == XmlElementType.XML_DATA_CHARACTERS; } public boolean endsWithTextElement() { @@ -136,7 +149,7 @@ public abstract class AbstractSyntheticBlock implements Block{ protected static TextRange calculateTextRange(final List subBlocks) { return new TextRange(subBlocks.get(0).getTextRange().getStartOffset(), - subBlocks.get(subBlocks.size()- 1).getTextRange().getEndOffset()); + subBlocks.get(subBlocks.size() - 1).getTextRange().getEndOffset()); } public boolean isIncomplete() { @@ -148,14 +161,14 @@ public abstract class AbstractSyntheticBlock implements Block{ } public XmlTag getStartTag() { - return (XmlTag)myStartTreeNode.getPsi(); + return (XmlTag)myStartTreeNode.getPsi(); } public boolean endsWithTag() { return isXmlTag(myEndTreeNode); } - + public boolean isJspTextBlock() { return false; } @@ -166,6 +179,7 @@ public abstract class AbstractSyntheticBlock implements Block{ /** * Checks if the block contains a single node which belongs to the outer (template) language. + * * @return True if it does, False otherwise. */ public boolean isOuterLanguageBlock() { From 7266cd54fbc6641bbcc6fed1782e9a6e50729d55 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Wed, 30 Jun 2010 22:42:59 +0400 Subject: [PATCH 12/18] fixed bug in django template formatter --- .../lang-impl/src/com/intellij/formatting/BlockDebugUtil.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/formatting/BlockDebugUtil.java b/platform/lang-impl/src/com/intellij/formatting/BlockDebugUtil.java index f76e2eb14be1..b1269b9cac32 100644 --- a/platform/lang-impl/src/com/intellij/formatting/BlockDebugUtil.java +++ b/platform/lang-impl/src/com/intellij/formatting/BlockDebugUtil.java @@ -15,9 +15,7 @@ */ package com.intellij.formatting; -import com.intellij.formatting.templateLanguages.DataLanguageBlockWrapper; import com.intellij.lang.ASTNode; -import com.intellij.psi.formatter.common.AbstractBlock; import java.io.PrintStream; import java.util.List; From 989d8306af5ab1f7843641a67ce4b4c2388938f5 Mon Sep 17 00:00:00 2001 From: Ekaterina Shliakhovetskaja Date: Thu, 1 Jul 2010 02:12:32 +0400 Subject: [PATCH 13/18] Spellchecker: update dictionary --- .../com/intellij/spellchecker/jetbrains.dic | 190 +++++++++++++++++- 1 file changed, 187 insertions(+), 3 deletions(-) diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic b/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic index fb9e26ab30dc..d34f3d052c74 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic +++ b/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic @@ -97,7 +97,8 @@ spellchecking Holdability permalink serializable -mutex, mutexes +mutex +mutexes arity unhandled trinary @@ -108,5 +109,188 @@ utf stylesheet charset vertices -println -encoded +commandline +cmdline +Petersburg +tokenize +vararg +sqlerror +pctused +maxtrans +nvarchar +localtimestamp +linestring +autoextend +inout +freepools +multipoint +unpivot +servererror +xmlschemas +middleint +infile +multiset +rowdependencies +systimestamp +outfile +likec +maxvalue +instantiable +timestamp +mediumtext +x509 +anyschema +desc +plsql +ccflags +asensitive +geometrycollection +varchar +xmlschema +dumpfile +tinytext +rtree +zerofill +btree +norely +binlog +float4 +float8 +schemas +innodb +novalidate +longtext +datafiles +resetlogs +substring +nullif +datetime +locator +charset +noarchivelog +norowdependencies +bool +nocopy +archivelog +processlist +mediumint +pipelined +serializable +ndbcluster +temptable +expr +keepduplicates +uninstall +sqlwarning +nomonitoring +maxdatafiles +filesystem +maxx +pctfree +notnull +maxlogfiles +fulltext +reindex +pctversion +clob +nocycle +maxloghistory +bigfile +bigint +nonschema +nomaxvalue +nominvalue +varray +isnull +sysdate +multipolygon +sqlcode +xmltype +pctthreshold +datafile +plsql +minvalue +noresetlogs +checksum +prebuilt +authid +nologging +nocache +plsql +bfile +timestamp +undofile +elsif +nocompress +deallocate +varcharacter +nodegroup +smallint +rlike +varchar +nomapping +varbinary +basicfile +noaudit +autocommit +deferrable +indextype +nchar +urowid +evex +rollup +minextents +online +sqlstate +deduplicate +controlfile +logoff +noparallel +subpartition +sqlexception +nosort +maxsize +maxinstances +capath +freelist +nclob +maxextents +binlog +plugins +mediumblob +pragma +logon +plsql +miny +localtime +mlslabel +noorder +tinyint +initrans +maxlogmembers +tinyblob +plsql +securefile +soname +oidindex +smallfile +stmt +tablespace +distinctrow +nowait +logfile +pctincrease +savepoint +freelists +autoincrement +longblob +autoextend +multilinestring +noreverse +calc +subpartitions +startup +elseif +configurator +django + From b318a99efe2b909b2c003eab4f4d226e2dde138d Mon Sep 17 00:00:00 2001 From: Ekaterina Shliakhovetskaja Date: Thu, 1 Jul 2010 02:13:34 +0400 Subject: [PATCH 14/18] Spellchecker: fix generics support in type tokenizer (IDEA-54464, IDEA-54431), add test cases --- .../spellchecker/DocCommentTokenizer.java | 14 +++++-- .../JavaSpellcheckingStrategy.java | 2 +- .../spellchecker/PsiTypeTokenizer.java | 13 ++++++- .../spellchecker/tokenizer/Token.java | 32 +++++++++++++--- .../testData/inspection/java/GenericTest.java | 37 ++++++++++++++++++ .../inspection/java/GenericTestt.java | 35 +++++++++++++++++ .../inspection/JavaSpellcheckingTest.java | 38 +++++++++++++++++++ 7 files changed, 160 insertions(+), 11 deletions(-) create mode 100644 plugins/spellchecker/testData/inspection/java/GenericTest.java create mode 100644 plugins/spellchecker/testData/inspection/java/GenericTestt.java create mode 100644 plugins/spellchecker/testSrc/com/intellij/spellchecker/inspection/JavaSpellcheckingTest.java diff --git a/plugins/java-i18n/src/com/intellij/spellchecker/DocCommentTokenizer.java b/plugins/java-i18n/src/com/intellij/spellchecker/DocCommentTokenizer.java index 5cd12f478bec..a661ec6957a4 100644 --- a/plugins/java-i18n/src/com/intellij/spellchecker/DocCommentTokenizer.java +++ b/plugins/java-i18n/src/com/intellij/spellchecker/DocCommentTokenizer.java @@ -22,12 +22,13 @@ import com.intellij.spellchecker.inspections.CommentSplitter; import com.intellij.spellchecker.inspections.SplitterFactory; import com.intellij.spellchecker.tokenizer.Token; import com.intellij.spellchecker.tokenizer.Tokenizer; +import com.intellij.util.containers.hash.HashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import java.util.Set; /** * Created by IntelliJ IDEA. @@ -36,8 +37,13 @@ import java.util.List; */ public class DocCommentTokenizer extends Tokenizer { - - private final String[] excludedTags = new String[]{"author", "link"}; + private static final Set excludedTags = new HashSet(); + { + excludedTags.add("author"); + excludedTags.add("see"); + excludedTags.add("by"); + excludedTags.add("link"); + } @Nullable @Override @@ -48,7 +54,7 @@ public class DocCommentTokenizer extends Tokenizer { for (PsiElement el : comment.getChildren()) { if (el instanceof PsiDocTag) { PsiDocTag tag = (PsiDocTag)el; - if (!Arrays.asList(excludedTags).contains(tag.getName())) { + if (!excludedTags.contains(tag.getName())) { for (PsiElement data : tag.getDataElements()) { result.add(new Token(data, splitter)); } diff --git a/plugins/java-i18n/src/com/intellij/spellchecker/JavaSpellcheckingStrategy.java b/plugins/java-i18n/src/com/intellij/spellchecker/JavaSpellcheckingStrategy.java index 43e35f2bbbeb..31b09c1a58b5 100644 --- a/plugins/java-i18n/src/com/intellij/spellchecker/JavaSpellcheckingStrategy.java +++ b/plugins/java-i18n/src/com/intellij/spellchecker/JavaSpellcheckingStrategy.java @@ -22,8 +22,8 @@ import com.intellij.psi.PsiLiteralExpression; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiNamedElement; import com.intellij.psi.javadoc.PsiDocComment; -import com.intellij.spellchecker.tokenizer.Tokenizer; import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy; +import com.intellij.spellchecker.tokenizer.Tokenizer; import org.jetbrains.annotations.NotNull; /** diff --git a/plugins/java-i18n/src/com/intellij/spellchecker/PsiTypeTokenizer.java b/plugins/java-i18n/src/com/intellij/spellchecker/PsiTypeTokenizer.java index c34df9034d4b..c7a7eeaea5a4 100644 --- a/plugins/java-i18n/src/com/intellij/spellchecker/PsiTypeTokenizer.java +++ b/plugins/java-i18n/src/com/intellij/spellchecker/PsiTypeTokenizer.java @@ -17,6 +17,7 @@ package com.intellij.spellchecker; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiTypeElement; @@ -49,6 +50,16 @@ public class PsiTypeTokenizer extends Tokenizer { final boolean isInSource = (virtualFile != null) && fileIndex.isInContent(virtualFile); - return !isInSource ? null : new Token[]{new Token(element, element.getText(), true, SplitterFactory.getInstance().getIdentifierSplitter())}; + return !isInSource + ? null + : new Token[]{ + new Token(element, element.getText(), true, 0, getRangeToCheck(element.getText(), psiClass.getName()), + SplitterFactory.getInstance().getIdentifierSplitter())}; + } + + @NotNull + private TextRange getRangeToCheck(@NotNull String text, @NotNull String name) { + final int i = text.indexOf(name); + return new TextRange(i, i + name.length()); } } \ No newline at end of file diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/tokenizer/Token.java b/plugins/spellchecker/src/com/intellij/spellchecker/tokenizer/Token.java index 50e36fde70e8..ad3b8f454dac 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/tokenizer/Token.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/tokenizer/Token.java @@ -15,9 +15,11 @@ */ package com.intellij.spellchecker.tokenizer; +import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import com.intellij.spellchecker.inspections.CheckArea; import com.intellij.spellchecker.inspections.Splitter; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -25,18 +27,24 @@ import java.util.List; public class Token { - private String text; - private String description; - private T element; - private boolean useRename; + private final String text; + private final String description; + private final boolean useRename; private int offset; + + + private final T element; private final Splitter splitter; + private TextRange range; + public Token(T element, String text, boolean useRename, Splitter splitter) { this.element = element; this.text = text; this.useRename = useRename; this.splitter = splitter; + this.offset = 0; + this.description = null; } public Token(T element, String text, boolean useRename, int offset, Splitter splitter) { @@ -52,6 +60,11 @@ public class Token { this(element, element.getText(), useRename, splitter); } + public Token(T element, String text, boolean useRename, int offset, TextRange textRange, Splitter splitter) { + this(element, text, useRename, offset, splitter); + this.range = textRange; + } + public String getText() { return text; } @@ -72,12 +85,21 @@ public class Token { return offset; } + @NotNull + public TextRange getRange() { + if (range==null){ + range = new TextRange(0,(text!=null?text.length():0)); + } + return range; + } @Nullable public List getAreas() { if (splitter == null || text == null) { return null; } - return splitter.split(text); + return splitter.split(text, getRange()); } + + } diff --git a/plugins/spellchecker/testData/inspection/java/GenericTest.java b/plugins/spellchecker/testData/inspection/java/GenericTest.java new file mode 100644 index 000000000000..537cd4295823 --- /dev/null +++ b/plugins/spellchecker/testData/inspection/java/GenericTest.java @@ -0,0 +1,37 @@ +public class GenericTest { + /** + @see com.intellij.openapi + */ + public void a( GenTest obj ) { + + } + + public void b( AnotherGenTest obj ) { + + } + + public void c( Predicate obj ) { + + } + + public void d( AnotherPredicate obj ) { + + } + + public class GenTest { + + } + + public class AnotherGenTest { + + } + + public interface Predicate { + + } + + public interface AnotherPredicate { + + } + +} diff --git a/plugins/spellchecker/testData/inspection/java/GenericTestt.java b/plugins/spellchecker/testData/inspection/java/GenericTestt.java new file mode 100644 index 000000000000..cd3981716509 --- /dev/null +++ b/plugins/spellchecker/testData/inspection/java/GenericTestt.java @@ -0,0 +1,35 @@ +public class GenericTestt { + + public void a( GenTestt obj ) { + + } + + public void b( AnotherGenTestt obj ) { + + } + + public void c( Predicatte obj ) { + + } + + public void d( AnotherPredicatte obj ) { + + } + + public class GenTestt { + + } + + public class AnotherGenTestt { + + } + + public interface Predicatte { + + } + + public interface AnotherPredicatte { + + } + +} diff --git a/plugins/spellchecker/testSrc/com/intellij/spellchecker/inspection/JavaSpellcheckingTest.java b/plugins/spellchecker/testSrc/com/intellij/spellchecker/inspection/JavaSpellcheckingTest.java new file mode 100644 index 000000000000..3d6ce4142f05 --- /dev/null +++ b/plugins/spellchecker/testSrc/com/intellij/spellchecker/inspection/JavaSpellcheckingTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2000-2009 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.spellchecker.inspection; + +import com.intellij.spellchecker.inspections.SpellCheckerInspectionToolProvider; + +/** + * Created by IntelliJ IDEA. + * User: Ekaterina Shliakhovetskaja + */ +public class JavaSpellcheckingTest extends SpellcheckerInspectionTestCase { + + + protected String getBasePath() { + return getSpellcheckerTestDataPath() + "/inspection/java"; + } + + public void testCorrectJava() throws Throwable { + doTest("GenericTest.java", SpellCheckerInspectionToolProvider.getInspectionTools()); + } + + public void testTypoInJava() throws Throwable { + doTest("GenericTestt.java", SpellCheckerInspectionToolProvider.getInspectionTools()); + } +} From 6562191907f6b8a13374374e4d2c77565d796978 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 1 Jul 2010 02:05:41 +0400 Subject: [PATCH 15/18] Don't ruin file encoding in code insight test fixture --- .../testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index a0cc7aea358c..1b97a5b626e9 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -1030,7 +1030,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig assertInitialized(); try { final OutputStream outputStream = copy.getOutputStream(null, 0, 0); - outputStream.write(loader.newFileText.getBytes()); + outputStream.write(loader.newFileText.getBytes(copy.getCharset())); outputStream.close(); } catch (IOException e) { From f4acb6140c56ce0ca51e75594925633bdda2d89c Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 1 Jul 2010 02:11:03 +0400 Subject: [PATCH 16/18] Language level of CE set to 1.6 (as in UE) --- .idea/misc.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 0b3844b53da6..a79bafffabe3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -27,7 +27,7 @@ - + From f72126361934bb5dbdc0145f59a402a5e41375d1 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 1 Jul 2010 02:13:50 +0400 Subject: [PATCH 17/18] Fix project encoding in Convert to Basic Latin intention test --- .../codeInsight/intention/ConvertToBasicLatinTest.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/intention/ConvertToBasicLatinTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/intention/ConvertToBasicLatinTest.java index 68a7eebb6085..3f9cc1c6907e 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/intention/ConvertToBasicLatinTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/intention/ConvertToBasicLatinTest.java @@ -14,18 +14,11 @@ * limitations under the License. */ -/* - * Created by IntelliJ IDEA. - * User: mike - * Date: Aug 22, 2002 - * Time: 2:58:42 PM - * To change template for new class use - * Code Style | Class Templates options (Tools | IDE Options). - */ package com.intellij.codeInsight.intention; import com.intellij.JavaTestUtil; import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.openapi.vfs.encoding.EncodingProjectManager; import com.intellij.testFramework.fixtures.CodeInsightTestUtil; import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase; @@ -38,6 +31,7 @@ public class ConvertToBasicLatinTest extends JavaCodeInsightFixtureTestCase { public void setUp() throws Exception { super.setUp(); myIntention = CodeInsightBundle.message("intention.convert.to.basic.latin"); + EncodingProjectManager.getInstance().setDefaultCharsetName("UTF-8"); } public void testConvertCharLiteral() throws Exception { From c830d83087bb36fed6e58e82e8609da6aba69d47 Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 1 Jul 2010 09:49:27 +0400 Subject: [PATCH 18/18] usages of OrderRootType.*CLASSES* migrated to new api --- .../compiler/ant/ModuleChunkClasspath.java | 216 +++++++++--------- .../impl/rmiCompiler/RmicCompiler.java | 40 +--- .../impl/CompilerModuleExtensionImpl.java | 58 +++-- .../intellij/roots/DependencyScopeTest.java | 71 +++--- .../com/intellij/roots/OrderEntriesTest.java | 2 +- .../src/com/intellij/psi/jsp/JspSpiUtil.java | 24 +- .../roots/CompilerModuleExtension.java | 4 + 7 files changed, 205 insertions(+), 210 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/ant/ModuleChunkClasspath.java b/java/compiler/impl/src/com/intellij/compiler/ant/ModuleChunkClasspath.java index d9ff911ebcb3..203d7b0e9f9b 100644 --- a/java/compiler/impl/src/com/intellij/compiler/ant/ModuleChunkClasspath.java +++ b/java/compiler/impl/src/com/intellij/compiler/ant/ModuleChunkClasspath.java @@ -24,6 +24,7 @@ import com.intellij.openapi.roots.*; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.util.ArrayUtil; +import com.intellij.util.Processor; import com.intellij.util.containers.OrderedSet; import gnu.trove.TObjectHashingStrategy; @@ -85,116 +86,103 @@ public class ModuleChunkClasspath extends Path { processedModules.add(module); final ProjectEx project = (ProjectEx)chunk.getProject(); final File baseDir = BuildProperties.getProjectBaseDir(project); - for (final OrderEntry orderEntry : ModuleRootManager.getInstance(module).getOrderEntries()) { - if (!orderEntry.isValid()) { - continue; - } - if (orderEntry instanceof ExportableOrderEntry) { - ExportableOrderEntry e = (ExportableOrderEntry)orderEntry; - switch (e.getScope()) { - case COMPILE: - break; - case PROVIDED: - if (generateRuntimeClasspath && !generateTestClasspath) { - continue; - } - break; - case RUNTIME: - if (!generateRuntimeClasspath) { - continue; - } - break; - case TEST: - if (!generateTestClasspath) { - continue; - } - break; - } - } - if (!generateRuntimeClasspath) { - // needed for compilation classpath only - if ((orderEntry instanceof ModuleSourceOrderEntry)) { - // this is the entry for outpath of the currently processed module - if (!generateTestClasspath && (dependencyLevel == 0 || chunk.contains(module))) { - // the root module is never included - continue; - } - } - else { - final boolean isExported = (orderEntry instanceof ExportableOrderEntry) && ((ExportableOrderEntry)orderEntry).isExported(); - if (dependencyLevel > 0 && !isExported) { - if (!(orderEntry instanceof ModuleOrderEntry)) { - // non-exported dependencies are excluded and not processed - continue; - } - } - } - } - if (orderEntry instanceof JdkOrderEntry) { - if (genOptions.forceTargetJdk && !generateRuntimeClasspath) { - pathItems - .add(new PathRefItem(BuildProperties.propertyRef(BuildProperties.getModuleChunkJdkClasspathProperty(chunk.getName())))); - } - } - else if (orderEntry instanceof ModuleOrderEntry) { - final ModuleOrderEntry moduleOrderEntry = (ModuleOrderEntry)orderEntry; - final Module dependentModule = moduleOrderEntry.getModule(); - if (!chunk.contains(dependentModule)) { - if (generateRuntimeClasspath && !genOptions.inlineRuntimeClasspath) { - // in case of runtime classpath, just an referenced to corresponding classpath is created - final ModuleChunk depChunk = genOptions.getChunkByModule(dependentModule); - if (!processedChunks.contains(depChunk)) { - // chunk references are included in the runtime classpath only once - processedChunks.add(depChunk); - String property = generateTestClasspath ? BuildProperties.getTestRuntimeClasspathProperty(depChunk.getName()) - : BuildProperties.getRuntimeClasspathProperty(depChunk.getName()); - pathItems.add(new PathRefItem(property)); - } - } - else { - // in case of compile classpath or inlined runtime classpath, - // the referenced module is processed recursively - processModule(dependentModule, dependencyLevel + 1, moduleOrderEntry.isExported()); - } - } - } - else if (orderEntry instanceof LibraryOrderEntry) { - final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)orderEntry; - final String libraryName = libraryOrderEntry.getLibraryName(); - if (((LibraryOrderEntry)orderEntry).isModuleLevel()) { - CompositeGenerator gen = new CompositeGenerator(); - gen.setHasLeadingNewline(false); - LibraryDefinitionsGeneratorFactory.genLibraryContent(project, genOptions, libraryOrderEntry.getLibrary(), baseDir, gen); - pathItems.add(new GeneratorItem(libraryName, gen)); - } - else { - pathItems.add(new PathRefItem(BuildProperties.getLibraryPathId(libraryName))); - } - } - else if (orderEntry instanceof ModuleSourceOrderEntry) { - // Module source entry? - for (String url : getCompilationClasses(orderEntry, ((GenerationOptionsImpl)genOptions), generateRuntimeClasspath, - generateTestClasspath, dependencyLevel == 0)) { - if (url.endsWith(JarFileSystem.JAR_SEPARATOR)) { - url = url.substring(0, url.length() - JarFileSystem.JAR_SEPARATOR.length()); - } - final String propertyRef = genOptions.getPropertyRefForUrl(url); - if (propertyRef != null) { - pathItems.add(new PathElementItem(propertyRef)); - } - else { - final String path = VirtualFileManager.extractPath(url); - pathItems.add(new PathElementItem( - GenerationUtils.toRelativePath(path, chunk.getBaseDir(), moduleChunkBasedirProperty, genOptions))); - } - } - } - else { - // Unknown order entry type. If it is actually encountered, extension point should be implemented - pathItems.add(new GeneratorItem(orderEntry.getClass().getName(), - new Comment("Unknown OrderEntryType: " + orderEntry.getClass().getName()))); + OrderEnumerator enumerator = ModuleRootManager.getInstance(module).orderEntries(); + if (generateRuntimeClasspath) { + enumerator = enumerator.runtimeOnly(); + } + else { + enumerator = enumerator.compileOnly(); + if (!generateTestClasspath && (dependencyLevel == 0 || chunk.contains(module))) { + // this is the entry for outpath of the currently processed module + // the root module is never included + enumerator = enumerator.withoutModuleSourceEntries(); } } + if (!generateTestClasspath) { + enumerator = enumerator.productionOnly(); + } + enumerator.forEach(new Processor() { + @Override + public boolean process(OrderEntry orderEntry) { + if (!orderEntry.isValid()) { + return true; + } + + if (!generateRuntimeClasspath && !(orderEntry instanceof ModuleOrderEntry)) { + // needed for compilation classpath only + final boolean isExported = (orderEntry instanceof ExportableOrderEntry) && ((ExportableOrderEntry)orderEntry).isExported(); + if (dependencyLevel > 0 && !isExported) { + // non-exported dependencies are excluded and not processed + return true; + } + } + + if (orderEntry instanceof JdkOrderEntry) { + if (genOptions.forceTargetJdk && !generateRuntimeClasspath) { + pathItems.add(new PathRefItem(BuildProperties.propertyRef(BuildProperties.getModuleChunkJdkClasspathProperty(chunk.getName())))); + } + } + else if (orderEntry instanceof ModuleOrderEntry) { + final ModuleOrderEntry moduleOrderEntry = (ModuleOrderEntry)orderEntry; + final Module dependentModule = moduleOrderEntry.getModule(); + if (!chunk.contains(dependentModule)) { + if (generateRuntimeClasspath && !genOptions.inlineRuntimeClasspath) { + // in case of runtime classpath, just an referenced to corresponding classpath is created + final ModuleChunk depChunk = genOptions.getChunkByModule(dependentModule); + if (!processedChunks.contains(depChunk)) { + // chunk references are included in the runtime classpath only once + processedChunks.add(depChunk); + String property = generateTestClasspath ? BuildProperties.getTestRuntimeClasspathProperty(depChunk.getName()) + : BuildProperties.getRuntimeClasspathProperty(depChunk.getName()); + pathItems.add(new PathRefItem(property)); + } + } + else { + // in case of compile classpath or inlined runtime classpath, + // the referenced module is processed recursively + processModule(dependentModule, dependencyLevel + 1, moduleOrderEntry.isExported()); + } + } + } + else if (orderEntry instanceof LibraryOrderEntry) { + final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)orderEntry; + final String libraryName = libraryOrderEntry.getLibraryName(); + if (((LibraryOrderEntry)orderEntry).isModuleLevel()) { + CompositeGenerator gen = new CompositeGenerator(); + gen.setHasLeadingNewline(false); + LibraryDefinitionsGeneratorFactory.genLibraryContent(project, genOptions, libraryOrderEntry.getLibrary(), baseDir, gen); + pathItems.add(new GeneratorItem(libraryName, gen)); + } + else { + pathItems.add(new PathRefItem(BuildProperties.getLibraryPathId(libraryName))); + } + } + else if (orderEntry instanceof ModuleSourceOrderEntry) { + // Module source entry? + for (String url : getCompilationClasses(module, ((GenerationOptionsImpl)genOptions), generateRuntimeClasspath, + generateTestClasspath, dependencyLevel == 0)) { + if (url.endsWith(JarFileSystem.JAR_SEPARATOR)) { + url = url.substring(0, url.length() - JarFileSystem.JAR_SEPARATOR.length()); + } + final String propertyRef = genOptions.getPropertyRefForUrl(url); + if (propertyRef != null) { + pathItems.add(new PathElementItem(propertyRef)); + } + else { + final String path = VirtualFileManager.extractPath(url); + pathItems.add(new PathElementItem( + GenerationUtils.toRelativePath(path, chunk.getBaseDir(), moduleChunkBasedirProperty, genOptions))); + } + } + } + else { + // Unknown order entry type. If it is actually encountered, extension point should be implemented + pathItems.add(new GeneratorItem(orderEntry.getClass().getName(), + new Comment("Unknown OrderEntryType: " + orderEntry.getClass().getName()))); + } + return true; + } + }); } }.processModule(module, 0, false); } @@ -225,24 +213,26 @@ public class ModuleChunkClasspath extends Path { } } - private static String[] getCompilationClasses(final OrderEntry orderEntry, + private static String[] getCompilationClasses(final Module module, final GenerationOptionsImpl options, final boolean forRuntime, final boolean forTest, final boolean firstLevel) { + final CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module); + if (extension == null) return ArrayUtil.EMPTY_STRING_ARRAY; + if (!forRuntime) { if (forTest) { - return orderEntry.getUrls(firstLevel ? OrderRootType.PRODUCTION_COMPILATION_CLASSES : OrderRootType.COMPILATION_CLASSES); + return extension.getOutputRootUrls(!firstLevel); } else { - return firstLevel ? new String[0] : orderEntry.getUrls(OrderRootType.PRODUCTION_COMPILATION_CLASSES); + return firstLevel ? ArrayUtil.EMPTY_STRING_ARRAY : extension.getOutputRootUrls(false); } } final Set jdkUrls = options.getAllJdkUrls(); final OrderedSet urls = new OrderedSet(); - urls.addAll(Arrays.asList(orderEntry.getUrls(forTest ? OrderRootType.COMPILATION_CLASSES - : OrderRootType.PRODUCTION_COMPILATION_CLASSES))); + urls.addAll(Arrays.asList(extension.getOutputRootUrls(forTest))); urls.removeAll(jdkUrls); return ArrayUtil.toStringArray(urls); } diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/rmiCompiler/RmicCompiler.java b/java/compiler/impl/src/com/intellij/compiler/impl/rmiCompiler/RmicCompiler.java index 04972a1e68f3..7b25a94add96 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/rmiCompiler/RmicCompiler.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/rmiCompiler/RmicCompiler.java @@ -31,7 +31,10 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.roots.*; +import com.intellij.openapi.roots.ModuleRootManager; +import com.intellij.openapi.roots.OrderEnumerator; +import com.intellij.openapi.roots.ProjectFileIndex; +import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; @@ -39,8 +42,7 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; -import com.intellij.util.PathUtil; -import com.intellij.util.StringBuilderSpinAllocator; +import com.intellij.util.PathsList; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -385,35 +387,9 @@ public class RmicCompiler implements ClassPostProcessingCompiler{ } private static String getCompilationClasspath(Module module) { - final StringBuilder classpathBuffer = StringBuilderSpinAllocator.alloc(); - try { - final OrderEntry[] orderEntries = ModuleRootManager.getInstance(module).getOrderEntries(); - final Set processedFiles = new HashSet(); - for (final OrderEntry orderEntry : orderEntries) { - if (orderEntry instanceof JdkOrderEntry) { - continue; - } - final VirtualFile[] files = orderEntry.getFiles(OrderRootType.COMPILATION_CLASSES); - for (VirtualFile file : files) { - if (processedFiles.contains(file)) { - continue; - } - processedFiles.add(file); - final String path = PathUtil.getLocalPath(file); - if (path == null) { - continue; - } - if (classpathBuffer.length() > 0) { - classpathBuffer.append(File.pathSeparatorChar); - } - classpathBuffer.append(path); - } - } - return classpathBuffer.toString(); - } - finally { - StringBuilderSpinAllocator.dispose(classpathBuffer); - } + final OrderEnumerator enumerator = ModuleRootManager.getInstance(module).orderEntries().withoutSdk().compileOnly().recursively().exportedOnly(); + final PathsList pathsList = enumerator.getPathsList(); + return pathsList.getPathsString(); } private static final class RemoteClassValidityState implements ValidityState { diff --git a/java/java-impl/src/com/intellij/openapi/roots/impl/CompilerModuleExtensionImpl.java b/java/java-impl/src/com/intellij/openapi/roots/impl/CompilerModuleExtensionImpl.java index 07493a68eeba..bebc8d23bd9e 100644 --- a/java/java-impl/src/com/intellij/openapi/roots/impl/CompilerModuleExtensionImpl.java +++ b/java/java-impl/src/com/intellij/openapi/roots/impl/CompilerModuleExtensionImpl.java @@ -299,40 +299,50 @@ public class CompilerModuleExtensionImpl extends CompilerModuleExtension { if (OrderRootType.CLASSES_AND_OUTPUT.equals(type) || OrderRootType.COMPILATION_CLASSES.equals(type) || OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type)) { - final ArrayList result = new ArrayList(); - - final VirtualFile outputPathForTests = OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type) ? null : getCompilerOutputPathForTests(); - if (outputPathForTests != null) { - result.add(outputPathForTests); - } - - VirtualFile outputRoot = getCompilerOutputPath(); - if (outputRoot != null && !outputRoot.equals(outputPathForTests)) { - result.add(outputRoot); - } - return VfsUtil.toVirtualFileArray(result); + return getOutputRoots(!OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type)); } return null; } + @Override + public VirtualFile[] getOutputRoots(final boolean includeTests) { + final ArrayList result = new ArrayList(); + + final VirtualFile outputPathForTests = includeTests ? getCompilerOutputPathForTests() : null; + if (outputPathForTests != null) { + result.add(outputPathForTests); + } + + VirtualFile outputRoot = getCompilerOutputPath(); + if (outputRoot != null && !outputRoot.equals(outputPathForTests)) { + result.add(outputRoot); + } + return VfsUtil.toVirtualFileArray(result); + } + @Override public String[] getRootUrls(final OrderRootType type) { if (OrderRootType.CLASSES_AND_OUTPUT.equals(type) || OrderRootType.COMPILATION_CLASSES.equals(type) || OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type)) { - final List result = new ArrayList(); - - final String outputPathForTests = OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type) ? null : getCompilerOutputUrlForTests(); - if (outputPathForTests != null) { - result.add(outputPathForTests); - } - - String outputRoot = getCompilerOutputUrl(); - if (outputRoot != null && !outputRoot.equals(outputPathForTests)) { - result.add(outputRoot); - } - return ArrayUtil.toStringArray(result); + return getOutputRootUrls(!OrderRootType.PRODUCTION_COMPILATION_CLASSES.equals(type)); } return null; } + + @Override + public String[] getOutputRootUrls(final boolean includeTests) { + final List result = new ArrayList(); + + final String outputPathForTests = includeTests ? getCompilerOutputUrlForTests() : null; + if (outputPathForTests != null) { + result.add(outputPathForTests); + } + + String outputRoot = getCompilerOutputUrl(); + if (outputRoot != null && !outputRoot.equals(outputPathForTests)) { + result.add(outputRoot); + } + return ArrayUtil.toStringArray(result); + } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/roots/DependencyScopeTest.java b/java/java-tests/testSrc/com/intellij/roots/DependencyScopeTest.java index f4286ff0f794..5bb5646847db 100644 --- a/java/java-tests/testSrc/com/intellij/roots/DependencyScopeTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/DependencyScopeTest.java @@ -10,6 +10,7 @@ import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl; import com.intellij.util.PathsList; import java.io.IOException; +import java.util.Collection; /** * @author yole @@ -38,10 +39,10 @@ public class DependencyScopeTest extends ModuleTestCase { assertFalse(moduleA.getModuleWithDependenciesAndLibrariesScope(false).contains(classB)); assertFalse(moduleA.getModuleWithDependenciesAndLibrariesScope(false).isSearchInModuleContent(moduleB)); - final VirtualFile[] compilationClasspath = ModuleRootManager.getInstance(moduleA).getFiles(OrderRootType.COMPILATION_CLASSES); - assertEquals(1, compilationClasspath.length); - final VirtualFile[] productionCompilationClasspath = ModuleRootManager.getInstance(moduleA).getFiles(OrderRootType.PRODUCTION_COMPILATION_CLASSES); - assertEquals(0, productionCompilationClasspath.length); + final Collection compilationClasspath = getCompilationClasspath(moduleA); + assertEquals(1, compilationClasspath.size()); + final Collection productionCompilationClasspath = getProductionCompileClasspath(moduleA); + assertEmpty(productionCompilationClasspath); final PathsList pathsList = OrderEnumerator.orderEntries(moduleA).recursively().getPathsList(); assertEquals(1, pathsList.getPathList().size()); @@ -77,35 +78,34 @@ public class DependencyScopeTest extends ModuleTestCase { assertTrue(m.getModuleWithDependenciesAndLibrariesScope(true).contains(libraryClass)); assertFalse(m.getModuleWithDependenciesAndLibrariesScope(false).contains(libraryClass)); - final VirtualFile[] compilationClasspath = ModuleRootManager.getInstance(m).getFiles(OrderRootType.COMPILATION_CLASSES); - assertEquals(1, compilationClasspath.length); - final VirtualFile[] productionCompilationClasspath = ModuleRootManager.getInstance(m).getFiles(OrderRootType.PRODUCTION_COMPILATION_CLASSES); - assertEquals(0, productionCompilationClasspath.length); + final Collection compilationClasspath = getCompilationClasspath(m); + assertEquals(1, compilationClasspath.size()); + final Collection productionCompilationClasspath = getProductionCompileClasspath(m); + assertEmpty(productionCompilationClasspath); } public void testRuntimeModuleDependency() throws IOException { Module moduleA = createModule("a.iml", StdModuleTypes.JAVA); addDependentModule(moduleA, DependencyScope.RUNTIME); - final VirtualFile[] runtimeClasspath = ModuleRootManager.getInstance(moduleA).getFiles(OrderRootType.CLASSES_AND_OUTPUT); - assertEquals(1, runtimeClasspath.length); - final VirtualFile[] compilationClasspath = ModuleRootManager.getInstance(moduleA).getFiles(OrderRootType.COMPILATION_CLASSES); - assertEquals(1, compilationClasspath.length); - VirtualFile[] production = ModuleRootManager.getInstance(moduleA).getFiles(OrderRootType.PRODUCTION_COMPILATION_CLASSES); - assertEquals(0, production.length); + final Collection runtimeClasspath = getRuntimeClasspath(moduleA); + assertEquals(1, runtimeClasspath.size()); + final Collection compilationClasspath = getCompilationClasspath(moduleA); + assertEquals(1, compilationClasspath.size()); + Collection production = getProductionCompileClasspath(moduleA); + assertEmpty(production); } public void testRuntimeLibraryDependency() throws IOException { Module m = createModule("a.iml", StdModuleTypes.JAVA); VirtualFile libraryRoot = addLibrary(m, DependencyScope.RUNTIME); - final VirtualFile[] runtimeClasspath = ModuleRootManager.getInstance(m).getFiles(OrderRootType.CLASSES_AND_OUTPUT); - assertEquals(1, runtimeClasspath.length); - assertEquals(libraryRoot, runtimeClasspath [0]); + final Collection runtimeClasspath = getRuntimeClasspath(m); + assertOrderedEquals(runtimeClasspath, libraryRoot); - final VirtualFile[] compilationClasspath = ModuleRootManager.getInstance(m).getFiles(OrderRootType.COMPILATION_CLASSES); - assertEquals(1, compilationClasspath.length); - VirtualFile[] production = ModuleRootManager.getInstance(m).getFiles(OrderRootType.PRODUCTION_COMPILATION_CLASSES); - assertEquals(0, production.length); + final Collection compilationClasspath = getCompilationClasspath(m); + assertEquals(1, compilationClasspath.size()); + Collection production = getProductionCompileClasspath(m); + assertEmpty(production); VirtualFile libraryClass = myFixture.createFile("lib/Test.java", "public class Test { }"); assertTrue(m.getModuleWithDependenciesAndLibrariesScope(true).contains(libraryClass)); @@ -115,28 +115,39 @@ public class DependencyScopeTest extends ModuleTestCase { public void testProvidedModuleDependency() throws IOException { Module moduleA = createModule("a.iml", StdModuleTypes.JAVA); addDependentModule(moduleA, DependencyScope.PROVIDED); - final VirtualFile[] runtimeClasspath = ModuleRootManager.getInstance(moduleA).getFiles(OrderRootType.CLASSES_AND_OUTPUT); - assertEquals(0, runtimeClasspath.length); - final VirtualFile[] compilationClasspath = ModuleRootManager.getInstance(moduleA).getFiles(OrderRootType.COMPILATION_CLASSES); - assertEquals(1, compilationClasspath.length); + Collection runtimeClasspath = getRuntimeClasspath(moduleA); + assertEmpty(runtimeClasspath); + final Collection compilationClasspath = getCompilationClasspath(moduleA); + assertEquals(1, compilationClasspath.size()); } public void testProvidedLibraryDependency() throws IOException { Module m = createModule("a.iml", StdModuleTypes.JAVA); VirtualFile libraryRoot = addLibrary(m, DependencyScope.PROVIDED); - final VirtualFile[] runtimeClasspath = ModuleRootManager.getInstance(m).getFiles(OrderRootType.CLASSES_AND_OUTPUT); - assertEquals(0, runtimeClasspath.length); + final Collection runtimeClasspath = getRuntimeClasspath(m); + assertEmpty(runtimeClasspath); - final VirtualFile[] compilationClasspath = ModuleRootManager.getInstance(m).getFiles(OrderRootType.COMPILATION_CLASSES); - assertEquals(1, compilationClasspath.length); - assertEquals(libraryRoot, compilationClasspath [0]); + final Collection compilationClasspath = getCompilationClasspath(m); + assertOrderedEquals(compilationClasspath, libraryRoot); VirtualFile libraryClass = myFixture.createFile("lib/Test.java", "public class Test { }"); assertTrue(m.getModuleWithDependenciesAndLibrariesScope(true).contains(libraryClass)); assertTrue(m.getModuleWithDependenciesAndLibrariesScope(false).contains(libraryClass)); } + private static Collection getRuntimeClasspath(Module m) { + return ModuleRootManager.getInstance(m).orderEntries().productionOnly().runtimeOnly().recursively().getClassesRoots(); + } + + private static Collection getProductionCompileClasspath(Module moduleA) { + return ModuleRootManager.getInstance(moduleA).orderEntries().productionOnly().compileOnly().recursively().exportedOnly().getClassesRoots(); + } + + private static Collection getCompilationClasspath(Module m) { + return ModuleRootManager.getInstance(m).orderEntries().recursively().exportedOnly().getClassesRoots(); + } + private VirtualFile addLibrary(Module m, final DependencyScope scope) { VirtualFile libraryRoot = myFixture.findOrCreateDir("lib"); diff --git a/java/java-tests/testSrc/com/intellij/roots/OrderEntriesTest.java b/java/java-tests/testSrc/com/intellij/roots/OrderEntriesTest.java index bb36326f98f8..f9412ed323ec 100644 --- a/java/java-tests/testSrc/com/intellij/roots/OrderEntriesTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/OrderEntriesTest.java @@ -98,7 +98,7 @@ public class OrderEntriesTest extends ModuleRootManagerTestCase { return base.recursively().exportedOnly().getPathsList(); } if (type == OrderRootType.PRODUCTION_COMPILATION_CLASSES) { - return base.productionOnly().recursively().exportedOnly().getPathsList(); + return base.productionOnly().compileOnly().recursively().exportedOnly().getPathsList(); } if (type == OrderRootType.CLASSES) { return base.withoutModuleSourceEntries().recursively().exportedOnly().getPathsList(); diff --git a/java/jsp-spi/src/com/intellij/psi/jsp/JspSpiUtil.java b/java/jsp-spi/src/com/intellij/psi/jsp/JspSpiUtil.java index 35e5b4080a67..542fdd95908e 100644 --- a/java/jsp-spi/src/com/intellij/psi/jsp/JspSpiUtil.java +++ b/java/jsp-spi/src/com/intellij/psi/jsp/JspSpiUtil.java @@ -19,7 +19,7 @@ import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; import com.intellij.openapi.roots.ModuleRootManager; -import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.roots.OrderEnumerator; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; @@ -138,37 +138,41 @@ public abstract class JspSpiUtil { } public static List buildUrls(@Nullable final VirtualFile virtualFile, @Nullable final Module module) { - return buildUrls(virtualFile, module, OrderRootType.CLASSES_AND_OUTPUT); + return buildUrls(virtualFile, module, true); } - public static List buildUrls(@Nullable final VirtualFile virtualFile, @Nullable final Module module, OrderRootType rootType) { + public static List buildUrls(@Nullable final VirtualFile virtualFile, @Nullable final Module module, boolean includeModuleOutput) { final List urls = new ArrayList(); processClassPathItems(virtualFile, module, new Consumer() { public void consume(final VirtualFile file) { addUrl(urls, file); } - }, rootType); + }, includeModuleOutput); return urls; } public static void processClassPathItems(final VirtualFile virtualFile, final Module module, final Consumer consumer) { - processClassPathItems(virtualFile, module, consumer, OrderRootType.CLASSES_AND_OUTPUT); + processClassPathItems(virtualFile, module, consumer, true); } public static void processClassPathItems(final VirtualFile virtualFile, final Module module, final Consumer consumer, - OrderRootType rootType) { + boolean includeModuleOutput) { if (isJarFile(virtualFile)){ consumer.consume(virtualFile); } if (module != null) { - for (VirtualFile file1 : ModuleRootManager.getInstance(module).getFiles(rootType)) { + OrderEnumerator enumerator = ModuleRootManager.getInstance(module).orderEntries().recursively(); + if (!includeModuleOutput) { + enumerator = enumerator.withoutModuleSourceEntries(); + } + for (VirtualFile root : enumerator.getClassesRoots()) { final VirtualFile file; - if (file1.getFileSystem().getProtocol().equals(JarFileSystem.PROTOCOL)) { - file = JarFileSystem.getInstance().getVirtualFileForJar(file1); + if (root.getFileSystem().getProtocol().equals(JarFileSystem.PROTOCOL)) { + file = JarFileSystem.getInstance().getVirtualFileForJar(root); } else { - file = file1; + file = root; } consumer.consume(file); } diff --git a/platform/lang-api/src/com/intellij/openapi/roots/CompilerModuleExtension.java b/platform/lang-api/src/com/intellij/openapi/roots/CompilerModuleExtension.java index 76d277992d06..110f7eded5ac 100644 --- a/platform/lang-api/src/com/intellij/openapi/roots/CompilerModuleExtension.java +++ b/platform/lang-api/src/com/intellij/openapi/roots/CompilerModuleExtension.java @@ -97,4 +97,8 @@ public abstract class CompilerModuleExtension extends ModuleExtension { public abstract void setExcludeOutput(boolean exclude); public abstract boolean isExcludeOutput(); + + public abstract VirtualFile[] getOutputRoots(boolean includeTests); + + public abstract String[] getOutputRootUrls(boolean includeTests); } \ No newline at end of file