summaryrefslogtreecommitdiff
path: root/plugins/IntentionPowerPak
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2013-02-27 09:41:48 -0800
committerJean-Baptiste Queru <jbq@google.com>2013-02-27 09:41:48 -0800
commit1d526b16d476792ca7ce47616d55833115e8d6ab (patch)
tree650fb03af01ff04097d1d59939518cc71be029cb /plugins/IntentionPowerPak
parent9edc8f6b58f71ec510ba36b838f115718d9a174d (diff)
downloadidea-1d526b16d476792ca7ce47616d55833115e8d6ab.tar.gz
Snapshot of commit 329607d9ebcedf2bb0ad81265354366db7dc3f9c
from branch master of git://git.jetbrains.org/idea/community.git Change-Id: I3b27d82897504da1b66169b67c7771e0f551c973
Diffstat (limited to 'plugins/IntentionPowerPak')
-rw-r--r--plugins/IntentionPowerPak/src/com/siyeh/ipp/annotation/ExpandToNormalAnnotationIntention.java57
-rw-r--r--plugins/IntentionPowerPak/src/com/siyeh/ipp/annotation/ExpandToNormalAnnotationPredicate.java20
-rw-r--r--plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/AlreadyHasName.java3
-rw-r--r--plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/MultiAttr.java3
-rw-r--r--plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/MultiAttr_after.java3
-rw-r--r--plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/OneAttr.java3
-rw-r--r--plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/OneAttr_after.java3
-rw-r--r--plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/Ambiguity.java2
-rw-r--r--plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/Ambiguity_after.java4
-rw-r--r--plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewDefaultConstructor.java6
-rw-r--r--plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewDefaultConstructor_after.java8
-rw-r--r--plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewRefsInnerClass.java4
-rw-r--r--plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewRefsInnerClass_after.java6
-rw-r--r--plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/TypeElementOnTheLeft.java2
-rw-r--r--plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/annotation/ExpandToNormalAnnotationIntentionTest.java42
15 files changed, 97 insertions, 69 deletions
diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/annotation/ExpandToNormalAnnotationIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/annotation/ExpandToNormalAnnotationIntention.java
index 2d9e5fdd3f96..22bfffc6d2e4 100644
--- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/annotation/ExpandToNormalAnnotationIntention.java
+++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/annotation/ExpandToNormalAnnotationIntention.java
@@ -30,7 +30,7 @@ public class ExpandToNormalAnnotationIntention extends MutablyNamedIntention {
@Override
protected String getTextForElement(PsiElement element) {
- final PsiAnnotation annotation = (PsiAnnotation)element;
+ final PsiNameValuePair annotation = (PsiNameValuePair)element;
final String text = buildReplacementText(annotation);
return IntentionPowerPackBundle.message(
"expand.to.normal.annotation.name", text);
@@ -42,51 +42,26 @@ public class ExpandToNormalAnnotationIntention extends MutablyNamedIntention {
return new ExpandToNormalAnnotationPredicate();
}
- public static String buildReplacementText(PsiAnnotation annotation) {
- final StringBuilder text = new StringBuilder("@");
- final PsiAnnotationParameterList parameterList =
- annotation.getParameterList();
- if (parameterList.getChildren().length == 0) {
- final PsiJavaCodeReferenceElement nameReferenceElement =
- annotation.getNameReferenceElement();
- if (nameReferenceElement != null) {
- text.append(nameReferenceElement.getText());
- }
- text.append("()");
- }
- else {
- final PsiNameValuePair[] attributes = parameterList.getAttributes();
- final PsiNameValuePair attribute = attributes[0];
- final PsiAnnotationMemberValue value = attribute.getValue();
- final PsiJavaCodeReferenceElement nameReferenceElement =
- annotation.getNameReferenceElement();
- if (nameReferenceElement != null) {
- text.append(nameReferenceElement.getText());
- }
- text.append("(value = ");
- if (value != null) {
- text.append(value.getText());
- }
- text.append(')');
+ public static String buildReplacementText(PsiNameValuePair attribute) {
+ final StringBuilder text = new StringBuilder();
+ final PsiAnnotationMemberValue value = attribute.getValue();
+ text.append("value = ");
+ if (value != null) {
+ text.append(value.getText());
}
return text.toString();
}
@Override
- protected void processIntention(@NotNull PsiElement element)
- throws IncorrectOperationException {
- final PsiAnnotation annotation = (PsiAnnotation)element;
- final int textOffset = annotation.getTextOffset();
- final Project project = annotation.getProject();
- final String text = buildReplacementText(annotation);
- final PsiElementFactory factory =
- JavaPsiFacade.getElementFactory(project);
- final PsiAnnotation newAnnotation =
- factory.createAnnotationFromText(
- text, annotation);
- annotation.replace(newAnnotation);
- final FileEditorManager editorManager =
- FileEditorManager.getInstance(project);
+ protected void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
+ final PsiNameValuePair attribute = (PsiNameValuePair)element;
+ final int textOffset = attribute.getTextOffset();
+ final Project project = attribute.getProject();
+ final String text = buildReplacementText(attribute);
+ final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
+ final PsiAnnotation newAnnotation = factory.createAnnotationFromText("@A(" + text +" )", attribute);
+ attribute.replace(newAnnotation.getParameterList().getAttributes()[0]);
+ final FileEditorManager editorManager = FileEditorManager.getInstance(project);
final Editor editor = editorManager.getSelectedTextEditor();
if (editor == null) {
return;
diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/annotation/ExpandToNormalAnnotationPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/annotation/ExpandToNormalAnnotationPredicate.java
index 5a7f25b7a4cc..83e343314576 100644
--- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/annotation/ExpandToNormalAnnotationPredicate.java
+++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/annotation/ExpandToNormalAnnotationPredicate.java
@@ -21,25 +21,17 @@ import com.siyeh.ipp.base.PsiElementPredicate;
class ExpandToNormalAnnotationPredicate implements PsiElementPredicate {
public boolean satisfiedBy(PsiElement element) {
- if (!(element instanceof PsiAnnotation)) {
+ if (!(element instanceof PsiNameValuePair)) {
return false;
}
- final PsiAnnotation annotation = (PsiAnnotation)element;
- final PsiAnnotationParameterList parameterList =
- annotation.getParameterList();
- if (parameterList.getChildren().length == 0) {
- return true;
- }
- final PsiNameValuePair[] attributes = parameterList.getAttributes();
- if (attributes.length != 1) {
- return false;
- }
- final PsiNameValuePair attribute = attributes[0];
+ final PsiNameValuePair attribute = (PsiNameValuePair)element;
+ if (attribute.getName() != null) return false;
+
final PsiAnnotationMemberValue value = attribute.getValue();
if (value == null) {
return false;
}
- final String name = attribute.getName();
- return name == null;
+
+ return true;
}
}
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/AlreadyHasName.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/AlreadyHasName.java
new file mode 100644
index 000000000000..6823f4ec30f6
--- /dev/null
+++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/AlreadyHasName.java
@@ -0,0 +1,3 @@
+@SuppressWarnings(value = "<caret>foo")
+public class Main {
+}
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/MultiAttr.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/MultiAttr.java
new file mode 100644
index 000000000000..47ce5f8d780d
--- /dev/null
+++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/MultiAttr.java
@@ -0,0 +1,3 @@
+@SuppressWarnings("<caret>foo", f = "bar")
+public class Main {
+}
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/MultiAttr_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/MultiAttr_after.java
new file mode 100644
index 000000000000..f86d257bad4b
--- /dev/null
+++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/MultiAttr_after.java
@@ -0,0 +1,3 @@
+@SuppressWarnings(value = "foo", f = "bar")
+public class Main {
+}
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/OneAttr.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/OneAttr.java
new file mode 100644
index 000000000000..54c7e943b6d9
--- /dev/null
+++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/OneAttr.java
@@ -0,0 +1,3 @@
+@SuppressWarnings("<caret>foo")
+public class Main {
+}
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/OneAttr_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/OneAttr_after.java
new file mode 100644
index 000000000000..43f2c1cc726b
--- /dev/null
+++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/expandToNormal/OneAttr_after.java
@@ -0,0 +1,3 @@
+@SuppressWarnings(value = "foo")
+public class Main {
+}
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/Ambiguity.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/Ambiguity.java
index f4b0d1c1772c..fa682838ad8e 100644
--- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/Ambiguity.java
+++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/Ambiguity.java
@@ -10,7 +10,7 @@ public class MyTest {
void m(Integer x);
}
- static void call(int i, I1 s) {}
+ static void call(Integer i, I1 s) {}
static void call(int i, I2 s) {}
public static void main(String[] args) {
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/Ambiguity_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/Ambiguity_after.java
index cadb53a71c48..b0e14f13dad8 100644
--- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/Ambiguity_after.java
+++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/Ambiguity_after.java
@@ -10,10 +10,10 @@ public class MyTest {
void m(Integer x);
}
- static void call(int i, I1 s) {}
+ static void call(Integer i, I1 s) {}
static void call(int i, I2 s) {}
public static void main(String[] args) {
- call(1, (I2) (x) -> MyTest.m(x));
+ call(1, (x) -> MyTest.m(x));
}
}
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewDefaultConstructor.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewDefaultConstructor.java
index 3dc2facab3c4..3e4e1727b067 100644
--- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewDefaultConstructor.java
+++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewDefaultConstructor.java
@@ -1,10 +1,12 @@
class Test1 {
- class Inner {}
+ static class Inner {
+ }
+
void test() {
BlahBlah6 blahBlah62 = Inner:<caret>:new;
}
}
interface BlahBlah6 {
- Test1.Inner foo6(Test1 p);
+ Test1.Inner foo6();
} \ No newline at end of file
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewDefaultConstructor_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewDefaultConstructor_after.java
index f346d7d7a18c..0183b2009c60 100644
--- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewDefaultConstructor_after.java
+++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewDefaultConstructor_after.java
@@ -1,10 +1,12 @@
class Test1 {
- class Inner {}
+ static class Inner {
+ }
+
void test() {
- BlahBlah6 blahBlah62 = (p) -> p.new Inner();
+ BlahBlah6 blahBlah62 = () -> new Inner();
}
}
interface BlahBlah6 {
- Test1.Inner foo6(Test1 p);
+ Test1.Inner foo6();
} \ No newline at end of file
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewRefsInnerClass.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewRefsInnerClass.java
index 3a28070d1db5..985c9a4a3094 100644
--- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewRefsInnerClass.java
+++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewRefsInnerClass.java
@@ -1,6 +1,6 @@
class MyTest {
- class Inner {
- Inner() {};
+ static class Inner {
+ Inner(MyTest mt) {};
}
interface I {
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewRefsInnerClass_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewRefsInnerClass_after.java
index 661cf589b482..600af263857a 100644
--- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewRefsInnerClass_after.java
+++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/NewRefsInnerClass_after.java
@@ -1,6 +1,6 @@
class MyTest {
- class Inner {
- Inner() {};
+ static class Inner {
+ Inner(MyTest mt) {};
}
interface I {
@@ -8,6 +8,6 @@ class MyTest {
}
static {
- I i1 = (receiver) -> receiver.new Inner();
+ I i1 = (receiver) -> new Inner(receiver);
}
}
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/TypeElementOnTheLeft.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/TypeElementOnTheLeft.java
index f3549e6c0c9c..4bb8270dc216 100644
--- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/TypeElementOnTheLeft.java
+++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/methodRefs2lambda/TypeElementOnTheLeft.java
@@ -4,6 +4,6 @@ class Test<T> {
class Bar {
void test() {
- Runnable runnable = Test<String>:<caret>:foo;
+ Runnable runnable = Test:<caret>:foo;
}
} \ No newline at end of file
diff --git a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/annotation/ExpandToNormalAnnotationIntentionTest.java b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/annotation/ExpandToNormalAnnotationIntentionTest.java
new file mode 100644
index 000000000000..dea52b1d28d3
--- /dev/null
+++ b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/annotation/ExpandToNormalAnnotationIntentionTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2000-2013 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.siyeh.ipp.annotation;
+
+import com.siyeh.ipp.IPPTestCase;
+
+public class ExpandToNormalAnnotationIntentionTest extends IPPTestCase {
+ public void testOneAttr() throws Exception {
+ doTest();
+ }
+
+ public void testMultiAttr() throws Exception {
+ doTest();
+ }
+
+ public void testAlreadyHasName() throws Exception {
+ assertIntentionNotAvailable();
+ }
+
+ @Override
+ protected String getIntentionName() {
+ return "Expand to 'value = \"foo\"'";
+ }
+
+ @Override
+ protected String getRelativePath() {
+ return "expandToNormal";
+ }
+}