diff --git a/bin/win/IdeaWin32.dll b/bin/win/IdeaWin32.dll index 3256217b082d..995f0ebc66c2 100644 Binary files a/bin/win/IdeaWin32.dll and b/bin/win/IdeaWin32.dll differ diff --git a/bin/win/IdeaWin64.dll b/bin/win/IdeaWin64.dll index 82abbb1c3e65..9b8f2b13a79e 100644 Binary files a/bin/win/IdeaWin64.dll and b/bin/win/IdeaWin64.dll differ diff --git a/java/execution/impl/src/com/intellij/execution/remote/RemoteConfigurable.form b/java/execution/impl/src/com/intellij/execution/remote/RemoteConfigurable.form index b9334af6915b..94cd8b27de81 100644 --- a/java/execution/impl/src/com/intellij/execution/remote/RemoteConfigurable.form +++ b/java/execution/impl/src/com/intellij/execution/remote/RemoteConfigurable.form @@ -1,8 +1,9 @@
- + + - + @@ -11,7 +12,6 @@ - @@ -19,25 +19,17 @@ - + - + - - - - - - - - - + @@ -53,18 +45,26 @@ - + + + + + + + + + - + @@ -79,7 +79,7 @@ - + @@ -141,34 +141,38 @@ - - + - + + + - - + - + + + - - + + + - - + - + + + diff --git a/java/execution/impl/src/com/intellij/execution/remote/RemoteConfigurable.java b/java/execution/impl/src/com/intellij/execution/remote/RemoteConfigurable.java index 5179eab1b1df..cfcf4e1d29a9 100644 --- a/java/execution/impl/src/com/intellij/execution/remote/RemoteConfigurable.java +++ b/java/execution/impl/src/com/intellij/execution/remote/RemoteConfigurable.java @@ -128,20 +128,20 @@ public class RemoteConfigurable extends SettingsEditor { myAddressField.addFocusListener(fieldFocusListener); myPortField.addFocusListener(fieldFocusListener); - myModuleSelector = new ConfigurationModuleSelector(project, myModule.getComponent()); + myModuleSelector = new ConfigurationModuleSelector(project, myModule.getComponent(), ""); } public void applyEditorTo(@NotNull final RemoteConfiguration configuration) throws ConfigurationException { configuration.HOST = (myHostField.isEditable() ? myHostField.getText() : myHostName).trim(); - if ("".equals(configuration.HOST)) { + if (configuration.HOST != null && configuration.HOST.isEmpty()) { configuration.HOST = null; } configuration.PORT = myPortField.getText().trim(); - if ("".equals(configuration.PORT)) { + if (configuration.PORT != null && configuration.PORT.isEmpty()) { configuration.PORT = null; } configuration.SHMEM_ADDRESS = myAddressField.getText().trim(); - if ("".equals(configuration.SHMEM_ADDRESS)) { + if (configuration.SHMEM_ADDRESS != null && configuration.SHMEM_ADDRESS.isEmpty()) { configuration.SHMEM_ADDRESS = null; } configuration.USE_SOCKET_TRANSPORT = myRbSocket.isSelected(); diff --git a/java/execution/impl/src/com/intellij/execution/ui/ConfigurationArgumentsHelpArea.form b/java/execution/impl/src/com/intellij/execution/ui/ConfigurationArgumentsHelpArea.form index 5b0bfbf163b6..2a714c767bcb 100644 --- a/java/execution/impl/src/com/intellij/execution/ui/ConfigurationArgumentsHelpArea.form +++ b/java/execution/impl/src/com/intellij/execution/ui/ConfigurationArgumentsHelpArea.form @@ -3,14 +3,14 @@ - + - + @@ -19,9 +19,14 @@ - + + + - + + + + @@ -29,7 +34,7 @@ - + diff --git a/java/execution/impl/src/com/intellij/execution/ui/ConfigurationArgumentsHelpArea.java b/java/execution/impl/src/com/intellij/execution/ui/ConfigurationArgumentsHelpArea.java index 5bb5ee45eac5..ef2bebd366bb 100644 --- a/java/execution/impl/src/com/intellij/execution/ui/ConfigurationArgumentsHelpArea.java +++ b/java/execution/impl/src/com/intellij/execution/ui/ConfigurationArgumentsHelpArea.java @@ -19,6 +19,7 @@ import com.intellij.execution.ExecutionBundle; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.ui.FixedSizeButton; +import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.PopupHandler; import com.intellij.util.PlatformIcons; @@ -37,6 +38,7 @@ public class ConfigurationArgumentsHelpArea extends JPanel { public ConfigurationArgumentsHelpArea() { super(new BorderLayout()); add(myPanel); + setBorder(IdeBorderFactory.createEmptyBorder(10, 0, 0, 0)); final DefaultActionGroup group = new DefaultActionGroup(); group.add(new MyCopyAction()); @@ -64,7 +66,7 @@ public class ConfigurationArgumentsHelpArea extends JPanel { public void setToolbarVisible() { myToolbarPanel.setVisible(true); } - + private static ActionPopupMenu createPopupMenu(DefaultActionGroup group) { return ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UNKNOWN, group); } diff --git a/java/execution/impl/src/com/intellij/execution/ui/ConfigurationModuleSelector.java b/java/execution/impl/src/com/intellij/execution/ui/ConfigurationModuleSelector.java index 6150292913fe..f63e679684ff 100644 --- a/java/execution/impl/src/com/intellij/execution/ui/ConfigurationModuleSelector.java +++ b/java/execution/impl/src/com/intellij/execution/ui/ConfigurationModuleSelector.java @@ -35,8 +35,8 @@ import java.util.Comparator; import java.util.List; public class ConfigurationModuleSelector { - private static final String NO_MODULE = ""; + private final String myNoModule; private final Project myProject; private final JComboBox myModulesList; private final SortedComboBoxModel myModules = new SortedComboBoxModel(new Comparator() { @@ -49,6 +49,11 @@ public class ConfigurationModuleSelector { }); public ConfigurationModuleSelector(final Project project, final JComboBox modulesList) { + this(project, modulesList, ""); + } + + public ConfigurationModuleSelector(final Project project, final JComboBox modulesList, String noModule) { + myNoModule = noModule; myProject = project; myModulesList = modulesList; new ComboboxSpeedSearch(modulesList){ @@ -56,7 +61,7 @@ public class ConfigurationModuleSelector { if (element instanceof Module){ return ((Module)element).getName(); } else if (element == null) { - return NO_MODULE; + return myNoModule; } return super.getElementText(element); } @@ -71,7 +76,7 @@ public class ConfigurationModuleSelector { setText(module.getName()); } else if (value == null) { - setText(NO_MODULE); + setText(myNoModule); } } }); diff --git a/java/java-impl/src/com/intellij/psi/impl/search/VariableInIncompleteCodeSearcher.java b/java/java-impl/src/com/intellij/psi/impl/search/VariableInIncompleteCodeSearcher.java index 19a75a872c26..fc0ca69b6a4c 100644 --- a/java/java-impl/src/com/intellij/psi/impl/search/VariableInIncompleteCodeSearcher.java +++ b/java/java-impl/src/com/intellij/psi/impl/search/VariableInIncompleteCodeSearcher.java @@ -15,6 +15,7 @@ */ package com.intellij.psi.impl.search; +import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.application.QueryExecutorBase; import com.intellij.psi.*; import com.intellij.psi.search.LocalSearchScope; @@ -44,7 +45,10 @@ public class VariableInIncompleteCodeSearcher extends QueryExecutorBase +typedef DWORD (WINAPI *GetFinalPathNameByHandlePtr) (HANDLE, LPCWSTR, DWORD, DWORD dwFlags); +static GetFinalPathNameByHandlePtr __GetFinalPathNameByHandle = NULL; static jfieldID nameID = NULL; static jfieldID attributesID = NULL; @@ -66,30 +68,38 @@ static jobject CreateFileInfo(JNIEnv *env, jstring path, bool append, LPWIN32_FI timestamp = 0; length = 0; - size_t nameLen = env->GetStringLength(path) + wcslen(lpData->cFileName) + 2; - wchar_t *lpName = (wchar_t *)malloc(nameLen * sizeof(wchar_t)); - if (lpName != NULL) { - const jchar *dirName = env->GetStringChars(path, 0); - wcscpy_s(lpName, nameLen, (LPCWSTR)dirName); - env->ReleaseStringChars(path, dirName); - if (append) { - wcscat_s(lpName, nameLen, L"\\"); - wcscat_s(lpName, nameLen, lpData->cFileName); - } + const jchar *dirName = env->GetStringChars(path, 0); + wchar_t *fullPath = (wchar_t *)dirName; + if (append) { + size_t nameLen = env->GetStringLength(path) + wcslen(lpData->cFileName) + 2; + fullPath = (wchar_t *)malloc(nameLen * sizeof(wchar_t)); + if (fullPath != NULL) { + wcscpy_s(fullPath, nameLen, (LPCWSTR)dirName); + wcscat_s(fullPath, nameLen, L"\\"); + wcscat_s(fullPath, nameLen, lpData->cFileName); + } + } + + if (fullPath != NULL) { // read symlink target attributes - HANDLE th = CreateFile(lpName, 0, FILE_SHARE_ATTRIBUTES, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); - if (th != INVALID_HANDLE_VALUE) { + HANDLE h = CreateFile(fullPath, 0, FILE_SHARE_ATTRIBUTES, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (h != INVALID_HANDLE_VALUE) { BY_HANDLE_FILE_INFORMATION targetData; - if (GetFileInformationByHandle(th, &targetData)) { + if (GetFileInformationByHandle(h, &targetData)) { attributes = targetData.dwFileAttributes | FILE_ATTRIBUTE_REPARSE_POINT; timestamp = pairToInt64(targetData.ftLastWriteTime.dwLowDateTime, targetData.ftLastWriteTime.dwHighDateTime); length = pairToInt64(targetData.nFileSizeLow, targetData.nFileSizeHigh); } - CloseHandle(th); + CloseHandle(h); + } + + if (append) { + free(fullPath); } - free(lpName); } + + env->ReleaseStringChars(path, dirName); } else { attributes &= (~ FILE_ATTRIBUTE_REPARSE_POINT); // keep reparse flag only for symlinks @@ -116,6 +126,9 @@ static jobject CreateFileInfo(JNIEnv *env, jstring path, bool append, LPWIN32_FI JNIEXPORT void JNICALL Java_com_intellij_openapi_util_io_win32_IdeaWin32_initIDs(JNIEnv *env, jclass cls) { + __GetFinalPathNameByHandle = + (GetFinalPathNameByHandlePtr)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "GetFinalPathNameByHandleW"); + jclass fileInfoClass = getFileInfoClass(env); if (fileInfoClass == NULL) { return; @@ -166,6 +179,10 @@ JNIEXPORT jobject JNICALL Java_com_intellij_openapi_util_io_win32_IdeaWin32_getI JNIEXPORT jstring JNICALL Java_com_intellij_openapi_util_io_win32_IdeaWin32_resolveSymLink0(JNIEnv *env, jobject method, jstring path) { + if (__GetFinalPathNameByHandle == NULL) { + return NULL; // XP + } + WIN32_FIND_DATA data; HANDLE h = FindFileInner(env, path, &data); if (h == INVALID_HANDLE_VALUE) { @@ -187,7 +204,7 @@ JNIEXPORT jstring JNICALL Java_com_intellij_openapi_util_io_win32_IdeaWin32_reso jstring result = NULL; TCHAR name[MAX_PATH]; - DWORD len = GetFinalPathNameByHandle(th, name, MAX_PATH, 0); + DWORD len = __GetFinalPathNameByHandle(th, name, MAX_PATH, 0); if (len > 0) { if (len < MAX_PATH) { result = env->NewString((jchar *)name, len); @@ -195,7 +212,7 @@ JNIEXPORT jstring JNICALL Java_com_intellij_openapi_util_io_win32_IdeaWin32_reso else { TCHAR *name = (TCHAR *)malloc(sizeof(TCHAR) * (len + 1)); if (name != NULL) { - len = GetFinalPathNameByHandle(th, name, len, 0); + len = __GetFinalPathNameByHandle(th, name, len, 0); if (len > 0) { result = env->NewString((jchar *)name, len); } diff --git a/platform/lang-impl/src/com/intellij/indentation/IndentationParser.java b/platform/lang-impl/src/com/intellij/indentation/IndentationParser.java index f406db0d336f..acf195d828ff 100644 --- a/platform/lang-impl/src/com/intellij/indentation/IndentationParser.java +++ b/platform/lang-impl/src/com/intellij/indentation/IndentationParser.java @@ -3,7 +3,6 @@ package com.intellij.indentation; import com.intellij.lang.ASTNode; import com.intellij.lang.PsiBuilder; import com.intellij.lang.PsiParser; -import com.intellij.openapi.util.Pair; import com.intellij.psi.tree.IElementType; import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NotNull; @@ -38,8 +37,8 @@ public abstract class IndentationParser implements PsiParser { final PsiBuilder.Marker fileMarker = builder.mark(); final PsiBuilder.Marker documentMarker = builder.mark(); - final Stack> stack = new Stack>(); - stack.push(Pair.create(0, builder.mark())); + final Stack stack = new Stack(); + stack.push(new BlockInfo(0, builder.mark())); PsiBuilder.Marker startLineMarker = null; int currentIndent = 0; @@ -61,7 +60,7 @@ public abstract class IndentationParser implements PsiParser { currentIndent = builder.getTokenText().length(); } else { - if (!eolSeen && !stack.isEmpty() && currentIndent > 0 && currentIndent < stack.peek().first) { + if (!eolSeen && !stack.isEmpty() && currentIndent > 0 && currentIndent < stack.peek().getIndent()) { // sometimes we do not have EOL between indents eolSeen = true; } @@ -71,18 +70,18 @@ public abstract class IndentationParser implements PsiParser { startLineMarker = null; } // Close indentation blocks - while (!stack.isEmpty() && currentIndent < stack.peek().first) { - closeBlock(builder, stack.pop().second); + while (!stack.isEmpty() && currentIndent < stack.peek().getIndent()) { + closeBlock(builder, stack.pop().getMarker()); } if (!stack.isEmpty()) { - final Pair pair = stack.peek(); - if (currentIndent >= pair.first) { - if (currentIndent == pair.first) { - closeBlock(builder, stack.pop().second); + final BlockInfo blockInfo = stack.peek(); + if (currentIndent >= blockInfo.getIndent()) { + if (currentIndent == blockInfo.getIndent()) { + closeBlock(builder, stack.pop().getMarker()); } passEOLsAndIndents(builder); - stack.push(Pair.create(currentIndent, builder.mark())); + stack.push(new BlockInfo(currentIndent, builder.mark())); } } eolSeen = false; @@ -98,7 +97,7 @@ public abstract class IndentationParser implements PsiParser { startLineMarker.drop(); } while (!stack.isEmpty()){ - closeBlock(builder, stack.pop().second); + closeBlock(builder, stack.pop().getMarker()); } documentMarker.done(myDocumentType); @@ -121,4 +120,24 @@ public abstract class IndentationParser implements PsiParser { tokenType = builder.getTokenType(); } } + + private static final class BlockInfo { + private final int myIndent; + @NotNull + private final PsiBuilder.Marker myMarker; + + private BlockInfo(final int indent, final @NotNull PsiBuilder.Marker marker) { + this.myIndent = indent; + this.myMarker = marker; + } + + public int getIndent() { + return myIndent; + } + + @NotNull + public PsiBuilder.Marker getMarker() { + return myMarker; + } + } } diff --git a/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java b/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java index e883eb65a4e9..0cc3229fadb5 100644 --- a/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java +++ b/platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java @@ -97,7 +97,7 @@ public class Tree extends JTree implements ComponentWithEmptyText, ComponentWith TreeUI actualUI = ui; if (!isCustomUI()) { if (!(ui instanceof WideSelectionTreeUI) && (UIUtil.isUnderAquaBasedLookAndFeel() || SystemInfo.isWindows) && isMacWideSelection()) { //todo[kb] fix on ubunty - actualUI = new WideSelectionTreeUI(isMacWideSelection(), !isFileColorsEnabled()); + actualUI = new WideSelectionTreeUI(isMacWideSelection(), !SystemInfo.isMac); } } super.setUI(actualUI); diff --git a/platform/platform-resources-en/src/messages/ApplicationBundle.properties b/platform/platform-resources-en/src/messages/ApplicationBundle.properties index 4332c8d81fa2..13c5cb478d13 100644 --- a/platform/platform-resources-en/src/messages/ApplicationBundle.properties +++ b/platform/platform-resources-en/src/messages/ApplicationBundle.properties @@ -402,7 +402,7 @@ group.error.highlighting=Error highlighting editbox.autoreparse.delay.ms=Autoreparse delay (ms): editbox.error.stripe.mark.min.height.pixels=Error stripe mark min height (pixels): checkbox.suppress.with.suppresswarnings=Suppress with @SuppressWarnings (for Java 5.0 only) -checkbox.next.error.action.goes.to.errors.first='Next Error' action goes to errors first +checkbox.next.error.action.goes.to.errors.first='Next Error' action goes to high priority problems only checkbox.show.import.popup=Show import &popup checkbox.indent.use.tab.character=Use tab character checkbox.indent.smart.tabs=Smart tabs diff --git a/platform/platform-resources-en/src/messages/ExecutionBundle.properties b/platform/platform-resources-en/src/messages/ExecutionBundle.properties index 71c7b5cabc4d..d03c6b7f3810 100644 --- a/platform/platform-resources-en/src/messages/ExecutionBundle.properties +++ b/platform/platform-resources-en/src/messages/ExecutionBundle.properties @@ -252,11 +252,11 @@ remote.configuration.socket.radio=Socket remote.configuration.shared.memory.address.label=Shared memory address: remote.configuration.port.label=Port: remote.configuration.host.label=Host: -remote.configuration.remote.debugging.allows.you.to.connect.idea.to.a.running.jvm.label=&Remote debugging allows you to connect IDEA to a running JVM started with the following command line arguments +remote.configuration.remote.debugging.allows.you.to.connect.idea.to.a.running.jvm.label=&Command line arguments for running remote JVM standard.runner.description=Run selected configuration environment.variables.helper.use.arguments.label=Use the following command line arguments for running remote JVM -environment.variables.helper.use.arguments.jdk13.label=If the &application runs on JDK 1.3.x or earlier, use following arguments -environment.variables.helper.use.arguments.jdk14.label=If the &application runs on JDK 1.4.x, use following arguments +environment.variables.helper.use.arguments.jdk13.label=For JDK 1.3.x or earlier +environment.variables.helper.use.arguments.jdk14.label=For JDK 1.4.x select.run.configuration.for.item.action.name=Select ''{0}'' save.run.configuration.for.item.action.name=Save ''{0}'' junit.runing.info.status.done.count=Done: {0} diff --git a/platform/platform-tests/testSrc/com/intellij/psi/util/NameUtilTest.java b/platform/platform-tests/testSrc/com/intellij/psi/util/NameUtilTest.java index 8064655edb19..0d831e863627 100644 --- a/platform/platform-tests/testSrc/com/intellij/psi/util/NameUtilTest.java +++ b/platform/platform-tests/testSrc/com/intellij/psi/util/NameUtilTest.java @@ -487,6 +487,6 @@ public class NameUtilTest extends UsefulTestCase { } } } - }).cpuBound().assertTiming(); + }).cpuBound().attempts(20).assertTiming(); } } diff --git a/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java b/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java index c1ef5bf25b68..13ff82470542 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/TestsUIUtil.java @@ -160,8 +160,10 @@ public class TestsUIUtil { int failedCount = failed.size(); final List notStarted = Filter.NOT_PASSED.select(allTests); notStarted.removeAll(failed); + final List ignored = Filter.IGNORED.select(allTests); + notStarted.removeAll(ignored); int notStartedCount = notStarted.size(); - int passedCount = allTests.size() - failedCount - notStartedCount; + int passedCount = allTests.size() - failedCount - notStartedCount - ignored.size(); if (failedCount > 0) { myTitle = ExecutionBundle.message("junit.runing.info.tests.failed.label"); myText = passedCount + " passed, " + failedCount + " failed" + (notStartedCount > 0 ? ", " + notStartedCount + " not started" : ""); diff --git a/platform/util/src/com/intellij/openapi/util/io/win32/IdeaWin32.java b/platform/util/src/com/intellij/openapi/util/io/win32/IdeaWin32.java index 1ebf61203d84..575ae4f9f787 100644 --- a/platform/util/src/com/intellij/openapi/util/io/win32/IdeaWin32.java +++ b/platform/util/src/com/intellij/openapi/util/io/win32/IdeaWin32.java @@ -46,11 +46,13 @@ public class IdeaWin32 { available = true; } catch (Throwable t0) { + LOG.debug(t0); try { System.load(PathManager.getHomePath() + "/bin/win/" + libName + ".dll"); available = true; } catch (Throwable t1) { + LOG.debug(t1); try { System.loadLibrary(libName); available = true; diff --git a/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesReadingTest.java b/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesReadingTest.java index 0ac50050a0d1..41bd996d02b1 100644 --- a/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesReadingTest.java +++ b/platform/util/testSrc/com/intellij/openapi/util/io/FileAttributesReadingTest.java @@ -101,6 +101,8 @@ public class FileAttributesReadingTest { @Test public void linkToFile() throws Exception { + assumeTrue(SystemInfo.areSymLinksSupported); + final File file = FileUtil.createTempFile(myTempDirectory, "test.", ".txt", true); FileUtil.writeToFile(file, myTestData); assertTrue(file.setLastModified(file.lastModified() - 5000)); @@ -120,6 +122,8 @@ public class FileAttributesReadingTest { @Test public void doubleLink() throws Exception { + assumeTrue(SystemInfo.areSymLinksSupported); + final File file = FileUtil.createTempFile(myTempDirectory, "test.", ".txt", true); FileUtil.writeToFile(file, myTestData); assertTrue(file.setLastModified(file.lastModified() - 5000)); @@ -140,6 +144,8 @@ public class FileAttributesReadingTest { @Test public void linkToDirectory() throws Exception { + assumeTrue(SystemInfo.areSymLinksSupported); + final File file = FileUtil.createTempDirectory(myTempDirectory, "test.", ".tmp"); if (SystemInfo.isUnix) assertTrue(file.setWritable(false, false)); assertTrue(file.setLastModified(file.lastModified() - 5000)); @@ -158,6 +164,8 @@ public class FileAttributesReadingTest { @Test public void missingLink() throws Exception { + assumeTrue(SystemInfo.areSymLinksSupported); + final File file = FileUtil.createTempFile(myTempDirectory, "test.", ".txt", false); final File link = IoTestUtil.createTempLink(file.getPath(), new File(myTempDirectory, "link").getPath()); diff --git a/plugins/android-designer/src/com/intellij/android/designer/componentTree/AndroidTreeDecorator.java b/plugins/android-designer/src/com/intellij/android/designer/componentTree/AndroidTreeDecorator.java index 1c4787fe2304..605a71f23561 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/componentTree/AndroidTreeDecorator.java +++ b/plugins/android-designer/src/com/intellij/android/designer/componentTree/AndroidTreeDecorator.java @@ -24,7 +24,6 @@ import com.intellij.designer.model.RadComponent; import com.intellij.designer.palette.DefaultPaletteItem; import com.intellij.designer.propertyTable.Property; import com.intellij.designer.propertyTable.PropertyTable; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.SimpleColoredComponent; import com.intellij.ui.SimpleTextAttributes; @@ -90,8 +89,6 @@ public final class AndroidTreeDecorator implements TreeComponentDecorator { } } - private static final Logger LOG = Logger.getInstance("#com.intellij.android.designer.componentTree"); - @Nullable private static String getPropertyValue(RadComponent component, String name) { if (component.getProperties() == null) { diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java b/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java index ac1813d70e12..c4ed59990c25 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java @@ -191,7 +191,9 @@ public class ModelParser extends XmlRecursiveElementVisitor { addComponent(newComponent, ViewsMetaManager.getInstance(newComponent.getTag().getProject()), propertyParser); } - IdManager.get(container).ensureIds(newComponent); + if (!(newComponent instanceof RadViewContainer)) { + IdManager.get(container).ensureIds(newComponent); + } } private static void addComponent(RadViewComponent parentComponent, diff --git a/plugins/android/resources/messages/AndroidBundle.properties b/plugins/android/resources/messages/AndroidBundle.properties index a991cb90d471..b6f65eec3731 100644 --- a/plugins/android/resources/messages/AndroidBundle.properties +++ b/plugins/android/resources/messages/AndroidBundle.properties @@ -171,7 +171,7 @@ android.wizard.specify.tested.module.error=Please specify tested module android.wizard.tested.module.without.facet.error=Tested module must contain Android facet android.wizard.cannot.find.module.parent.dir.error=Cannot find module parent directory: {0} android.wizard.invalid.sdk.error=Android SDK is invalid -android.facet.editor.is.library.checkbox=&Is Library project +android.facet.editor.is.library.checkbox=Li&brary module android.run.sdk.manager.action.text=SDK Manager android.run.avd.manager.action.text=AVD Manager android.choose.sdk.label=Please choose Android SDK location @@ -220,7 +220,7 @@ android.keystore.password.label=Pa&ssword: android.keystore.confirm.password.label=C&onfirm: android.export.package.new.key.alias.label=&Alias: android.key.password.label=Pa&ssword: -android.cannot.run.library.project.error=The module cannot be Android library project +android.cannot.run.library.project.error=The module cannot be Android library android.compilation.error.specify.platform=[{0}] Android SDK is not specified or cannot be parsed android.compilation.error.manifest.not.found=[{0}] AndroidManifest.xml file not found. Please, check Android facet settings. android.compilation.error.apt.gen.not.specified=AAPT destination directory not specified for module {0} @@ -389,7 +389,7 @@ android.lint.inspections.use.sparsearray=HashMap can be replaced with SparseArra android.lint.inspections.value.of=Should use 'valueOf' instead of 'new' android.lint.inspections.multiple.uses.sdk=Multiple elements in the manifest android.lint.inspections.uses.min.sdk=Minimum SDK and target SDK attributes not defined -android.lint.inspections.custom.view=Using custom namespace attributes in a library project +android.lint.inspections.custom.view=Using custom namespace attributes in a library module android.lint.inspections.proguard.split.config=Proguard.cfg file contains generic Android rules android.lint.inspections.sd.card.path=Hardcoded reference to /sdcard android.lint.inspections.world,writable.files=openFileOutput() call passing MODE_WORLD_WRITEABLE diff --git a/plugins/android/src/org/jetbrains/android/AndroidRenameResourceProcessor.java b/plugins/android/src/org/jetbrains/android/AndroidRenameResourceProcessor.java index 9fd22af565a0..5457ad25899b 100644 --- a/plugins/android/src/org/jetbrains/android/AndroidRenameResourceProcessor.java +++ b/plugins/android/src/org/jetbrains/android/AndroidRenameResourceProcessor.java @@ -125,8 +125,10 @@ public class AndroidRenameResourceProcessor extends RenamePsiElementProcessor { } } String name = AndroidResourceUtil.getResourceNameByReferenceText(newName); - for (PsiField resField : AndroidResourceUtil.findIdFields(value)) { - allRenames.put(resField, name); + if (name != null) { + for (PsiField resField : AndroidResourceUtil.findIdFields(value)) { + allRenames.put(resField, AndroidResourceUtil.getFieldNameByResourceName(name)); + } } } @@ -186,7 +188,7 @@ public class AndroidRenameResourceProcessor extends RenamePsiElementProcessor { } PsiField[] resFields = AndroidResourceUtil.findResourceFieldsForValueResource(tag, false); for (PsiField resField : resFields) { - allRenames.put(resField, newName); + allRenames.put(resField, AndroidResourceUtil.getFieldNameByResourceName(newName)); } } @@ -226,7 +228,7 @@ public class AndroidRenameResourceProcessor extends RenamePsiElementProcessor { PsiField[] resFields = AndroidResourceUtil.findResourceFieldsForFileResource(file, false); for (PsiField resField : resFields) { String newFieldName = AndroidCommonUtils.getResourceName(type, newName); - allRenames.put(resField, newFieldName); + allRenames.put(resField, AndroidResourceUtil.getFieldNameByResourceName(newFieldName)); } } diff --git a/plugins/android/src/org/jetbrains/android/AndroidValueResourcesIndex.java b/plugins/android/src/org/jetbrains/android/AndroidValueResourcesIndex.java index 455dd76f0e83..de2f9d0309ac 100644 --- a/plugins/android/src/org/jetbrains/android/AndroidValueResourcesIndex.java +++ b/plugins/android/src/org/jetbrains/android/AndroidValueResourcesIndex.java @@ -56,9 +56,9 @@ public class AndroidValueResourcesIndex extends FileBasedIndexExtensionemptySet()); - addEntryToMap(entry, createTypeMarkerEntry(entry.getType()), result); - addEntryToMap(entry, createTypeNameMarkerEntry(entry.getType(), entry.getName()), result); + result.put(createKey(entry), Collections.emptySet()); + addEntryToMap(entry, createTypeMarkerKey(entry.getType()), result); + addEntryToMap(entry, createTypeNameMarkerKey(entry.getType(), entry.getName()), result); } }); @@ -76,12 +76,39 @@ public class AndroidValueResourcesIndex extends FileBasedIndexExtension myKeyDescriptor = new KeyDescriptor() { diff --git a/plugins/android/src/org/jetbrains/android/dom/converters/AndroidResourceReference.java b/plugins/android/src/org/jetbrains/android/dom/converters/AndroidResourceReference.java index 42bf53f9169f..69099c57db4f 100644 --- a/plugins/android/src/org/jetbrains/android/dom/converters/AndroidResourceReference.java +++ b/plugins/android/src/org/jetbrains/android/dom/converters/AndroidResourceReference.java @@ -85,9 +85,14 @@ public class AndroidResourceReference extends PsiReferenceBase.Poly ResourceValue value = myValue.getValue(); assert value != null; String resType = value.getResourceType(); + if (resType != null && newElementName != null) { - myValue.setValue(ResourceValue.referenceTo(value.getPrefix(), value.getPackage(), resType, - AndroidCommonUtils.getResourceName(resType, newElementName))); + // todo: do not allow new value resource name to contain dot, because it is impossible to check if it file or value otherwise + + final String newResName = newElementName.contains(".") // it is file + ? AndroidCommonUtils.getResourceName(resType, newElementName) + : newElementName; + myValue.setValue(ResourceValue.referenceTo(value.getPrefix(), value.getPackage(), resType, newResName)); } return myValue.getXmlTag(); } diff --git a/plugins/android/src/org/jetbrains/android/resourceManagers/LocalResourceManager.java b/plugins/android/src/org/jetbrains/android/resourceManagers/LocalResourceManager.java index 8f62c4398bca..901edeef9843 100644 --- a/plugins/android/src/org/jetbrains/android/resourceManagers/LocalResourceManager.java +++ b/plugins/android/src/org/jetbrains/android/resourceManagers/LocalResourceManager.java @@ -139,11 +139,12 @@ public class LocalResourceManager extends ResourceManager { final GlobalSearchScope scope = GlobalSearchScope.projectScope(myModule.getProject()); for (ResourceType resourceType : AndroidResourceUtil.ALL_VALUE_RESOURCE_TYPES) { - final ResourceEntry typeMarkerEntry = AndroidValueResourcesIndex.createTypeMarkerEntry(resourceType.getName()); + final ResourceEntry typeMarkerEntry = AndroidValueResourcesIndex.createTypeMarkerKey(resourceType.getName()); for (Set entrySet : index.getValues(AndroidValueResourcesIndex.INDEX_ID, typeMarkerEntry, scope)) { for (ResourceEntry entry : entrySet) { - final Collection files = index.getContainingFiles(AndroidValueResourcesIndex.INDEX_ID, entry, scope); + final Collection files = + index.getContainingFiles(AndroidValueResourcesIndex.INDEX_ID, AndroidValueResourcesIndex.createKey(entry), scope); for (VirtualFile file : files) { Set resourcesInFile = file2Types.get(file); diff --git a/plugins/android/src/org/jetbrains/android/resourceManagers/ResourceManager.java b/plugins/android/src/org/jetbrains/android/resourceManagers/ResourceManager.java index 7578b7a70707..4074d08af222 100644 --- a/plugins/android/src/org/jetbrains/android/resourceManagers/ResourceManager.java +++ b/plugins/android/src/org/jetbrains/android/resourceManagers/ResourceManager.java @@ -281,13 +281,14 @@ public abstract class ResourceManager { } final FileBasedIndex index = FileBasedIndex.getInstance(); - final ResourceEntry typeMarkerEntry = AndroidValueResourcesIndex.createTypeMarkerEntry(resourceType); + final ResourceEntry typeMarkerEntry = AndroidValueResourcesIndex.createTypeMarkerKey(resourceType); final GlobalSearchScope scope = GlobalSearchScope.allScope(myModule.getProject()); final Map> file2resourceSet = new HashMap>(); for (Set entrySet : index.getValues(AndroidValueResourcesIndex.INDEX_ID, typeMarkerEntry, scope)) { for (ResourceEntry entry : entrySet) { - final Collection files = index.getContainingFiles(AndroidValueResourcesIndex.INDEX_ID, entry, scope); + final Collection files = + index.getContainingFiles(AndroidValueResourcesIndex.INDEX_ID, AndroidValueResourcesIndex.createKey(entry), scope); for (VirtualFile file : files) { Set resourcesInFile = file2resourceSet.get(file); @@ -438,7 +439,7 @@ public abstract class ResourceManager { final Collection files = FileBasedIndex.getInstance() .getContainingFiles(AndroidValueResourcesIndex.INDEX_ID, - AndroidValueResourcesIndex.createTypeNameMarkerEntry(resourceType, resourceName), + AndroidValueResourcesIndex.createTypeNameMarkerKey(resourceType, resourceName), GlobalSearchScope.allScope(myModule.getProject())); if (files.size() == 0) { diff --git a/plugins/android/src/org/jetbrains/android/run/AndroidDebugRunner.java b/plugins/android/src/org/jetbrains/android/run/AndroidDebugRunner.java index c97c498aea13..9d51584f12ee 100644 --- a/plugins/android/src/org/jetbrains/android/run/AndroidDebugRunner.java +++ b/plugins/android/src/org/jetbrains/android/run/AndroidDebugRunner.java @@ -102,7 +102,7 @@ public class AndroidDebugRunner extends DefaultProgramRunner { launcher.setRunDescriptor(runDescriptor); } if (runDescriptor == null) { - throw new ExecutionException("Can't run an application"); + return null; } tryToCloseOldSessions(executor, project); runningState.getProcessHandler().putUserData(ANDROID_PROCESS_HANDLER, runDescriptor); diff --git a/plugins/android/testData/resNavigation/dist_delims.xml b/plugins/android/testData/resNavigation/dist_delims.xml new file mode 100644 index 000000000000..212cfb7a77c5 --- /dev/null +++ b/plugins/android/testData/resNavigation/dist_delims.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/plugins/android/testData/resNavigation/src/p1/p2/JavaFileNavigation12.java b/plugins/android/testData/resNavigation/src/p1/p2/JavaFileNavigation12.java new file mode 100644 index 000000000000..2a8be34e10a4 --- /dev/null +++ b/plugins/android/testData/resNavigation/src/p1/p2/JavaFileNavigation12.java @@ -0,0 +1,7 @@ +package p1.p2; + +class Java { + public void g() { + int a = R.string.dist_delims; + } +} \ No newline at end of file diff --git a/plugins/android/testSrc/org/jetbrains/android/AndroidResourcesLineMarkerTest.java b/plugins/android/testSrc/org/jetbrains/android/AndroidResourcesLineMarkerTest.java index 0db7679853aa..5c79c87efc22 100644 --- a/plugins/android/testSrc/org/jetbrains/android/AndroidResourcesLineMarkerTest.java +++ b/plugins/android/testSrc/org/jetbrains/android/AndroidResourcesLineMarkerTest.java @@ -73,6 +73,11 @@ public class AndroidResourcesLineMarkerTest extends AndroidTestCase { doJavaFileNavigationTest(1, true, XmlAttributeValue.class); } + public void testJavaFileNavigation12() throws Exception { + myFixture.copyFileToProject(BASE_PATH + "dist_delims.xml", "res/values/strings12.xml"); + doJavaFileNavigationTest(1, true, XmlAttributeValue.class); + } + private void doJavaFileNavigationTest(int expectedTargets, boolean expectedEnabled, @Nullable Class targetElementClass) diff --git a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLibraryProjectTest.java b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLibraryProjectTest.java index 047b940266aa..3783096f7ee2 100644 --- a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLibraryProjectTest.java +++ b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLibraryProjectTest.java @@ -240,13 +240,13 @@ public class AndroidLibraryProjectTest extends UsefulTestCase { myFixture.copyFileToProject(BASE_PATH + "FindUsagesClass1.java", "app/src/p1/p2/lib/Class.java"); myFixture.copyFileToProject(BASE_PATH + "FindUsagesClass1.java", "lib/src/p1/p2/lib/Class.java"); myFixture.copyFileToProject(BASE_PATH + "FindUsagesStyles.xml", "app/res/values/styles.xml"); - myFixture.copyFileToProject(BASE_PATH + "FindUsagesStyles2.xml", "lib/res/values/styles2.xml"); + //myFixture.copyFileToProject(BASE_PATH + "FindUsagesStyles2.xml", "lib/res/values/styles2.xml"); myFixture.copyFileToProject(BASE_PATH + "picture1.png", "lib/res/drawable/picture1.png"); myFixture.copyFileToProject("R.java", "app/src/p1/p2/R.java"); myFixture.copyFileToProject(BASE_PATH + "LibR.java", "app/src/p1/p2/lib/R.java"); myFixture.copyFileToProject(BASE_PATH + "LibR.java", "lib/src/p1/p2/lib/R.java"); Collection references = findCodeUsages(getTestName(false) + "." + extension, dir); - assertEquals(buildFileList(references), 6, references.size()); + assertEquals(buildFileList(references), 5, references.size()); } private List findCodeUsages(String path, String dir) throws Throwable { diff --git a/plugins/devkit/src/dom/Action.java b/plugins/devkit/src/dom/Action.java index bd03efde2566..89f354604d07 100644 --- a/plugins/devkit/src/dom/Action.java +++ b/plugins/devkit/src/dom/Action.java @@ -64,7 +64,7 @@ public interface Action extends DomElement { * @return the value of the class child. */ @NotNull - @com.intellij.util.xml.Attribute ("class") + @Attribute ("class") @Required @ExtendClass(value = "com.intellij.openapi.actionSystem.AnAction", instantiatable = true, allowNonPublic = true, allowAbstract = false, allowInterface = false) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrHighlightUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrHighlightUtil.java index 079467ac7c19..621a8ad4bc20 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrHighlightUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrHighlightUtil.java @@ -1,186 +1,190 @@ -/* - * 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 org.jetbrains.plugins.groovy.annotator; - -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.editor.colors.TextAttributesKey; -import com.intellij.openapi.util.TextRange; -import com.intellij.pom.PomDeclarationSearcher; -import com.intellij.pom.PomTarget; -import com.intellij.psi.*; -import com.intellij.psi.search.LocalSearchScope; -import com.intellij.psi.search.searches.ReferencesSearch; -import com.intellij.psi.tree.IElementType; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.util.CollectConsumer; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.plugins.groovy.extensions.GroovyUnresolvedHighlightFilter; -import org.jetbrains.plugins.groovy.highlighter.DefaultHighlighter; -import org.jetbrains.plugins.groovy.lang.lexer.TokenSets; -import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod; -import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass; -import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils; -import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; -import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; - -/** - * @author Max Medvedev - */ -public class GrHighlightUtil { - private static final Logger LOG = Logger.getInstance(GrHighlightUtil.class); - - static boolean isReassigned(GrVariable var) { - PsiMethod method = PsiTreeUtil.getParentOfType(var, PsiMethod.class); - PsiNamedElement scope = method == null ? var.getContainingFile() : method; - if (scope == null) { - return false; - } - boolean hasAssignment = var.getInitializerGroovy() != null || var instanceof GrParameter; - for (PsiReference reference : ReferencesSearch.search(var, new LocalSearchScope(scope)).findAll()) { - if (reference instanceof GrReferenceExpression && - (PsiUtil.isLValue((GrReferenceExpression)reference) || - ((GrReferenceExpression)reference).getParent() instanceof GrUnaryExpression && - ((GrUnaryExpression)((GrReferenceExpression)reference).getParent()).isPostfix())) { - if (hasAssignment) { - return true; - } - hasAssignment = true; - } - } - return false; - } - - @Nullable - static TextAttributesKey getDeclarationHighlightingAttribute(PsiElement resolved) { - if (resolved instanceof PsiField || resolved instanceof GrVariable && ResolveUtil.isScriptField((GrVariable)resolved)) { - boolean isStatic = ((PsiVariable)resolved).hasModifierProperty(PsiModifier.STATIC); - return isStatic ? DefaultHighlighter.STATIC_FIELD : DefaultHighlighter.INSTANCE_FIELD; - } - else if (resolved instanceof GrAccessorMethod) { - boolean isStatic = ((GrAccessorMethod)resolved).hasModifierProperty(PsiModifier.STATIC); - return isStatic ? DefaultHighlighter.STATIC_PROPERTY_REFERENCE : DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE; - } - else if (resolved instanceof PsiMethod) { - if (!((PsiMethod)resolved).isConstructor()) { - boolean isStatic = ((PsiMethod)resolved).hasModifierProperty(PsiModifier.STATIC); - if (GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)resolved)) { - return isStatic ? DefaultHighlighter.STATIC_PROPERTY_REFERENCE : DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE; - } - else { - return isStatic ? DefaultHighlighter.STATIC_METHOD_ACCESS : DefaultHighlighter.METHOD_CALL; - } - } - } - else if (resolved instanceof PsiTypeParameter) { - return DefaultHighlighter.TYPE_PARAMETER; - } - else if (resolved instanceof PsiClass) { - if (((PsiClass)resolved).isAnnotationType()) { - return DefaultHighlighter.ANNOTATION; - } - else { - return DefaultHighlighter.CLASS_REFERENCE; - } - } - else if (resolved instanceof GrParameter) { - boolean reassigned = isReassigned((GrParameter)resolved); - return reassigned ? DefaultHighlighter.REASSIGNED_PARAMETER : DefaultHighlighter.PARAMETER; - } - else if (resolved instanceof GrVariable) { - boolean reassigned = isReassigned((GrVariable)resolved); - return reassigned ? DefaultHighlighter.REASSIGNED_LOCAL_VARIABLE : DefaultHighlighter.LOCAL_VARIABLE; - } - return null; - } - - public static boolean isDeclarationAssignment(GrReferenceExpression refExpr) { - if (isAssignmentLhs(refExpr)) { - return isExpandoQualified(refExpr); - } - return false; - } - - private static boolean isAssignmentLhs(GrReferenceExpression refExpr) { - return refExpr.getParent() instanceof GrAssignmentExpression && - refExpr.equals(((GrAssignmentExpression)refExpr.getParent()).getLValue()); - } - - private static boolean isExpandoQualified(GrReferenceExpression refExpr) { - final GrExpression qualifier = refExpr.getQualifierExpression(); - if (qualifier == null) { - final PsiClass clazz = PsiTreeUtil.getParentOfType(refExpr, PsiClass.class); - if (clazz == null) { //script - return true; - } - return false; //in class, a property should normally be defined, so it's not a declaration - } - - final PsiType type = qualifier.getType(); - if (type instanceof PsiClassType) { - final PsiClassType classType = (PsiClassType)type; - final PsiClass psiClass = classType.resolve(); - if (psiClass instanceof GroovyScriptClass) { - return true; - } - } - return false; - } - - public static boolean shouldHighlightAsUnresolved(@NotNull GrReferenceExpression referenceExpression) { - PsiElement refNameElement = referenceExpression.getReferenceNameElement(); - if (refNameElement != null && referenceExpression.getQualifier() == null) { - final IElementType type = refNameElement.getNode().getElementType(); - if (TokenSets.STRING_LITERAL_SET.contains(type)) return false; - } - - if (!GroovyUnresolvedHighlightFilter.shouldHighlight(referenceExpression)) return false; - - CollectConsumer consumer = new CollectConsumer(); - - for (PomDeclarationSearcher searcher : PomDeclarationSearcher.EP_NAME.getExtensions()) { - searcher.findDeclarationsAt(referenceExpression, 0, consumer); - if (consumer.getResult().size() > 0) return false; - } - - return true; - } - - public static TextRange getMethodHeaderTextRange(PsiMethod method) { - final PsiModifierList modifierList = method.getModifierList(); - final PsiParameterList parameterList = method.getParameterList(); - - final TextRange textRange = modifierList.getTextRange(); - LOG.assertTrue(textRange != null, method.getClass() + ":" + method.getText()); - int startOffset = textRange.getStartOffset(); - int endOffset = parameterList.getTextRange().getEndOffset() + 1; - - return new TextRange(startOffset, endOffset); - } - - @NotNull - public static PsiElement getElementToHighlight(@NotNull GrReferenceElement refElement) { - final PsiElement refNameElement = refElement.getReferenceNameElement(); - return refNameElement != null ? refNameElement : refElement; - } -} +/* + * 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 org.jetbrains.plugins.groovy.annotator; + +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.editor.colors.TextAttributesKey; +import com.intellij.openapi.util.TextRange; +import com.intellij.pom.PomDeclarationSearcher; +import com.intellij.pom.PomTarget; +import com.intellij.psi.*; +import com.intellij.psi.search.PsiElementProcessor; +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.CollectConsumer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.groovy.extensions.GroovyUnresolvedHighlightFilter; +import org.jetbrains.plugins.groovy.highlighter.DefaultHighlighter; +import org.jetbrains.plugins.groovy.lang.lexer.TokenSets; +import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod; +import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass; +import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils; +import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; +import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; + +/** + * @author Max Medvedev + */ +public class GrHighlightUtil { + private static final Logger LOG = Logger.getInstance(GrHighlightUtil.class); + + static boolean isReassigned(final GrVariable var) { + PsiMethod method = PsiTreeUtil.getParentOfType(var, PsiMethod.class); + PsiNamedElement scope = method == null ? var.getContainingFile() : method; + if (scope == null) { + return false; + } + return !PsiTreeUtil.processElements(scope, new PsiElementProcessor() { + boolean hasAssignment = var.getInitializerGroovy() != null || var instanceof GrParameter; + @Override + public boolean execute(@NotNull PsiElement element) { + if (element instanceof GrReferenceExpression && + var.getName().equals(((GrReferenceExpression)element).getReferenceName()) && + ((GrReferenceExpression)element).isReferenceTo(var)) { + if (PsiUtil.isLValue((GrReferenceExpression)element) || + element.getParent() instanceof GrUnaryExpression && ((GrUnaryExpression)element.getParent()).isPostfix()) { + if (hasAssignment) { + return false; + } + hasAssignment = true; + } + } + return true; + } + }); + } + + @Nullable + static TextAttributesKey getDeclarationHighlightingAttribute(PsiElement resolved) { + if (resolved instanceof PsiField || resolved instanceof GrVariable && ResolveUtil.isScriptField((GrVariable)resolved)) { + boolean isStatic = ((PsiVariable)resolved).hasModifierProperty(PsiModifier.STATIC); + return isStatic ? DefaultHighlighter.STATIC_FIELD : DefaultHighlighter.INSTANCE_FIELD; + } + else if (resolved instanceof GrAccessorMethod) { + boolean isStatic = ((GrAccessorMethod)resolved).hasModifierProperty(PsiModifier.STATIC); + return isStatic ? DefaultHighlighter.STATIC_PROPERTY_REFERENCE : DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE; + } + else if (resolved instanceof PsiMethod) { + if (!((PsiMethod)resolved).isConstructor()) { + boolean isStatic = ((PsiMethod)resolved).hasModifierProperty(PsiModifier.STATIC); + if (GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)resolved)) { + return isStatic ? DefaultHighlighter.STATIC_PROPERTY_REFERENCE : DefaultHighlighter.INSTANCE_PROPERTY_REFERENCE; + } + else { + return isStatic ? DefaultHighlighter.STATIC_METHOD_ACCESS : DefaultHighlighter.METHOD_CALL; + } + } + } + else if (resolved instanceof PsiTypeParameter) { + return DefaultHighlighter.TYPE_PARAMETER; + } + else if (resolved instanceof PsiClass) { + if (((PsiClass)resolved).isAnnotationType()) { + return DefaultHighlighter.ANNOTATION; + } + else { + return DefaultHighlighter.CLASS_REFERENCE; + } + } + else if (resolved instanceof GrParameter) { + boolean reassigned = isReassigned((GrParameter)resolved); + return reassigned ? DefaultHighlighter.REASSIGNED_PARAMETER : DefaultHighlighter.PARAMETER; + } + else if (resolved instanceof GrVariable) { + boolean reassigned = isReassigned((GrVariable)resolved); + return reassigned ? DefaultHighlighter.REASSIGNED_LOCAL_VARIABLE : DefaultHighlighter.LOCAL_VARIABLE; + } + return null; + } + + public static boolean isDeclarationAssignment(GrReferenceExpression refExpr) { + if (isAssignmentLhs(refExpr)) { + return isExpandoQualified(refExpr); + } + return false; + } + + private static boolean isAssignmentLhs(GrReferenceExpression refExpr) { + return refExpr.getParent() instanceof GrAssignmentExpression && + refExpr.equals(((GrAssignmentExpression)refExpr.getParent()).getLValue()); + } + + private static boolean isExpandoQualified(GrReferenceExpression refExpr) { + final GrExpression qualifier = refExpr.getQualifierExpression(); + if (qualifier == null) { + final PsiClass clazz = PsiTreeUtil.getParentOfType(refExpr, PsiClass.class); + if (clazz == null) { //script + return true; + } + return false; //in class, a property should normally be defined, so it's not a declaration + } + + final PsiType type = qualifier.getType(); + if (type instanceof PsiClassType) { + final PsiClassType classType = (PsiClassType)type; + final PsiClass psiClass = classType.resolve(); + if (psiClass instanceof GroovyScriptClass) { + return true; + } + } + return false; + } + + public static boolean shouldHighlightAsUnresolved(@NotNull GrReferenceExpression referenceExpression) { + PsiElement refNameElement = referenceExpression.getReferenceNameElement(); + if (refNameElement != null && referenceExpression.getQualifier() == null) { + final IElementType type = refNameElement.getNode().getElementType(); + if (TokenSets.STRING_LITERAL_SET.contains(type)) return false; + } + + if (!GroovyUnresolvedHighlightFilter.shouldHighlight(referenceExpression)) return false; + + CollectConsumer consumer = new CollectConsumer(); + + for (PomDeclarationSearcher searcher : PomDeclarationSearcher.EP_NAME.getExtensions()) { + searcher.findDeclarationsAt(referenceExpression, 0, consumer); + if (consumer.getResult().size() > 0) return false; + } + + return true; + } + + public static TextRange getMethodHeaderTextRange(PsiMethod method) { + final PsiModifierList modifierList = method.getModifierList(); + final PsiParameterList parameterList = method.getParameterList(); + + final TextRange textRange = modifierList.getTextRange(); + LOG.assertTrue(textRange != null, method.getClass() + ":" + method.getText()); + int startOffset = textRange.getStartOffset(); + int endOffset = parameterList.getTextRange().getEndOffset() + 1; + + return new TextRange(startOffset, endOffset); + } + + @NotNull + public static PsiElement getElementToHighlight(@NotNull GrReferenceElement refElement) { + final PsiElement refNameElement = refElement.getReferenceNameElement(); + return refNameElement != null ? refNameElement : refElement; + } +} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrReferenceHighlighter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrReferenceHighlighter.java index 6da3f86bf93d..59ddb6cbdee4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrReferenceHighlighter.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GrReferenceHighlighter.java @@ -1,88 +1,74 @@ -/* - * 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 org.jetbrains.plugins.groovy.annotator; - -import com.intellij.codeHighlighting.TextEditorHighlightingPass; -import com.intellij.codeInsight.daemon.impl.HighlightInfo; -import com.intellij.codeInsight.daemon.impl.HighlightInfoType; -import com.intellij.codeInsight.daemon.impl.UpdateHighlightersUtil; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.colors.TextAttributesKey; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement; -import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; -import org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor; -import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Max Medvedev - */ -public class GrReferenceHighlighter extends TextEditorHighlightingPass { - @NotNull private final GroovyFile myFile; - @Nullable private List myInfos = null; - - protected GrReferenceHighlighter(@Nullable Document document, @NotNull GroovyFile file) { - super(file.getProject(), document); - myFile = file; - } - - @Override - public void doCollectInformation(@NotNull ProgressIndicator progress) { - myInfos = new ArrayList(); - myFile.accept(new GroovyRecursiveElementVisitor() { - @Override - public void visitReferenceExpression(GrReferenceExpression referenceExpression) { - super.visitReferenceExpression(referenceExpression); - visit(referenceExpression); - } - - private void visit(GrReferenceElement element) { - final PsiElement resolved = element.resolve(); - final TextAttributesKey attribute = GrHighlightUtil.getDeclarationHighlightingAttribute(resolved); - if (attribute != null) { - final PsiElement refNameElement = GrHighlightUtil.getElementToHighlight(element); - myInfos.add(HighlightInfo.createHighlightInfo(HighlightInfoType.INFORMATION, refNameElement, null, attribute)); - } - } - - @Override - public void visitCodeReferenceElement(GrCodeReferenceElement refElement) { - super.visitCodeReferenceElement(refElement); - visit(refElement); - } - - @Override - public void visitAnnotation(GrAnnotation annotation) { - super.visitAnnotation(annotation); - visit(annotation.getClassReference()); - } - }); - } - - @Override - public void doApplyInformationToEditor() { - if (myInfos == null) return; - UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), myInfos, getColorsScheme(), getId()); - } -} +/* + * 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 org.jetbrains.plugins.groovy.annotator; + +import com.intellij.codeHighlighting.TextEditorHighlightingPass; +import com.intellij.codeInsight.daemon.impl.HighlightInfo; +import com.intellij.codeInsight.daemon.impl.HighlightInfoType; +import com.intellij.codeInsight.daemon.impl.UpdateHighlightersUtil; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.colors.TextAttributesKey; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiRecursiveElementWalkingVisitor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement; +import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Max Medvedev + */ +public class GrReferenceHighlighter extends TextEditorHighlightingPass { + @NotNull private final GroovyFile myFile; + @Nullable private List myInfos = null; + + protected GrReferenceHighlighter(@Nullable Document document, @NotNull GroovyFile file) { + super(file.getProject(), document); + myFile = file; + } + + @Override + public void doCollectInformation(@NotNull ProgressIndicator progress) { + myInfos = new ArrayList(); + myFile.accept(new PsiRecursiveElementWalkingVisitor() { + @Override + public void visitElement(PsiElement element) { + super.visitElement(element); + if (element instanceof GrReferenceElement) { + visit((GrReferenceElement)element); + } + } + private void visit(GrReferenceElement element) { + final PsiElement resolved = element.resolve(); + final TextAttributesKey attribute = GrHighlightUtil.getDeclarationHighlightingAttribute(resolved); + if (attribute != null) { + final PsiElement refNameElement = GrHighlightUtil.getElementToHighlight(element); + myInfos.add(HighlightInfo.createHighlightInfo(HighlightInfoType.INFORMATION, refNameElement, null, attribute)); + } + } + }); + } + + @Override + public void doApplyInformationToEditor() { + if (myInfos == null) return; + UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), myInfos, getColorsScheme(), getId()); + } +} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java index 0b332bc32bc8..8f5a2d5a3f25 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java @@ -56,7 +56,6 @@ import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes; import org.jetbrains.plugins.groovy.lang.psi.GrNamedElement; import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement; import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; -import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField; import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock; @@ -109,7 +108,6 @@ public class GroovyPostHighlightingPass extends TextEditorHighlightingPass { }; final List unusedDeclarations = new ArrayList(); - final Set unusedImports = new HashSet(PsiUtil.getValidImportStatements(myFile)); final Map usedParams = new HashMap(); myFile.accept(new PsiRecursiveElementWalkingVisitor() { @@ -156,13 +154,11 @@ public class GroovyPostHighlightingPass extends TextEditorHighlightingPass { } } - for (GrImportStatement used : GroovyImportOptimizer.findUsedImports(myFile)) { - unusedImports.remove(used); - } - super.visitElement(element); } }); + final Set unusedImports = new HashSet(PsiUtil.getValidImportStatements(myFile)); + unusedImports.removeAll(GroovyImportOptimizer.findUsedImports(myFile)); myUnusedImports = unusedImports; if (deadCodeEnabled) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/editor/GroovyImportOptimizer.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/editor/GroovyImportOptimizer.java index 31cf84c594d5..88fee646dbc2 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/editor/GroovyImportOptimizer.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/editor/GroovyImportOptimizer.java @@ -29,9 +29,11 @@ import gnu.trove.TObjectIntProcedure; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.codeStyle.GroovyCodeStyleSettings; -import org.jetbrains.plugins.groovy.lang.psi.*; +import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement; +import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; +import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; +import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement; import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; @@ -40,7 +42,8 @@ import org.jetbrains.plugins.groovy.lang.resolve.processors.ResolverProcessor; import java.util.*; -import static org.jetbrains.plugins.groovy.lang.editor.GroovyImportHelper.*; +import static org.jetbrains.plugins.groovy.lang.editor.GroovyImportHelper.isImplicitlyImported; +import static org.jetbrains.plugins.groovy.lang.editor.GroovyImportHelper.processImports; /** * @author ven @@ -72,16 +75,14 @@ public class GroovyImportOptimizer implements ImportOptimizer { @Nullable final Map annotations) { if (!(file instanceof GroovyFile)) return; - ((GroovyFile)file).accept(new GroovyRecursiveElementVisitor() { - public void visitCodeReferenceElement(GrCodeReferenceElement refElement) { - visitRefElement(refElement); - super.visitCodeReferenceElement(refElement); - } - - public void visitReferenceExpression(GrReferenceExpression referenceExpression) { - visitRefElement(referenceExpression); - super.visitReferenceExpression(referenceExpression); - } + ((GroovyFile)file).accept(new PsiRecursiveElementWalkingVisitor() { + @Override + public void visitElement(PsiElement element) { + super.visitElement(element); + if (element instanceof GrReferenceElement) { + visitRefElement((GrReferenceElement)element); + } + } private void visitRefElement(GrReferenceElement refElement) { final GroovyResolveResult[] resolveResults = refElement.multiResolve(false); diff --git a/plugins/properties/src/com/intellij/lang/properties/refactoring/PropertyRenameHandler.java b/plugins/properties/src/com/intellij/lang/properties/refactoring/PropertyRenameHandler.java index 70524010897d..99355d34bc6e 100644 --- a/plugins/properties/src/com/intellij/lang/properties/refactoring/PropertyRenameHandler.java +++ b/plugins/properties/src/com/intellij/lang/properties/refactoring/PropertyRenameHandler.java @@ -22,6 +22,7 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.ScrollType; import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference; import com.intellij.refactoring.rename.PsiElementRenameHandler; import com.intellij.lang.properties.references.PropertyReferenceBase; import org.jetbrains.annotations.NotNull; @@ -46,6 +47,14 @@ public class PropertyRenameHandler extends PsiElementRenameHandler { if (reference instanceof PropertyReferenceBase) { final ResolveResult[] resolveResults = ((PropertyReferenceBase)reference).multiResolve(false); return resolveResults.length > 0 ? resolveResults[0].getElement() : null; + } else if (reference instanceof PsiMultiReference) { + final PsiReference[] references = ((PsiMultiReference)reference).getReferences(); + for (PsiReference psiReference : references) { + if (psiReference instanceof PropertyReferenceBase) { + final ResolveResult[] resolveResults = ((PropertyReferenceBase)psiReference).multiResolve(false); + if (resolveResults.length > 0) return resolveResults[0].getElement(); + } + } } return null; } diff --git a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfiguration.java b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfiguration.java index 2c26dda1d5e1..c434216c6fa4 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfiguration.java +++ b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGConfiguration.java @@ -317,7 +317,7 @@ public class TestNGConfiguration extends ModuleBasedConfiguration + + + + +