Home | History | Annotate | Download | only in checker
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.icu4j.srcgen.checker;
     17 
     18 import com.google.currysrc.api.process.JavadocUtils;
     19 import com.google.currysrc.api.process.Reporter;
     20 import com.google.currysrc.api.process.ast.BodyDeclarationLocators;
     21 import com.google.currysrc.processors.BaseModifyCommentScanner;
     22 
     23 import com.android.icu4j.srcgen.TranslateJcite;
     24 
     25 import org.eclipse.jdt.core.dom.BodyDeclaration;
     26 import org.eclipse.jdt.core.dom.Comment;
     27 import org.eclipse.jdt.core.dom.Javadoc;
     28 
     29 import java.util.List;
     30 import java.util.Set;
     31 
     32 /**
     33  * Checks for escaped (rather than transformed) jcite tags and warns for any found in the
     34  * public APIs.
     35  */
     36 class CheckForBrokenJciteTag extends BaseModifyCommentScanner {
     37 
     38   private final Set<String> publicMembers;
     39 
     40   public CheckForBrokenJciteTag(Set<String> publicMembers) {
     41     this.publicMembers = publicMembers;
     42   }
     43 
     44   @Override
     45   protected String processComment(Reporter reporter, Comment commentNode, String commentText) {
     46     if (commentNode instanceof Javadoc
     47         && commentText.contains(TranslateJcite.ESCAPED_JCITE_TAG)) {
     48       BodyDeclaration declaration = BodyDeclarationLocators.findDeclarationNode(commentNode);
     49       if (JavadocUtils.isNormallyDocumented(declaration)) {
     50         List<String> locatorStrings = BodyDeclarationLocators.toLocatorStringForms(declaration);
     51         for (String locatorString : locatorStrings) {
     52           if (publicMembers.contains(locatorString)) {
     53             reporter.info(
     54                 commentNode, "Escaped JCITE tag found in public API docs:" + commentText);
     55           } else {
     56             reporter.info(
     57                 commentNode, "Escaped JCITE tag found in non-public API docs (this is fine)");
     58           }
     59         }
     60       }
     61     }
     62     return null;
     63   }
     64 
     65   @Override
     66   public String toString() {
     67     return "CheckForBrokenJciteTag{" +
     68         "publicMembers=" + publicMembers +
     69         '}';
     70   }
     71 }
     72