Skip to content

Commit

Permalink
Map Javac problems to JDT problems
Browse files Browse the repository at this point in the history
  • Loading branch information
testforstephen committed May 10, 2024
1 parent 550bc72 commit 7312c76
Show file tree
Hide file tree
Showing 41 changed files with 577 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package Ambiguous;

import Ambiguous.pkg1.*;
import Ambiguous.pkg2.*;

public class Ambiguous {
private void testAmbiguous1() {
// compiler.err.ref.ambiguous -> AmbiguousType(16777220)
A a;
// compiler.err.ref.ambiguous -> AmbiguousMethod(67108966)
method(1, 2);
}

void method(int i, double d) {
}

void method(double d, int m) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Ambiguous.pkg1;

public class A {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Ambiguous.pkg2;

public class A {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

// compiler.err.annotation.value.must.be.name.value -> UndefinedAnnotationMember(67109475)
@Retention(RetentionPolicy.RUNTIME, "error")
public @interface AnnotationMember {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

public abstract class BodyForAbstractMethod {
// compiler.err.abstract.meth.cant.have.body -> BodyForAbstractMethod(603979889)
abstract void testBodyForAbstractMethod() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class CodeCannotBeReached {
public void testCodeCannotBeReached() {
return;
// compiler.err.unreachable.stmt -> CodeCannotBeReached(536871073)
String reach = "";
}
}
5 changes: 5 additions & 0 deletions org.eclipse.jdt.core.javac/examples/diagnostics/File.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import java.io.File;
// compiler.err.already.defined.this.unit -> ConflictingImport(268435841)
public class File {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

// compiler.err.class.public.should.be.in.file -> PublicClassMustMatchFileName(16777541)
public class ClassName {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package IncompatibleExpInThrow;

// compiler.err.override.meth.doesnt.throw -> IncompatibleExceptionInThrowsClause(67109266)
public class Sub extends Super {
@Override
void foo() throws Exception {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package IncompatibleExpInThrow;

import java.io.IOException;

public class Super {
void foo() throws IOException {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package IncompatibleReturnType;

// compiler.err.override.incompatible.ret -> UndefinedAnnotationMember(67109475)
public class Sub extends Super {
@Override
void foo() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package IncompatibleReturnType;

import java.io.IOException;

public class Super {
String foo() {
return "foo";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

import java.io.File;
import java.io.IOException;
import java.io.FileNotFoundException;

public class InvalidUnionTypeReferenceSequenceCatch {
public void testInvalidUnionTypeReferenceSequence() {
try {
boolean success = new File("f").createNewFile();
} catch (FileNotFoundException | IOException e) {
// compiler.err.multicatch.types.must.be.disjoint -> InvalidUnionTypeReferenceSequence(553649001)

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

public class MethodReturnsVoid {
public void testVoidMethod() {

}

public String testMethodReturnsVoid() {
// compiler.err.prob.found.req -> MethodReturnsVoid(67108969)
return testVoidMethod();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

public class MissingReturnType {
// compiler.err.invalid.meth.decl.ret.type.req -> MissingReturnType(16777327)
public testMissingReturnType() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package MissingValueForAnnotationMember;

// compiler.err.annotation.missing.default.value -> MissingValueForAnnotationMember(16777825)
public class A {
@CustomAnnotation
public void testMissingValueForAnnotationMember() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package MissingValueForAnnotationMember;

public @interface CustomAnnotation {
String name();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

public class NoMessageSendOnArrayType {
public void testNoMessageSendOnArrayType() {
String[] test = {"1", "2"};
// compiler.err.cant.resolve.location.args -> NoMessageSendOnArrayType(67108980)
int size = test.size();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package NotVisibleConstructor;

public class A {
private String a;
private A(String a) {
this.a = a;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package NotVisibleConstructor;

public class B {
public void testNotVisibleConstructor() {
// compiler.err.report.access -> NotVisibleConstructor(134217859)
A a = new A("a");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package NotVisibleConstructorInDefaultConstructor;

// compiler.err.report.access -> NotVisibleConstructorInDefaultConstructor(134217869)
public class Sub extends Super {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package NotVisibleConstructorInDefaultConstructor;

public class Super {
private Super() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package NotVisibleMethod;

public class A {
private void a() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package NotVisibleMethod;

public class B {
public void testNotVisibleMethod() {
A a = new A();
// compiler.err.report.access -> NotVisibleMethod(67108965)
a.a();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package NotVisibleType;

public class A {
private class Inner {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package NotVisibleType;

public class B {
public void testNotVisibleType() {
// compiler.err.report.access -> NotVisibleType(16777219)
A.Inner i = new A.Inner();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

public class ParameterMismatch {

private String message;

private void setMessage(String message) {
this.message = message;
}

private void testMethodParameterMatch() {
// compiler.err.cant.apply.symbol -> ParameterMismatch(67108979)
this.setMessage();
}

void m(int i1) {}
void m(int i1, int i2) {}

ParameterMismatch() {
// compiler.err.cant.apply.symbols -> ParameterMismatch(67108979)
this.m();
}
}
29 changes: 29 additions & 0 deletions org.eclipse.jdt.core.javac/examples/diagnostics/TypeMismatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

import java.util.List;
import java.util.ArrayList;

public class TypeMismatch {
private void testTypeMismatch() {
// compiler.err.illegal.initializer.for.type -> TypeMismatch(16777233)
String a = { "a", "b" };
}

private void testTypeMismatch1() {
// compiler.err.prob.found.req -> TypeMismatch(16777233)
String a = new String[] { "a", "b" };
}

private String testReturnTypeMismatch() {
// compiler.err.prob.found.req -> ReturnTypeMismatch(16777235)
return new String[] { "a", "b" };
}


private void testIncompatibleTypesInForeach() {
List<Integer> intList = new ArrayList<>();
// compiler.err.prob.found.req -> IncompatibleTypesInForeach(16777796)
for (String s : intList) {
s.hashCode();
}
}
}
46 changes: 46 additions & 0 deletions org.eclipse.jdt.core.javac/examples/diagnostics/Undefined.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

import java.util.List;

public class Undefined {
Undefined(Integer x) {}

private void testUndefinedConstructor1() {
// compiler.err.cant.apply.symbols -> UndefinedConstructor(134217858)
String l = new String("s", "t");
}

void testUndefinedConstructor2() {
// compiler.err.cant.resolve.args -> UndefinedConstructor(134217858)
new Undefined(""){};
}

private void testUndefinedType() {
// compiler.err.cant.resolve.location -> UndefinedType(16777218)
UndefinedType a = new UndefinedType();
}

private void testUndefinedMethod1() {
// compiler.err.cant.resolve.location.args -> UndefinedMethod(67108964)
test();
}

private void testUndefinedMethod2() {
// compiler.err.cant.resolve.args.params -> UndefinedMethod(67108964)
Object o = new Object() {
{ this.<Integer,Double>m2(1, ""); }
};
}

private void testUndefinedMethod3() {
// compiler.err.cant.resolve.args -> UndefinedMethod(67108964)
new Runnable() {
{ unknown(); }
public void run() { }
};
}

private void testUndefinedMethod4() {
// compiler.err.cant.resolve.location.args.params -> UndefinedMethod(67108964)
Object o = List.<String>unknown();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package UndefinedConstructorInDefaultConstructor;

// compiler.err.cant.apply.symbol -> UndefinedConstructorInDefaultConstructor(134217868)
public class Sub extends Super {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package UndefinedConstructorInDefaultConstructor;

public class Super {
Super(int a) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

import java.io.IOException;

public class UnhandledException {
public void testUnhandledException() {
throw new IOException("IOExp");
}

public static class AutoCloseableClass implements AutoCloseable {
@Override
public void close() throws Exception {
System.out.println("close");
}
}

// compiler.err.unreported.exception.implicit.close -> UnhandledExceptionOnAutoClose(16778098)
public void testUnhandledExceptionOnAutoClose() {
try (AutoCloseableClass a = new AutoCloseableClass()) {
System.out.println("try-with-resource AutoCloseableClass");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package UnhandledExceptionInDefaultConstructor;

// compiler.err.unreported.exception.default.constructor -> UnhandledExceptionInDefaultConstructor(16777362)
public class Sub extends Super {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package UnhandledExceptionInDefaultConstructor;

public class Super {
Super() throws Exception {
throw new Exception("Exp");
}
}
Loading

0 comments on commit 7312c76

Please sign in to comment.