Esempio n. 1
0
  @Override
  protected void setUp() throws Exception {
    Hashtable<String, String> options = TestOptions.getDefaultOptions();
    options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
    options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
    options.put(
        DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE,
        JavaCore.DO_NOT_INSERT);

    JavaCore.setOptions(options);

    IPreferenceStore store = JavaPlugin.getDefault().getPreferenceStore();
    store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, false);

    fJProject1 = Java18ProjectTestSetup.getProject();

    StubUtility.setCodeTemplate(CodeTemplateContextType.METHODSTUB_ID, "", null);
    StubUtility.setCodeTemplate(CodeTemplateContextType.CONSTRUCTORSTUB_ID, "", null);

    fSourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
  }
 @Override
 protected void setUp() throws Exception {
   fJProject1 = Java18ProjectTestSetup.getProject();
   fJProject1.getProject().getFolder(ANNOTATION_PATH).create(true, true, null);
   fJProject1.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED);
 }
Esempio n. 3
0
 @Override
 protected void tearDown() throws Exception {
   JavaProjectHelper.clear(fJProject1, Java18ProjectTestSetup.getDefaultClasspath());
 }
Esempio n. 4
0
  // bug 420116 : test for annotated varargs and return type
  public void testUnimplementedMethods4() throws Exception {
    JavaProjectHelper.addLibrary(
        fJProject1, new Path(Java18ProjectTestSetup.getJdtAnnotations20Path()));

    IPackageFragment pack2 = fSourceFolder.createPackageFragment("test1", false, null);

    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("import java.io.IOException;\n\n");
    buf.append("import org.eclipse.jdt.annotation.*;\n");
    buf.append("public interface Inter {\n");
    buf.append("    public int foo(@NonNull String @Nullable... s) throws IOException;\n");
    buf.append("    public int bar(@NonNull String... s) throws IOException;\n");
    buf.append("    static int staticMethod(Object[] o) throws IOException{return 10;}\n");
    buf.append("    default int defaultMethod(Object[] o) throws IOException{return 20;}\n");
    buf.append("}\n");
    buf.append("class E implements Inter{\n");
    buf.append("}\n");

    ICompilationUnit cu = pack2.createCompilationUnit("Inter.java", buf.toString(), false, null);

    CompilationUnit astRoot = getASTRoot(cu);
    ArrayList<IJavaCompletionProposal> proposals = collectCorrections(cu, astRoot, 2);
    assertNumberOfProposals(proposals, 2);
    assertCorrectLabels(proposals);

    CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(1);
    String preview1 = getPreviewContent(proposal);

    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("import java.io.IOException;\n\n");
    buf.append("import org.eclipse.jdt.annotation.*;\n");
    buf.append("public interface Inter {\n");
    buf.append("    public int foo(@NonNull String @Nullable... s) throws IOException;\n");
    buf.append("    public int bar(@NonNull String... s) throws IOException;\n");
    buf.append("    static int staticMethod(Object[] o) throws IOException{return 10;}\n");
    buf.append("    default int defaultMethod(Object[] o) throws IOException{return 20;}\n");
    buf.append("}\n");
    buf.append("abstract class E implements Inter{\n");
    buf.append("}\n");
    String expected1 = buf.toString();

    proposal = (CUCorrectionProposal) proposals.get(0);
    String preview2 = getPreviewContent(proposal);

    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("import java.io.IOException;\n\n");
    buf.append("import org.eclipse.jdt.annotation.*;\n");
    buf.append("public interface Inter {\n");
    buf.append("    public int foo(@NonNull String @Nullable... s) throws IOException;\n");
    buf.append("    public int bar(@NonNull String... s) throws IOException;\n");
    buf.append("    static int staticMethod(Object[] o) throws IOException{return 10;}\n");
    buf.append("    default int defaultMethod(Object[] o) throws IOException{return 20;}\n");
    buf.append("}\n");
    buf.append("class E implements Inter{\n");
    buf.append("\n");
    buf.append("    @Override\n");
    buf.append("    public int foo(@NonNull String @Nullable... s) throws IOException {\n");
    buf.append("        return 0;\n");
    buf.append("    }\n\n");
    buf.append("    @Override\n");
    buf.append("    public int bar(@NonNull String... s) throws IOException {\n");
    buf.append("        return 0;\n");
    buf.append("    }\n");
    buf.append("}\n");
    String expected2 = buf.toString();

    assertEqualStringsIgnoreOrder(
        new String[] {preview1, preview2}, new String[] {expected1, expected2});
  }