JG13 from 183794: Warn when not using generics action-registration-183794
authorJaroslav Tulach <jtulach@netbeans.org>
Tue, 10 Aug 2010 10:06:26 +0200
branchaction-registration-183794
changeset 1754464e8dd82dab94
parent 175445 3b3ae1262864
child 175447 868cccdefce7
JG13 from 183794: Warn when not using generics
openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java
openide.awt/test/unit/src/org/netbeans/modules/openide/awt/ActionProcessorTest.java
     1.1 --- a/openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java	Tue Aug 10 10:01:10 2010 +0200
     1.2 +++ b/openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java	Tue Aug 10 10:06:26 2010 +0200
     1.3 @@ -213,6 +213,9 @@
     1.4          DeclaredType dt = (DeclaredType)ve.asType();
     1.5          String dtName = processingEnv.getElementUtils().getBinaryName((TypeElement)dt.asElement()).toString();
     1.6          if ("java.util.List".equals(dtName)) {
     1.7 +            if (dt.getTypeArguments().isEmpty()) {
     1.8 +                throw new LayerGenerationException("Use List<SomeType>", ee);
     1.9 +            }
    1.10              f.stringvalue("type", dt.getTypeArguments().get(0).toString());
    1.11              f.methodvalue("delegate", "org.openide.awt.Actions", "inject");
    1.12              f.stringvalue("injectable", processingEnv.getElementUtils().getBinaryName((TypeElement) e).toString());
     2.1 --- a/openide.awt/test/unit/src/org/netbeans/modules/openide/awt/ActionProcessorTest.java	Tue Aug 10 10:01:10 2010 +0200
     2.2 +++ b/openide.awt/test/unit/src/org/netbeans/modules/openide/awt/ActionProcessorTest.java	Tue Aug 10 10:06:26 2010 +0200
     2.3 @@ -42,7 +42,6 @@
     2.4  import java.awt.Component;
     2.5  import javax.swing.JMenuItem;
     2.6  import org.openide.util.actions.Presenter;
     2.7 -import java.beans.PropertyChangeListener;
     2.8  import java.io.IOException;
     2.9  import org.openide.util.test.AnnotationProcessorTestUtils;
    2.10  import java.util.Collections;
    2.11 @@ -495,4 +494,25 @@
    2.12          assertFalse("Compilation has to fail:\n" + os, r);
    2.13      }
    2.14      
    2.15 +    public void testListWithNoType() throws IOException {
    2.16 +        clearWorkDir();
    2.17 +        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A", 
    2.18 +            "import org.openide.awt.ActionRegistration;\n" +
    2.19 +            "import org.openide.awt.ActionID;\n" +
    2.20 +            "import org.openide.util.actions.Presenter;\n" +
    2.21 +            "import java.awt.event.*;\n" +
    2.22 +            "import java.util.List;\n" +
    2.23 +            "import javax.swing.*;\n" +
    2.24 +            "@ActionID(category=\"Tools\",id=\"my.action\")" +
    2.25 +            "@ActionRegistration(displayName=\"AAA\", key=\"K\") " +
    2.26 +            "public class A extends AbstractAction {\n" +
    2.27 +            "    public A(List wrongCnt) {}\n" +
    2.28 +            "    public void actionPerformed(ActionEvent e) {}" +
    2.29 +            "}\n"
    2.30 +        );
    2.31 +        ByteArrayOutputStream os = new ByteArrayOutputStream();
    2.32 +        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
    2.33 +        assertFalse("Compilation has to fail:\n" + os, r);
    2.34 +    }
    2.35 +    
    2.36  }
    2.37 \ No newline at end of file