Skip to content

Commit

Permalink
Eclipse 4.19 (M3) JDT Patch for Groovy-Eclipse: JDT commit 96e9f52
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Feb 22, 2021
1 parent fc4caf4 commit 146a2e3
Show file tree
Hide file tree
Showing 23 changed files with 410 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</license>

<requires>
<import feature="org.eclipse.jdt" version="3.18.700.v20210129-1800" patch="true"/>
<import feature="org.eclipse.jdt" version="3.18.700.v20210217-1800" patch="true"/>
</requires>

<plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,13 @@ protected void runTest(boolean shouldCompileOK, String[] testFiles, Object extra
&& (errCompareOK = semiNormalizedComparison(expectedErrOutputString,
errOutputString, outputDirNormalizer));
}
// test sanity of the test definition: did we forget to use "---OUTPUT_DIR_PLACEHOLDER---" instead of OUTPUT_DIR?
if (!outCompareOK) {
assertEquals("outputDirNormalizer should not affect expectedOutOutput", expectedOutOutputString, outputDirNormalizer.normalized(expectedOutOutputString));
}
if (!errCompareOK) {
assertEquals("outputDirNormalizer should not affect expectedErrOutput", expectedErrOutputString, outputDirNormalizer.normalized(expectedErrOutputString));
}
if (compileOK != shouldCompileOK || !compareOK) {
System.out.println(getClass().getName() + '#' + getName());
if (testFiles != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2014 IBM Corporation and others.
* Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -4941,4 +4941,42 @@ public void test163() {
"Javadoc: Invalid parameters declaration\n" +
"----------\n");
}

public void test164() {
this.runNegativeReferenceTest(
new String[] {
"X.java",
"package test;\n"
+ "public class X {\n"
+ " /**\n"
+ " * Invalid param and throws tags\n"
+ " * \n"
+ " * @param\n"
+ " * @throws\n"
+ " */\n"
+ " public void s_foo(int a) throws Exception {\n"
+ " }\n"
+ "}\n" },
"----------\n"
+ "1. ERROR in X.java (at line 6)\n"
+ " * @param\n"
+ " ^^^^^\n"
+ "Javadoc: Missing parameter name\n"
+ "----------\n"
+ "2. ERROR in X.java (at line 7)\n"
+ " * @throws\n"
+ " ^^^^^^\n"
+ "Javadoc: Missing class name\n"
+ "----------\n"
+ "3. ERROR in X.java (at line 9)\n"
+ " public void s_foo(int a) throws Exception {\n"
+ " ^\n"
+ "Javadoc: Missing tag for parameter a\n"
+ "----------\n"
+ "4. ERROR in X.java (at line 9)\n"
+ " public void s_foo(int a) throws Exception {\n"
+ " ^^^^^^^^^\n"
+ "Javadoc: Missing tag for declared exception Exception\n"
+ "----------\n");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -927,24 +927,24 @@ public void test490010NoEeaFile1() throws IOException {
Util.createFile(annots_java_lang + File.separator + "Object.eea",
TEST_440687_OBJECT_EEA_CONTENT);

runTest440687("-annotationpath CLASSPATH -classpath \"" + annots_dir2 + "\"",
File.pathSeparator + annots_dir1, // extra source path
"----------\n" +
"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 9)\n" +
" Test1 v = map.get(key);\n" +
" ^^^^^^^^^^^^\n" +
"Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull Map<@NonNull String,@NonNull Test1>\'. Type \'Map<K,V>\' doesn\'t seem to be designed with null type annotations in mind\n" +
"----------\n" +
"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 11)\n" +
" throw new RuntimeException(); // should not be reported as dead code, although V is a \'@NonNull Test1\'\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Dead code\n" +
"----------\n" +
"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 13)\n" +
" public boolean equals(@NonNull Object other) { return false; }\n" +
" ^^^^^^^^^^^^^^^\n" +
"Illegal redefinition of parameter other, inherited method from Object declares this parameter as @Nullable\n" +
"----------\n" +
runTest440687("-annotationpath CLASSPATH -classpath \"" + annots_dir2 + "\"",
File.pathSeparator + annots_dir1, // extra source path
"----------\n" +
"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 9)\n" +
" Test1 v = map.get(key);\n" +
" ^^^^^^^^^^^^\n" +
"Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull Map<@NonNull String,@NonNull Test1>\'. Type \'Map<K,V>\' doesn\'t seem to be designed with null type annotations in mind\n" +
"----------\n" +
"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 11)\n" +
" throw new RuntimeException(); // should not be reported as dead code, although V is a \'@NonNull Test1\'\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Dead code\n" +
"----------\n" +
"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 13)\n" +
" public boolean equals(@NonNull Object other) { return false; }\n" +
" ^^^^^^^^^^^^^^^\n" +
"Illegal redefinition of parameter other, inherited method from Object declares this parameter as @Nullable\n" +
"----------\n" +
"3 problems (3 warnings)\n",
true);
}
Expand All @@ -964,24 +964,24 @@ public void test490010NoEeaFile2() throws IOException {
Util.zip(new File(annots_dir2), zipName);
Util.delete(annots_dir2);

runTest440687("-annotationpath CLASSPATH -classpath \"" + zipName + "\"",
File.pathSeparator + annots_dir1, // extra source path
"----------\n" +
"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 9)\n" +
" Test1 v = map.get(key);\n" +
" ^^^^^^^^^^^^\n" +
"Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull Map<@NonNull String,@NonNull Test1>\'. Type \'Map<K,V>\' doesn\'t seem to be designed with null type annotations in mind\n" +
"----------\n" +
"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 11)\n" +
" throw new RuntimeException(); // should not be reported as dead code, although V is a \'@NonNull Test1\'\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Dead code\n" +
"----------\n" +
"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 13)\n" +
" public boolean equals(@NonNull Object other) { return false; }\n" +
" ^^^^^^^^^^^^^^^\n" +
"Illegal redefinition of parameter other, inherited method from Object declares this parameter as @Nullable\n" +
"----------\n" +
runTest440687("-annotationpath CLASSPATH -classpath \"" + zipName + "\"",
File.pathSeparator + annots_dir1, // extra source path
"----------\n" +
"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 9)\n" +
" Test1 v = map.get(key);\n" +
" ^^^^^^^^^^^^\n" +
"Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull Map<@NonNull String,@NonNull Test1>\'. Type \'Map<K,V>\' doesn\'t seem to be designed with null type annotations in mind\n" +
"----------\n" +
"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 11)\n" +
" throw new RuntimeException(); // should not be reported as dead code, although V is a \'@NonNull Test1\'\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Dead code\n" +
"----------\n" +
"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 13)\n" +
" public boolean equals(@NonNull Object other) { return false; }\n" +
" ^^^^^^^^^^^^^^^\n" +
"Illegal redefinition of parameter other, inherited method from Object declares this parameter as @Nullable\n" +
"----------\n" +
"3 problems (3 warnings)\n",
true);
}
Expand All @@ -1001,25 +1001,119 @@ public void test490010NoEeaFile3() throws IOException {
Util.zip(new File(annots_dir2), zipName);
Util.delete(annots_dir2);

runTest440687("-annotationpath \"" + zipName + "\"",
File.pathSeparator + annots_dir1, // extra source path
"----------\n" +
"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 9)\n" +
" Test1 v = map.get(key);\n" +
" ^^^^^^^^^^^^\n" +
"Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull Map<@NonNull String,@NonNull Test1>\'. Type \'Map<K,V>\' doesn\'t seem to be designed with null type annotations in mind\n" +
"----------\n" +
"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 11)\n" +
" throw new RuntimeException(); // should not be reported as dead code, although V is a \'@NonNull Test1\'\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Dead code\n" +
"----------\n" +
"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 13)\n" +
" public boolean equals(@NonNull Object other) { return false; }\n" +
" ^^^^^^^^^^^^^^^\n" +
"Illegal redefinition of parameter other, inherited method from Object declares this parameter as @Nullable\n" +
"----------\n" +
runTest440687("-annotationpath \"" + zipName + "\"",
File.pathSeparator + annots_dir1, // extra source path
"----------\n" +
"1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 9)\n" +
" Test1 v = map.get(key);\n" +
" ^^^^^^^^^^^^\n" +
"Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull Map<@NonNull String,@NonNull Test1>\'. Type \'Map<K,V>\' doesn\'t seem to be designed with null type annotations in mind\n" +
"----------\n" +
"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 11)\n" +
" throw new RuntimeException(); // should not be reported as dead code, although V is a \'@NonNull Test1\'\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Dead code\n" +
"----------\n" +
"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 13)\n" +
" public boolean equals(@NonNull Object other) { return false; }\n" +
" ^^^^^^^^^^^^^^^\n" +
"Illegal redefinition of parameter other, inherited method from Object declares this parameter as @Nullable\n" +
"----------\n" +
"3 problems (3 warnings)\n",
true);
}
public void testBug571055_explicit() throws IOException {
runTestBug571055(false, false);
}
public void testBug571055_inherit() throws IOException {
runTestBug571055(true, false);
}
public void testBug571055_dedicatedAnnotationPath() throws IOException {
runTestBug571055(false, true);
}
private void runTestBug571055(boolean inheritAnnotations, boolean dedicatedAnnotationPath) throws IOException {
String annots_dir = Util.getOutputDirectory() + File.separator + "annots";
String annots_api = annots_dir + File.separator + "api";
new File(annots_api).mkdirs();
Util.createFile(
annots_api + File.separator + "Foo.eea",
"class api/Foo\n" +
"m\n" +
" (Ljava/lang/String;)Ljava/lang/String;\n" +
" (L1java/lang/String;)L0java/lang/String;\n");
if (!inheritAnnotations) {
// 'manually' establish consistency:
String annots_impl = annots_dir + File.separator + "impl";
new File(annots_impl).mkdirs();
Util.createFile(
annots_impl + File.separator + "FooImpl.eea",
"class impl/FooImpl\n" +
"m\n" +
" (Ljava/lang/String;)Ljava/lang/String;\n" +
" (L1java/lang/String;)L0java/lang/String;\n");
}

String[] testFiles = new String[] {
"java/lang/annotation/ElementType.java",
ELEMENT_TYPE_18_CONTENT,
"org/eclipse/jdt/annotation/NonNull.java",
NONNULL_ANNOTATION_18_CONTENT,
"org/eclipse/jdt/annotation/Nullable.java",
NULLABLE_ANNOTATION_18_CONTENT,
"org/eclipse/jdt/annotation/DefaultLocation.java",
DEFAULT_LOCATION_CONTENT,
"api/Foo.java",
"package api;\n" +
"public interface Foo {\n" +
" String m(String a);\n" +
"}\n",
"impl/FooImpl.java",
"package impl;\n" +
"import api.Foo;\n" +
"public class FooImpl implements Foo {\n" +
" public String m(String a) { return null; }\n" + // ensure Foo & FooImpl are seen with consistent nullness
"}\n",
"test1/Test1.java",
"package test1;\n" +
"\n" +
"import api.Foo;\n" +
"\n" +
"public class Test1 {\n" +
" void test(Foo api) {\n" +
" String result = api.m(null);\n" +
" System.out.println(result.toUpperCase());\n" +
" }\n" +
"}\n"
};

String commandLine;
if (dedicatedAnnotationPath) {
commandLine = "-annotationpath \"" + annots_dir + "\" " +
" -1.8 -proc:none -err:+nullAnnot -warn:+null " +
(inheritAnnotations ? " -warn:+inheritNullAnnot ": "") +
" \"" + OUTPUT_DIR + "\"";
} else {
commandLine = "-annotationpath CLASSPATH " +
" -1.8 -proc:none -err:+nullAnnot -warn:+null " +
(inheritAnnotations ? " -warn:+inheritNullAnnot ": "") +
" -classpath \"" + annots_dir + "\" " +
" \"" + OUTPUT_DIR + "\"";
}

// expect eea-motivated problems in Test1 but no in FooImpl:
String expectedCompilerMessage =
"----------\n" +
"1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 7)\n" +
" String result = api.m(null);\n" +
" ^^^^\n" +
"Null type mismatch: required '@NonNull String' but the provided value is null\n" +
"----------\n" +
"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 8)\n" +
" System.out.println(result.toUpperCase());\n" +
" ^^^^^^\n" +
"Potential null pointer access: The variable result may be null at this location\n" +
"----------\n" +
"2 problems (1 error, 1 warning)\n";
this.runNegativeTest(testFiles, commandLine, "", expectedCompilerMessage, false);
}
}
2 changes: 1 addition & 1 deletion jdt-patch/e419/org.eclipse.jdt.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Export-Package: org.eclipse.jdt.core,
org.eclipse.jdt.internal.formatter.linewrap;x-internal:=true,
org.eclipse.jdt.internal.formatter.old;x-internal:=true,
org.codehaus.jdt.groovy.integration
Require-Bundle: org.eclipse.core.resources;bundle-version="[3.12.0,4.0.0)",
Require-Bundle: org.eclipse.core.resources;bundle-version="[3.14.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.13.0,4.0.0)",
org.eclipse.core.filesystem;bundle-version="[1.7.0,2.0.0)",
org.eclipse.text;bundle-version="[3.6.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageN
}
@Override
public boolean hasAnnotationFileFor(String qualifiedTypeName) {
return this.zipFile.getEntry(qualifiedTypeName+ExternalAnnotationProvider.ANNOTATION_FILE_SUFFIX) != null;
if (this.zipFile == null)
return false;
return this.zipFile.getEntry(qualifiedTypeName+ExternalAnnotationProvider.ANNOTATION_FILE_SUFFIX) != null;
}
@Override
public char[][][] findTypeNames(final String qualifiedPackageName, String moduleName) {
Expand Down Expand Up @@ -205,7 +207,7 @@ void acceptModule(ClassFileReader reader) {
}
}
void acceptModule(byte[] content) {
if (content == null)
if (content == null)
return;
ClassFileReader reader = null;
try {
Expand Down Expand Up @@ -235,7 +237,7 @@ public synchronized char[][] getModulesDeclaringPackage(String qualifiedPackageN

this.packageCache = new HashSet<>(41);
this.packageCache.add(Util.EMPTY_STRING);

for (Enumeration e = this.zipFile.entries(); e.hasMoreElements(); ) {
String fileName = ((ZipEntry) e.nextElement()).getName();
addToPackageCache(fileName, false);
Expand All @@ -254,7 +256,7 @@ public boolean hasCompilationUnit(String qualifiedPackageName, String moduleName
if (tail.toLowerCase().endsWith(SUFFIX_STRING_class))
return true;
}
}
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.io.File;
import java.io.IOException;
import java.util.function.Function;

import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
Expand All @@ -39,6 +40,11 @@ public class CompilationUnit implements ICompilationUnit {
// be written.
private boolean ignoreOptionalProblems;
private ModuleBinding moduleBinding;
/**
* annotation path can only be retrieved once the qualified type name is known.
* This is the provided function for computing the annotation path from that type name.
*/
private Function<String,String> annotationPathProvider;

public CompilationUnit(char[] contents, String fileName, String encoding) {
this(contents, fileName, encoding, null);
Expand All @@ -49,6 +55,12 @@ public CompilationUnit(char[] contents, String fileName, String encoding,
}
public CompilationUnit(char[] contents, String fileName, String encoding,
String destinationPath, boolean ignoreOptionalProblems, String modName) {
this(contents, fileName, encoding, destinationPath, ignoreOptionalProblems, modName, null);
}
public CompilationUnit(char[] contents, String fileName, String encoding, String destinationPath,
boolean ignoreOptionalProblems, String modName, Function<String,String> annotationPathProvider)
{
this.annotationPathProvider = annotationPathProvider;
this.contents = contents;
if (modName != null)
this.module = modName.toCharArray();
Expand Down Expand Up @@ -130,4 +142,10 @@ public ModuleBinding module(LookupEnvironment rootEnvironment) {
public String getDestinationPath() {
return this.destinationPath;
}
@Override
public String getExternalAnnotationPath(String qualifiedTypeName) {
if (this.annotationPathProvider != null)
return this.annotationPathProvider.apply(qualifiedTypeName);
return null;
}
}
Loading

0 comments on commit 146a2e3

Please sign in to comment.