AlbumenJ commented on code in PR #11513: URL: https://github.com/apache/dubbo/pull/11513#discussion_r1105209827
########## dubbo-annotation-processor/src/main/java/org/apache/dubbo/annotation/handler/DeprecatedHandler.java: ########## @@ -0,0 +1,247 @@ +/* + * 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.handler; + +import org.apache.dubbo.annotation.AnnotationProcessingHandler; +import org.apache.dubbo.annotation.AnnotationProcessorContext; +import org.apache.dubbo.annotation.constant.DeprecatedHandlerConstants; +import org.apache.dubbo.annotation.util.ASTUtils; + +import com.sun.tools.javac.code.Flags; +import com.sun.tools.javac.code.Symbol; +import com.sun.tools.javac.code.Types; +import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.tree.TreeMaker; +import com.sun.tools.javac.tree.TreeTranslator; +import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.ListBuffer; + +import javax.lang.model.element.Element; +import java.lang.annotation.Annotation; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * Handles @Deprecated annotation and adds logger warn call to the methods that are annotated with it. + */ +public class DeprecatedHandler implements AnnotationProcessingHandler { + + @Override + public Set<Class<? extends Annotation>> getAnnotationsToHandle() { + return new HashSet<>( + Collections.singletonList(Deprecated.class) + ); + } + + @Override + public void process(Set<Element> elements, AnnotationProcessorContext apContext) { + for (Element element : elements) { + // Only interested in methods. + if (!(element instanceof Symbol.MethodSymbol)) { + continue; + } + + Symbol.ClassSymbol classSymbol = (Symbol.ClassSymbol) element.getEnclosingElement(); + + ASTUtils.addImportStatement(apContext, classSymbol, "org.apache.dubbo.common.logger", "LoggerFactory"); + ASTUtils.addImportStatement(apContext, classSymbol, "org.apache.dubbo.common.logger", "ErrorTypeAwareLogger"); + ASTUtils.addImportStatement(apContext, classSymbol, "org.apache.dubbo.common", "DeprecatedMethodInvocationCounter"); Review Comment: Just insert `DeprecatedMethodCollector.collect(xxx)` here. Log and count in `DeprecatedMethodCollector.collect`. ########## NOTICE: ########## @@ -4,11 +4,35 @@ 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 ================= Please visit the Netty web site for more information: * http://netty.io/ Copyright 2014 The Netty Project + +This product contains code from The Project Lombok, which is licensed under MIT License: + +/* + * Copyright (C) 2018-2021 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ Review Comment: No need to add notice if there is not NOTICE file in https://github.com/projectlombok/lombok. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
