forked from eclipse-jdt/eclipse.jdt.core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'eclipse-jdt:master' into master
- Loading branch information
Showing
184 changed files
with
1,316 additions
and
782 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+9.14 KB
(100%)
org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
187 changes: 187 additions & 0 deletions
187
...ssors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java23ElementProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 IBM Corporation. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.jdt.compiler.apt.tests.processors.elements; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import javax.annotation.processing.Filer; | ||
import javax.annotation.processing.Messager; | ||
import javax.annotation.processing.ProcessingEnvironment; | ||
import javax.annotation.processing.RoundEnvironment; | ||
import javax.annotation.processing.SupportedAnnotationTypes; | ||
import javax.annotation.processing.SupportedSourceVersion; | ||
import javax.lang.model.SourceVersion; | ||
import javax.lang.model.element.Element; | ||
import javax.lang.model.element.ExecutableElement; | ||
import javax.lang.model.element.TypeElement; | ||
import javax.lang.model.util.Elements.DocCommentKind; | ||
import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor; | ||
|
||
/** | ||
* A processor that explores the Java 23 specific elements and validates the lambda and | ||
* type annotated elements. To enable this processor, add | ||
* -Aorg.eclipse.jdt.compiler.apt.tests.processors.elements.Java23ElementProcessor to the command line. | ||
*/ | ||
@SupportedAnnotationTypes("*") | ||
@SupportedSourceVersion(SourceVersion.RELEASE_8) | ||
public class Java23ElementProcessor extends BaseProcessor { | ||
boolean reportSuccessAlready = true; | ||
RoundEnvironment roundEnv = null; | ||
Messager _messager = null; | ||
Filer _filer = null; | ||
boolean isBinaryMode = false; | ||
String mode; | ||
@Override | ||
public synchronized void init(ProcessingEnvironment processingEnv) { | ||
super.init(processingEnv); | ||
_elementUtils = processingEnv.getElementUtils(); | ||
_messager = processingEnv.getMessager(); | ||
_filer = processingEnv.getFiler(); | ||
} | ||
// Always return false from this processor, because it supports "*". | ||
// The return value does not signify success or failure! | ||
@Override | ||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { | ||
if (roundEnv.processingOver()) { | ||
return false; | ||
} | ||
|
||
this.roundEnv = roundEnv; | ||
Map<String, String> options = processingEnv.getOptions(); | ||
if (!options.containsKey(this.getClass().getName())) { | ||
// Disable this processor unless we are intentionally performing the test. | ||
return false; | ||
} else { | ||
try { | ||
if (options.containsKey("binary")) { | ||
this.isBinaryMode = true; | ||
this.mode = "binary"; | ||
} else { | ||
this.mode = "source"; | ||
} | ||
if (!invokeTestMethods(options)) { | ||
testAll(); | ||
} | ||
if (this.reportSuccessAlready) { | ||
super.reportSuccess(); | ||
} | ||
} catch (AssertionFailedError e) { | ||
super.reportError(getExceptionStackTrace(e)); | ||
} catch (Throwable e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private boolean invokeTestMethods(Map<String, String> options) throws Throwable { | ||
Method testMethod = null; | ||
Set<String> keys = options.keySet(); | ||
boolean testsFound = false; | ||
for (String option : keys) { | ||
if (option.startsWith("test")) { | ||
try { | ||
testMethod = this.getClass().getDeclaredMethod(option, new Class[0]); | ||
if (testMethod != null) { | ||
testsFound = true; | ||
testMethod.invoke(this, new Object[0]); | ||
} | ||
} catch (InvocationTargetException e) { | ||
throw e.getCause(); | ||
} catch (Exception e) { | ||
super.reportError(getExceptionStackTrace(e)); | ||
} | ||
} | ||
} | ||
return testsFound; | ||
} | ||
|
||
public void testAll() throws AssertionFailedError, IOException { | ||
testJavadocKind1(); | ||
testJavadocKind2(); | ||
} | ||
|
||
public void testJavadocKind1() throws IOException { | ||
String typeName = "my.mod.Main1"; | ||
TypeElement typeElement = _elementUtils.getTypeElement(typeName); | ||
assertNotNull("type element should not be null", typeElement); | ||
DocCommentKind kind = _elementUtils.getDocCommentKind(typeElement); | ||
assertSame("Incorrect doc kind", DocCommentKind.TRADITIONAL, kind); | ||
List<? extends Element> enclosedElements = typeElement.getEnclosedElements(); | ||
ExecutableElement method = null; | ||
for (Element element : enclosedElements) { | ||
if ("myMethod".equals(element.getSimpleName().toString())) { | ||
method = (ExecutableElement) element; | ||
} | ||
} | ||
assertNotNull("method element should not be null", method); | ||
kind = _elementUtils.getDocCommentKind(method); | ||
assertSame("Incorrect doc kind", DocCommentKind.END_OF_LINE, kind); | ||
} | ||
public void testJavadocKind2() throws IOException { | ||
String typeName = "my.mod.Main2"; | ||
TypeElement typeElement = _elementUtils.getTypeElement(typeName); | ||
assertNotNull("type element should not be null", typeElement); | ||
DocCommentKind kind = _elementUtils.getDocCommentKind(typeElement); | ||
assertSame("Incorrect doc kind", DocCommentKind.END_OF_LINE, kind); | ||
List<? extends Element> enclosedElements = typeElement.getEnclosedElements(); | ||
ExecutableElement method = null; | ||
for (Element element : enclosedElements) { | ||
if ("myMethod".equals(element.getSimpleName().toString())) { | ||
method = (ExecutableElement) element; | ||
} | ||
} | ||
assertNotNull("method element should not be null", method); | ||
kind = _elementUtils.getDocCommentKind(method); | ||
assertSame("Incorrect doc kind", DocCommentKind.TRADITIONAL, kind); | ||
} | ||
|
||
@Override | ||
public void reportError(String msg) { | ||
throw new AssertionFailedError(msg); | ||
} | ||
private String getExceptionStackTrace(Throwable t) { | ||
StringBuilder buf = new StringBuilder(t.getMessage()); | ||
StackTraceElement[] traces = t.getStackTrace(); | ||
for (int i = 0; i < traces.length; i++) { | ||
StackTraceElement trace = traces[i]; | ||
buf.append("\n\tat " + trace); | ||
if (i == 12) | ||
break; // Don't dump all stacks | ||
} | ||
return buf.toString(); | ||
} | ||
public void assertSame(String msg, Object obj1, Object obj2) { | ||
if (obj1 != obj2) { | ||
reportError(msg + ", should be " + obj1.toString() + " but " + obj2.toString()); | ||
} | ||
} | ||
public void assertNotNull(String msg, Object obj) { | ||
if (obj == null) { | ||
reportError(msg); | ||
} | ||
} | ||
private static class AssertionFailedError extends Error { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public AssertionFailedError(String msg) { | ||
super(msg); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...pse.jdt.compiler.apt.tests/resources/mod_locations/modules23/module.main/module-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module module.main { | ||
exports my.mod; | ||
} |
12 changes: 12 additions & 0 deletions
12
...se.jdt.compiler.apt.tests/resources/mod_locations/modules23/module.main/my/mod/Main1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package my.mod; | ||
|
||
/** | ||
* A traditional Javadoc comment on a class | ||
*/ | ||
public class Main1 { | ||
/// | ||
/// A markdown type comment on a method | ||
/// | ||
public static void myMethod(String argv[]) { | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...se.jdt.compiler.apt.tests/resources/mod_locations/modules23/module.main/my/mod/Main2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package my.mod; | ||
|
||
/// | ||
/// A markdown type comment on a class | ||
/// | ||
public class Main2 { | ||
/** | ||
* A traditional Javadoc comment on a method | ||
*/ | ||
public static void myMethod(String argv[]) { | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
...se.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java23ElementsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 IBM Corporation. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.jdt.compiler.apt.tests; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import javax.lang.model.SourceVersion; | ||
import javax.tools.Diagnostic; | ||
import javax.tools.DiagnosticListener; | ||
import javax.tools.JavaCompiler; | ||
import javax.tools.ToolProvider; | ||
import junit.framework.TestCase; | ||
import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler; | ||
|
||
public class Java23ElementsTests extends TestCase { | ||
private static final String MODULE_PROC = "org.eclipse.jdt.compiler.apt.tests.processors.elements.Java23ElementProcessor"; | ||
|
||
public void testJavadocKind1() throws IOException { | ||
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); | ||
internalTestWithBinary(compiler, MODULE_PROC, "23", "testJavadocKind1", null, "modules23", false); | ||
} | ||
public void testJavadocKind2() throws IOException { | ||
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); | ||
internalTestWithBinary(compiler, MODULE_PROC, "23", "testJavadocKind2", null, "modules23", false); | ||
} | ||
public void testJavadocKind1Javac() throws IOException { | ||
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); | ||
internalTestWithBinary(compiler, MODULE_PROC, "23", "testJavadocKind1", null, "modules23", false); | ||
} | ||
public void testJavadocKind2Javac() throws IOException { | ||
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); | ||
internalTestWithBinary(compiler, MODULE_PROC, "23", "testJavadocKind2", null, "modules23", false); | ||
} | ||
@SuppressWarnings({ "rawtypes", "unchecked" }) | ||
protected void internalTestWithBinary(JavaCompiler compiler, String processor, String compliance, String testMethod, String testClass, String resourceArea, | ||
boolean processBinariesAgain) throws IOException { | ||
if (!canRunJava23()) { | ||
return; | ||
} | ||
System.clearProperty(processor); | ||
File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "mod_locations", resourceArea); | ||
if (testClass == null || testClass.equals("")) { | ||
BatchTestUtils.copyResources("mod_locations/" + resourceArea, targetFolder); | ||
} else { | ||
BatchTestUtils.copyResource("mod_locations/" + resourceArea + "/" + testClass, targetFolder); | ||
} | ||
|
||
List<String> options = new ArrayList<>(); | ||
options.add("-A" + processor); | ||
options.add("-A" + testMethod); | ||
options.add("-processor"); | ||
options.add(processor); | ||
// Javac 1.8 doesn't (yet?) support the -1.8 option | ||
if (compiler instanceof EclipseCompiler) { | ||
options.add("-" + compliance); | ||
} else { | ||
options.add("-source"); | ||
options.add(compliance); | ||
} | ||
BatchTestUtils.compileInModuleMode(compiler, options, processor, targetFolder, new DiagnosticListener() { | ||
@Override | ||
public void report(Diagnostic d) { | ||
if (d.getKind() == Diagnostic.Kind.ERROR) { | ||
System.out.println("Compilation error: " + d.getMessage(Locale.getDefault())); | ||
} | ||
} | ||
}, true, processBinariesAgain); | ||
// If it succeeded, the processor will have set this property to "succeeded"; | ||
// if not, it will set it to an error value. | ||
assertEquals("succeeded", System.getProperty(processor)); | ||
} | ||
public boolean canRunJava23() { | ||
try { | ||
SourceVersion.valueOf("RELEASE_23"); | ||
} catch(IllegalArgumentException iae) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
/* (non-Javadoc) | ||
* @see junit.framework.TestCase#setUp() | ||
*/ | ||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
BatchTestUtils.init(); | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see junit.framework.TestCase#tearDown() | ||
*/ | ||
@Override | ||
protected void tearDown() throws Exception { | ||
super.tearDown(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Oops, something went wrong.