Skip to content

Commit

Permalink
Merge pull request #3459 from jarthana/BETA_JAVA24
Browse files Browse the repository at this point in the history
Merge master into BETA_JAVA24
  • Loading branch information
jarthana authored Dec 16, 2024
2 parents feb6e0c + e2eff6b commit f0bc53d
Show file tree
Hide file tree
Showing 72 changed files with 1,197 additions and 1,369 deletions.
3 changes: 3 additions & 0 deletions JCL/javax23api/src/javax/lang/model/util/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ DeclaredType getDeclaredType(DeclaredType containing,
TypeElement typeElem, TypeMirror... typeArgs);

TypeMirror asMemberOf(DeclaredType containing, Element element);
default <T extends TypeMirror> T stripAnnotations(T t) {
throw new UnsupportedOperationException();
}
}
2 changes: 1 addition & 1 deletion org.eclipse.jdt.compiler.apt.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.compiler.apt.tests;singleton:=true
Bundle-Version: 1.3.600.qualifier
Bundle-Version: 1.3.700.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-17
Expand Down
Binary file modified org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
Binary file not shown.
Binary file modified org.eclipse.jdt.compiler.apt.tests/lib/javax23api.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions org.eclipse.jdt.compiler.apt.tests/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012, 2023 Eclipse Foundation and others.
Copyright (c) 2012, 2024 Eclipse Foundation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v1.0
which accompanies this distribution, and is available at
Expand All @@ -19,7 +19,7 @@
<relativePath>../tests-pom/</relativePath>
</parent>
<artifactId>org.eclipse.jdt.compiler.apt.tests</artifactId>
<version>1.3.600-SNAPSHOT</version>
<version>1.3.700-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.ElementFilter;
import javax.lang.model.util.Elements.DocCommentKind;
import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor;

Expand Down Expand Up @@ -206,6 +211,53 @@ public void testMarkdownContent3() throws IOException {
+ "@param p parameter", docComment);
}

public void testStripAnnotations() {
String typeName = "my.mod.Main3";
String annotationName = "my.annot.MyAnnotation";
TypeElement typeElement = _elementUtils.getTypeElement(typeName);
List<? extends TypeMirror> interfaces = typeElement.getInterfaces();
assertEquals("Wrong no of super interfaces", 1, interfaces.size());
TypeMirror superclass = interfaces.get(0);
List<? extends AnnotationMirror> annotations = superclass.getAnnotationMirrors();
assertEquals("Incorrect no of annotations", 1, annotations.size());
TypeMirror withoutAnnotations = _typeUtils.stripAnnotations(superclass);
assertTrue("Type should not have any annotations", withoutAnnotations.getAnnotationMirrors().isEmpty());
assertTrue("Should be of the same type", _typeUtils.isSameType(superclass, withoutAnnotations));
List<ExecutableElement> methods = ElementFilter.methodsIn(typeElement.getEnclosedElements());
for (ExecutableElement method : methods) {
if (method.getSimpleName().toString().equals("run")) {
continue;
}
TypeMirror typeMirror = method.getReturnType();

TypeMirror expAnnotation = _elementUtils.getTypeElement(annotationName).asType();
annotations = typeMirror.getAnnotationMirrors();
assertEquals("Incorrect no of annotations", 1, annotations.size());
DeclaredType annotationType = typeMirror.getAnnotationMirrors().get(0).getAnnotationType();
assertTrue("Incorrecton annotation type", _typeUtils.isSameType(expAnnotation, annotationType));

// after stripAnnotations() TypeMirror should not have any annotations.
withoutAnnotations = _typeUtils.stripAnnotations(typeMirror);
assertTrue("Type should not have any annotations", withoutAnnotations.getAnnotationMirrors().isEmpty());

TypeMirror typeMirror1 = null;
if (typeMirror.getKind() != TypeKind.WILDCARD) {
assertTrue("Should be of the same type", _typeUtils.isSameType(typeMirror, withoutAnnotations));
} else {
typeMirror1 = _typeUtils.getWildcardType(typeMirror, null);
annotations = typeMirror.getAnnotationMirrors();
assertTrue("Type should not have any annotations", typeMirror1.getAnnotationMirrors().isEmpty());
}

typeMirror1 = _typeUtils.erasure(typeMirror);
annotations = typeMirror.getAnnotationMirrors();
assertEquals("Incorrect no of annotations", 1, annotations.size());

typeMirror1 = _typeUtils.getArrayType(typeMirror);
annotations = typeMirror.getAnnotationMirrors();
assertEquals("Incorrect no of annotations", 1, annotations.size());
}
}
@Override
public void reportError(String msg) {
throw new AssertionFailedError(msg);
Expand Down Expand Up @@ -253,6 +305,11 @@ public void assertNotNull(String msg, Object obj) {
reportError(msg);
}
}
public void assertTrue(String msg, boolean result) {
if (!result) {
reportError(msg);
}
}
private static class AssertionFailedError extends Error {
private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ public void testModuleTypeMirror1() {
TypeMirror asType = base.asType();
assertNotNull("module type should not be null", asType);
assertEquals("incorrect type kind", TypeKind.MODULE, asType.getKind());
assertEquals("must be a NoType", (asType instanceof NoType));
assertTrue("must be a NoType", (asType instanceof NoType));
}
public void testModuleTypeMirror2() {
ModuleElement base = _elementUtils.getModuleElement("mod.a");
Expand Down Expand Up @@ -1308,11 +1308,6 @@ public void assertEquals(String msg, int expected, int actual) {
reportError(buf.toString());
}
}
public void assertEquals(Object expected, Object actual) {
if (expected != actual) {

}
}
private void verifyAnnotations(AnnotatedConstruct construct, String[] annots) {
List<? extends AnnotationMirror> annotations = construct.getAnnotationMirrors();
assertEquals("Incorrect no of annotations", annots.length, annotations.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package my.annot;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target(ElementType.TYPE_USE)
public @interface MyAnnotation {
String value() default "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package my.mod;

import my.annot.*;

public class Main3 implements @MyAnnotation Runnable {

public void run() {
}

public static @MyAnnotation("1") int method1() {
return 0;
}

public static @MyAnnotation("2") Integer method2() {
return null;
}

public static @MyAnnotation("3") String method3() {
return null;
}

public static String @MyAnnotation("4") [] method4() {
return null;
}

public static java.util.@MyAnnotation("5") Set<@MyAnnotation("6") String> method5() {
return null;
}

public static <@MyAnnotation("7") T extends @MyAnnotation("8") String> @MyAnnotation("9") T method6() {
return null;
}

public static java.util.@MyAnnotation("10") Set<@MyAnnotation("11") ? extends @MyAnnotation("12") Number> method7() {
return null;
}

public static <@MyAnnotation("13") S extends Number & Runnable> @MyAnnotation("14") S method8() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -217,4 +218,81 @@ public void testBug530665() throws IOException {
assertTrue(!preexistsFile.exists()); // deleted
assertTrue(nonexistsFile.exists()); // rewritten
}
public void testGHIssue2347_1() throws IOException {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
File folder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "AnnotationProcessorTests", "bug540090");
BatchTestUtils.copyResources("targets/AnnotationProcessorTests/bug540090", folder);
List<String> options = new ArrayList<>();
final String PROC = "org.eclipse.jdt.compiler.apt.tests.processors.AnnotationProcessorTests.Bug540090Proc";
options.add("-processorpath");
options.add(" ");
options.add("-processor");
options.add(PROC);
options.add("-proc:full");
options.add("-verbose");
StringWriter stringWriter = new StringWriter();
BatchTestUtils.compileTree(stringWriter, compiler, options, folder, null);
folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090");
String output = stringWriter.getBuffer().toString();
assertTrue("Files not generated as expected", output.contains("[3 .class files generated]"));
}
public void testGHIssue2347_2() throws IOException {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
File folder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "AnnotationProcessorTests", "bug540090");
BatchTestUtils.copyResources("targets/AnnotationProcessorTests/bug540090", folder);
List<String> options = new ArrayList<>();
final String PROC = "org.eclipse.jdt.compiler.apt.tests.processors.AnnotationProcessorTests.Bug540090Proc";
options.add("-processorpath");
options.add(" ");
options.add("-processor");
options.add(PROC);
options.add("-proc:only");
options.add("-proc:full");
options.add("-verbose");
StringWriter stringWriter = new StringWriter();
BatchTestUtils.compileTree(stringWriter, compiler, options, folder, null);
folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090");
String output = stringWriter.getBuffer().toString();
assertTrue("Files not generated as expected", output.contains("[3 .class files generated]"));

}
public void testGHIssue2347_3() throws IOException {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
File folder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "AnnotationProcessorTests", "bug540090");
BatchTestUtils.copyResources("targets/AnnotationProcessorTests/bug540090", folder);
List<String> options = new ArrayList<>();
final String PROC = "org.eclipse.jdt.compiler.apt.tests.processors.AnnotationProcessorTests.Bug540090Proc";
options.add("-processorpath");
options.add(" ");
options.add("-processor");
options.add(PROC);
options.add("-proc:none");
options.add("-proc:full");
options.add("-verbose");
StringWriter stringWriter = new StringWriter();
BatchTestUtils.compileTree(stringWriter, compiler, options, folder, null);
folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090");
String output = stringWriter.getBuffer().toString();
assertTrue("Files not generated as expected", output.contains("[3 .class files generated]"));
}
public void testGHIssue2347_4() throws IOException {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
File folder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "AnnotationProcessorTests", "bug540090");
BatchTestUtils.copyResources("targets/AnnotationProcessorTests/bug540090", folder);
List<String> options = new ArrayList<>();
final String PROC = "org.eclipse.jdt.compiler.apt.tests.processors.AnnotationProcessorTests.Bug540090Proc";
options.add("-processorpath");
options.add(" ");
options.add("-processor");
options.add(PROC);
options.add("-proc:none");
options.add("-proc:only");
BatchTestUtils.compileTree(compiler, options, folder, null);
folder = TestUtils.concatPath(BatchTestUtils.getBinFolderName(), "targets", "AnnotationProcessorTests", "bug540090");
File classfile = new File(folder, "B.class");
assertFalse(classfile.exists());
folder = TestUtils.concatPath(BatchTestUtils.getGenFolderName(), "gen");
classfile = new File(folder, "GenClass.java");
assertTrue(classfile.exists());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ public static void compileTree(JavaCompiler compiler, List<String> options, File
compileTree(compiler, options, targetFolder, false);
}

public static void compileTree(StringWriter stringWriter, JavaCompiler compiler, List<String> options, File targetFolder,
DiagnosticListener<? super JavaFileObject> listener) {
compileTree(stringWriter, compiler, options, targetFolder, false, listener);
}

public static void compileTree(JavaCompiler compiler, List<String> options, File targetFolder,
DiagnosticListener<? super JavaFileObject> listener) {
compileTree(compiler, options, targetFolder, false, listener);
Expand Down Expand Up @@ -230,13 +235,18 @@ public int compare(File f1, File f2) {
public static void compileTree(JavaCompiler compiler, List<String> options,
File targetFolder, boolean useJLS8Processors,
DiagnosticListener<? super JavaFileObject> listener) {
StringWriter stringWriter = new StringWriter();
compileTree(stringWriter, compiler, options, targetFolder, useJLS8Processors, listener);
}
public static void compileTree(StringWriter stringWriter, JavaCompiler compiler, List<String> options,
File targetFolder, boolean useJLS8Processors,
DiagnosticListener<? super JavaFileObject> listener) {
StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());

// create new list containing inputfile
List<File> files = new ArrayList<>();
findFilesUnder(targetFolder, files);
Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);

options.add("-d");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public void testMarkdownContent3Javac() throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
internalTestWithBinary(compiler, MODULE_PROC, "23", "testMarkdownContent3", null, "modules23", false);
}
public void testStripAnnotations() throws IOException {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
internalTestWithBinary(compiler, MODULE_PROC, "23", "testStripAnnotations", null, "modules23", false);
}
public void testStripAnnotationsJavac() throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
internalTestWithBinary(compiler, MODULE_PROC, "23", "testStripAnnotations", 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 {
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.compiler.tool.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.compiler.tool.tests
Bundle-Version: 1.4.600.qualifier
Bundle-Version: 1.4.700.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-17
Expand Down
Binary file modified org.eclipse.jdt.compiler.tool.tests/lib/javax23api.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions org.eclipse.jdt.compiler.tool.tests/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012, 2017 Eclipse Foundation and others.
Copyright (c) 2012, 2024 Eclipse Foundation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v1.0
which accompanies this distribution, and is available at
Expand All @@ -19,7 +19,7 @@
<relativePath>../tests-pom/</relativePath>
</parent>
<artifactId>org.eclipse.jdt.compiler.tool.tests</artifactId>
<version>1.4.600-SNAPSHOT</version>
<version>1.4.700-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
<testSuite>${project.artifactId}</testSuite>
Expand Down
Binary file modified org.eclipse.jdt.core.compiler.batch/lib/javax23api.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3750,7 +3750,7 @@ public static final char[] replace(
next : for (int i = 0; i < max;) {
int index = indexOf(toBeReplaced, array, true, i);
if (index == -1) {
i++;
i = max; // end
continue next;
}
if (occurrenceCount == starts.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,15 @@ public PrimitiveType unboxedType(TypeMirror t) {
return (PrimitiveType) this._env.getFactory().newTypeMirror(unboxed);
}

@Override
@SuppressWarnings("unchecked")
public <T extends TypeMirror> T stripAnnotations(T t) {
if (t instanceof TypeMirrorImpl typeImpl) {
Binding b = typeImpl.binding();
if (b instanceof TypeBinding typeBinding) {
return (T) this._env.getFactory().newTypeMirror(typeBinding.unannotated());
}
}
return t;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public abstract class ASTNode implements TypeConstants, TypeIds {
public static final int IsUsefulEmptyStatement = Bit1;

// for block and method declaration
public static final int SwitchRuleBlock = Bit1;
public static final int BlockShouldEndDead = Bit1;
public static final int UndocumentedEmptyBlock = Bit4;
public static final int OverridingMethodWithSupercall = Bit5;
public static final int CanBeStatic = Bit9; // used to flag a method that can be declared static
Expand Down
Loading

0 comments on commit f0bc53d

Please sign in to comment.