Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dubbo Annotation Processor (Add deprecated method warn when called by user, #10850) #11513

Merged
merged 84 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
43a4eb3
Initial Commit of annotation processor.
win120a Jan 24, 2023
972c5a3
Hard coded path -> Automatic obtained path.
win120a Jan 24, 2023
d70d4bd
Imports tools.jar only in JDK 8.
win120a Jan 24, 2023
e076d9a
Imports tools.jar only in JDK 8 (2).
win120a Jan 24, 2023
3957ebd
Add parent configuration.
win120a Jan 24, 2023
f1d06b2
Skip checkstyle.
win120a Jan 24, 2023
5aaeba5
Correct <jdk> section in pom.xml.
win120a Jan 24, 2023
03a2f68
Change profile name.
win120a Jan 24, 2023
989bc96
Indention changes.
win120a Jan 24, 2023
fee3ff2
Add initial logic.
win120a Jan 24, 2023
360d5fe
Optimize processor code.
win120a Jan 25, 2023
f1dd9f4
Add processor in compiler plugin.
win120a Jan 25, 2023
c6b9714
Recover the original pom.xml in build-tools.
win120a Jan 25, 2023
be3efd6
Move annotation processor to root.
win120a Jan 25, 2023
29a463b
Change Sequence of modules.
win120a Jan 25, 2023
adc86f9
Use -proc:none instead of ignoring.
win120a Jan 25, 2023
21042f0
Add >9 profile.
win120a Jan 26, 2023
d04a9fc
Restore 17 to 8.
win120a Jan 26, 2023
5c1abcd
Fix --add-exports error.
win120a Jan 26, 2023
9510b07
Add version in plugin.
win120a Jan 26, 2023
9f55c94
Add -J.
win120a Jan 26, 2023
44e693b
Remove arguments.
win120a Jan 26, 2023
888c650
Trying to fix building problems.
win120a Jan 26, 2023
bff5617
Remove annotationProcessorPaths in config-api module.
win120a Jan 26, 2023
daef604
Change parameter.
win120a Jan 28, 2023
cd156e2
Trying to add import statement.
win120a Jan 29, 2023
12b9f43
Add invocation of warn.
win120a Jan 29, 2023
9180423
Introduce AnnotationProcessorContext.
win120a Jan 29, 2023
c5fb4a2
Refactor with DispatchingAnnotationProcessor + Handlers.
win120a Jan 29, 2023
09b6e73
ASF Header + ASTUtils
win120a Jan 29, 2023
4c975f0
Use handlers.cfg to manage handlers.
win120a Jan 29, 2023
6d7ec00
Javadoc.
win120a Jan 29, 2023
ea8cc86
Use <proc> instead of compiler args.
win120a Jan 30, 2023
3581412
ASF Header.
win120a Jan 31, 2023
c699fc9
Add detection of ECJ and support version declaration.
win120a Jan 31, 2023
06dde8c
Add real-invocation test.
win120a Jan 31, 2023
ee5852e
Let annotation processor work.
win120a Jan 31, 2023
ed6629d
Trying to add InitOnlyProcessor to make it work in Maven.
win120a Feb 1, 2023
fb486e7
Add tests of InitOnlyProcessor.
win120a Feb 1, 2023
2ff76cd
ASF Header.
win120a Feb 1, 2023
71a6cca
Revert "ASF Header."
win120a Feb 1, 2023
957041f
Revert "Add tests of InitOnlyProcessor."
win120a Feb 1, 2023
3883abd
Revert "Trying to add InitOnlyProcessor to make it work in Maven."
win120a Feb 1, 2023
a84cad0
Revert "Revert "ASF Header.""
win120a Feb 1, 2023
9eb9ae4
Force javac compiler use for debugging.
win120a Feb 5, 2023
d09cd42
Debugging purpose.
win120a Feb 5, 2023
b8fc091
Revert debugging settings.
win120a Feb 5, 2023
1cfe1d0
Export Javac's API to processor's module.
win120a Feb 6, 2023
d229c16
Use -proc:none when compiling metadata processor.
win120a Feb 6, 2023
d411f0c
Load handlers after Javac's modules are exported.
win120a Feb 6, 2023
0898534
Add annotation processor as a global dependency.
win120a Feb 6, 2023
da180b5
Fix bug of interface method declaration.
win120a Feb 6, 2023
93db66d
Fix bug of super() statement sequence in constructor.
win120a Feb 6, 2023
82753e0
Fix bug of this() statement sequence in constructor.
win120a Feb 6, 2023
c172db5
Fix bug of this() statement sequence in constructor. (2)
win120a Feb 6, 2023
4feff2a
ASF header and Add DeprecatedHandlerConstants.java.
win120a Feb 7, 2023
d505c6d
Refactor.
win120a Feb 7, 2023
ef3e2c4
Let another annotation processor run.
win120a Feb 8, 2023
2612ddc
Use a hack to bypass the package symbol scanning.
win120a Feb 8, 2023
e39c5be
Use a hack to bypass the package symbol scanning (2).
win120a Feb 8, 2023
c70d1f2
Use a hack to bypass the package symbol scanning (3).
win120a Feb 8, 2023
a2e5cbf
Use a hack to bypass the package symbol scanning (4).
win120a Feb 8, 2023
565c41b
Use a hack to bypass the package symbol scanning (5).
win120a Feb 8, 2023
3295765
Javadoc.
win120a Feb 9, 2023
8cf4c35
Add 0-99 in LoggerCodeConstants.
win120a Feb 9, 2023
efb8253
Javadoc.
win120a Feb 9, 2023
69dcf83
Add DeprecatedMethodInvocationCounter.
win120a Feb 10, 2023
204378c
Formally add DeprecatedMethodInvocationCounter.
win120a Feb 10, 2023
e7fb015
ASF Header.
win120a Feb 10, 2023
3126b39
Add DeprecatedMethodInvocationCounterTest.
win120a Feb 10, 2023
3ead6f0
Add DeprecatedMethodInvocationCounterTest (2).
win120a Feb 10, 2023
1952ae2
Add DeprecatedMethodInvocationCounterTest (3).
win120a Feb 10, 2023
df64d97
Use methods in DeprecatedMethodInvocationCounter instead of writing d…
win120a Feb 14, 2023
829dd7f
Javadoc and modifiers.
win120a Feb 14, 2023
97546aa
Correct the error code in tests.
win120a Feb 19, 2023
988ed76
Make the mock of DeprecatedMethodInvocationCounter smaller.
win120a Feb 20, 2023
00019fa
Use computeIfAbsent instead of putIfAbsent to reduce performance pena…
win120a Feb 20, 2023
3d7fb15
Delete unused DeprecatedHandlerConstants.java.
win120a Feb 20, 2023
7591941
Delete unused logger mocks.
win120a Feb 20, 2023
4cbd643
Add ignore in FileTest.
win120a Mar 6, 2023
d470633
Ignore (2)
win120a Mar 6, 2023
5a8653c
Remove printStackTrace.
win120a Mar 6, 2023
ae672a5
Add dubbo-maven-plugin back.
win120a Mar 21, 2023
582c6e9
Restore license headers.
win120a Mar 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright 2018-2023 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).

This product contains code form the Netty Project:
This product contains code from the Netty Project:

The Netty Project
=================
Expand Down
165 changes: 165 additions & 0 deletions dubbo-annotation-processor/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-annotation-processor</artifactId>
<version>1.0.0</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- System dependencies may cause problems in checkstyle. -->
<checkstyle.skip>true</checkstyle.skip>
<checkstyle_unix.skip>true</checkstyle_unix.skip>
<rat.skip>true</rat.skip>
<jacoco.skip>true</jacoco.skip>

<maven.deploy.skip>true</maven.deploy.skip>

<junit_jupiter_version>5.9.0</junit_jupiter_version>
<javassist_version>3.29.2-GA</javassist_version>
</properties>

<packaging>jar</packaging>

<dependencies>
<!-- JUnit Jupiter Engine to depend on the JUnit5 engine and JUnit 5 API -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit_jupiter_version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>${javassist_version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<proc>none</proc>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>default-profile-in-jdk-8</id>
<activation>
<file>
<exists>${java.home}/../lib/tools.jar</exists>
</file>
<jdk>(, 9)</jdk>
</activation>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>

<dependencies>
<dependency>
<groupId>javac</groupId>
<artifactId>javac</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${toolsjar}</systemPath>
</dependency>
</dependencies>
</profile>

<profile>
<id>legacy-apple-jdk-profile</id>
<activation>
<activeByDefault>false</activeByDefault>
<file>
<exists>${java.home}/../Classes/classes.jar</exists>
</file>
<jdk>(, 9)</jdk>
</activation>

<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
</properties>

<dependencies>
<dependency>
<groupId>javac</groupId>
<artifactId>javac</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${toolsjar}</systemPath>
</dependency>
</dependencies>
</profile>

<profile>
<id>add-export-greater-than-9</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>[9, )</jdk>
</activation>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<fork>true</fork>
<proc>none</proc>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.dubbo.annotation;

import javax.lang.model.element.Element;
import java.lang.annotation.Annotation;
import java.util.Set;

/**
* Represents an annotation processing handler, which is invoked by DispatchingAnnotationProcessor.
*/
public interface AnnotationProcessingHandler {

/**
* Set the annotations that this handler will handle.
*
* @return annotations to handle
*/
Set<Class<? extends Annotation>> getAnnotationsToHandle();

/**
* Formal processing method.
*
* @param elements the elements that annotated by the annotations of getAnnotationsToHandle()
* @param annotationProcessorContext the annotation processor context object (Javac object encapsulation)
*/
void process(Set<Element> elements,
AnnotationProcessorContext annotationProcessorContext);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.dubbo.annotation;

import com.sun.source.util.Trees;
import com.sun.tools.javac.api.JavacTrees;
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Names;

import javax.annotation.processing.ProcessingEnvironment;
import java.lang.reflect.Method;
import java.util.Objects;

/**
* The Context Object of Annotation Processor, which stores objects related to javac.
*/
public class AnnotationProcessorContext {
private JavacProcessingEnvironment javacProcessingEnvironment;
private JavacTrees javacTrees;
private TreeMaker treeMaker;
private Names names;
private Context javacContext;
private Trees trees;

private AnnotationProcessorContext() { }

private static <T> T jbUnwrap(Class<? extends T> iface, T wrapper) {
T unwrapped = null;
try {
final Class<?> apiWrappers = wrapper.getClass().getClassLoader().loadClass("org.jetbrains.jps.javac.APIWrappers");
final Method unwrapMethod = apiWrappers.getDeclaredMethod("unwrap", Class.class, Object.class);
unwrapped = iface.cast(unwrapMethod.invoke(null, iface, wrapper));
} catch (Throwable ignored) {
}

return unwrapped != null ? unwrapped : wrapper;
}

public static AnnotationProcessorContext fromProcessingEnvironment(ProcessingEnvironment processingEnv) {
AnnotationProcessorContext apContext = new AnnotationProcessorContext();

Object procEnvToUnwrap = processingEnv.getClass() == JavacProcessingEnvironment.class ?
processingEnv : jbUnwrap(JavacProcessingEnvironment.class, processingEnv);

JavacProcessingEnvironment jcProcessingEnvironment = (JavacProcessingEnvironment) procEnvToUnwrap;

Context context = jcProcessingEnvironment.getContext();

apContext.javacProcessingEnvironment = jcProcessingEnvironment;

apContext.javacContext = context;
apContext.javacTrees = JavacTrees.instance(jcProcessingEnvironment);
apContext.treeMaker = TreeMaker.instance(context);
apContext.names = Names.instance(context);

apContext.trees = Trees.instance(jcProcessingEnvironment);

return apContext;
}

// Auto-generated methods.

public JavacTrees getJavacTrees() {
return javacTrees;
}

public TreeMaker getTreeMaker() {
return treeMaker;
}

public Names getNames() {
return names;
}

public Context getJavacContext() {
return javacContext;
}

public Trees getTrees() {
return trees;
}

public JavacProcessingEnvironment getJavacProcessingEnvironment() {
return javacProcessingEnvironment;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

AnnotationProcessorContext context = (AnnotationProcessorContext) o;

if (!Objects.equals(javacTrees, context.javacTrees)) return false;
if (!Objects.equals(treeMaker, context.treeMaker)) return false;
if (!Objects.equals(names, context.names)) return false;
if (!Objects.equals(javacContext, context.javacContext))
return false;
return Objects.equals(trees, context.trees);
}

@Override
public int hashCode() {
int result = javacTrees != null ? javacTrees.hashCode() : 0;
result = 31 * result + (treeMaker != null ? treeMaker.hashCode() : 0);
result = 31 * result + (names != null ? names.hashCode() : 0);
result = 31 * result + (javacContext != null ? javacContext.hashCode() : 0);
result = 31 * result + (trees != null ? trees.hashCode() : 0);
return result;
}

@Override
public String toString() {
return "AnnotationProcessorContext{" +
"javacTrees=" + javacTrees +
", treeMaker=" + treeMaker +
", names=" + names +
", javacContext=" + javacContext +
", trees=" + trees +
'}';
}
}
Loading