diff --git a/.idea/runConfigurations/SimpleCodeInsightTest.xml b/.idea/runConfigurations/SimpleCodeInsightTest.xml
index 18fea3282..7459aee87 100644
--- a/.idea/runConfigurations/SimpleCodeInsightTest.xml
+++ b/.idea/runConfigurations/SimpleCodeInsightTest.xml
@@ -11,7 +11,7 @@
-
+
diff --git a/src/com/simpleplugin/CreatePropertyQuickFix.java b/src/com/simpleplugin/CreatePropertyQuickFix.java
index ecb5ced18..aa58b49d2 100644
--- a/src/com/simpleplugin/CreatePropertyQuickFix.java
+++ b/src/com/simpleplugin/CreatePropertyQuickFix.java
@@ -13,13 +13,18 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.Navigatable;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
+import com.intellij.psi.search.FileTypeIndex;
+import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.IncorrectOperationException;
+import com.intellij.util.indexing.FileBasedIndex;
import com.simpleplugin.psi.SimpleElementFactory;
import com.simpleplugin.psi.SimpleFile;
import com.simpleplugin.psi.SimpleProperty;
import com.simpleplugin.psi.SimpleTypes;
import org.jetbrains.annotations.NotNull;
+import java.util.Collection;
+
class CreatePropertyQuickFix extends BaseIntentionAction {
private String key;
@@ -49,27 +54,37 @@ class CreatePropertyQuickFix extends BaseIntentionAction {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
- final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(SimpleFileType.INSTANCE);
- descriptor.setRoots(project.getBaseDir());
- final VirtualFile file = FileChooser.chooseFile(descriptor, project, null);
- if (file != null) {
- ApplicationManager.getApplication().runWriteAction(new Runnable() {
- @Override
- public void run() {
- SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(file);
- ASTNode lastChildNode = simpleFile.getNode().getLastChildNode();
- if (lastChildNode != null && !lastChildNode.getElementType().equals(SimpleTypes.CRLF)) {
- simpleFile.getNode().addChild(SimpleElementFactory.createCRLF(project).getNode());
- }
- SimpleProperty property = SimpleElementFactory.createProperty(project, key, "");
- simpleFile.getNode().addChild(property.getNode());
- ((Navigatable) property.getLastChild().getNavigationElement()).navigate(true);
- FileEditorManager.getInstance(project).getSelectedTextEditor().getCaretModel().
- moveCaretRelatively(2, 0, false, false, false);
- }
- });
+ Collection virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SimpleFileType.INSTANCE,
+ GlobalSearchScope.allScope(project));
+ if (virtualFiles.size() == 1) {
+ createProperty(project, virtualFiles.iterator().next());
+ } else {
+ final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(SimpleFileType.INSTANCE);
+ descriptor.setRoots(project.getBaseDir());
+ final VirtualFile file = FileChooser.chooseFile(descriptor, project, null);
+ if (file != null) {
+ createProperty(project, file);
+ }
}
}
});
}
+
+ private void createProperty(final Project project, final VirtualFile file) {
+ ApplicationManager.getApplication().runWriteAction(new Runnable() {
+ @Override
+ public void run() {
+ SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(file);
+ ASTNode lastChildNode = simpleFile.getNode().getLastChildNode();
+ if (lastChildNode != null && !lastChildNode.getElementType().equals(SimpleTypes.CRLF)) {
+ simpleFile.getNode().addChild(SimpleElementFactory.createCRLF(project).getNode());
+ }
+ SimpleProperty property = SimpleElementFactory.createProperty(project, key, "");
+ simpleFile.getNode().addChild(property.getNode());
+ ((Navigatable) property.getLastChild().getNavigationElement()).navigate(true);
+ FileEditorManager.getInstance(project).getSelectedTextEditor().getCaretModel().
+ moveCaretRelatively(2, 0, false, false, false);
+ }
+ });
+ }
}
diff --git a/testData/FindUsagesTestData.java b/testData/FindUsagesTestData.java
new file mode 100644
index 000000000..14d4ec27c
--- /dev/null
+++ b/testData/FindUsagesTestData.java
@@ -0,0 +1,5 @@
+public class Test {
+ public static void main(String[] args) {
+ System.out.println("simple:website");
+ }
+}
diff --git a/testData/FindUsagesTestData.simple b/testData/FindUsagesTestData.simple
new file mode 100644
index 000000000..b0bbbca98
--- /dev/null
+++ b/testData/FindUsagesTestData.simple
@@ -0,0 +1,13 @@
+# You are reading the ".properties" entry.
+! The exclamation mark can also mark text as comments.
+website = http://en.wikipedia.org/
+
+language = English
+# The backslash below tells the application to continue reading
+# the value onto the next line.
+message = Welcome to \
+ Wikipedia!
+# Add spaces to the key
+key\ with\ spaces = This is the value that could be looked up with the key "key with spaces".
+# Unicode
+tab : \u0009
\ No newline at end of file
diff --git a/tests/com/simpleplugin/SimpleCodeInsightTest.java b/tests/com/simpleplugin/SimpleCodeInsightTest.java
index 5874da196..04f3dc6d8 100644
--- a/tests/com/simpleplugin/SimpleCodeInsightTest.java
+++ b/tests/com/simpleplugin/SimpleCodeInsightTest.java
@@ -7,8 +7,12 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
+import com.intellij.usageView.UsageInfo;
+import com.intellij.util.indexing.FileBasedIndex;
import com.simpleplugin.psi.SimpleProperty;
+import java.util.Collection;
+
public class SimpleCodeInsightTest extends LightCodeInsightFixtureTestCase {
@Override
protected String getTestDataPath() {
@@ -29,7 +33,6 @@ public class SimpleCodeInsightTest extends LightCodeInsightFixtureTestCase {
public void testAnnotations() {
myFixture.configureByFiles("AnnotationTest.java", "Example.simple");
- System.out.println(getProjectDescriptor().getSdk());
myFixture.checkHighlighting(false, false, true);
}
@@ -64,4 +67,9 @@ public class SimpleCodeInsightTest extends LightCodeInsightFixtureTestCase {
commentAction.actionPerformedImpl(getProject(), myFixture.getEditor());
myFixture.checkResult("website = http://en.wikipedia.org/");
}
+
+ public void testFindUsages() {
+ Collection usageInfos = myFixture.testFindUsages("FindUsagesTestData.simple", "FindUsagesTestData.java");
+ assertEquals(1, usageInfos.size());
+ }
}
\ No newline at end of file