Home | History | Annotate | Download | only in processors
      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.google.currysrc.processors;
     17 
     18 import com.google.common.collect.ImmutableSet;
     19 import com.google.currysrc.api.process.Reporter;
     20 
     21 import org.eclipse.jdt.core.dom.Javadoc;
     22 import org.eclipse.jdt.core.dom.TagElement;
     23 import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
     24 
     25 import java.util.List;
     26 import java.util.Set;
     27 
     28 /**
     29  * Remove the specified JavaDoc tags from the AST. Assumes the Javadoc is well-formed.
     30  */
     31 public final class RemoveJavaDocTags extends BaseJavadocNodeScanner {
     32 
     33   private final Set<String> tagsToRemove;
     34 
     35   public RemoveJavaDocTags(String... tags) {
     36     ImmutableSet.Builder<String> builder = ImmutableSet.builder();
     37     for (String tag : tags) {
     38       builder.add(tag.toLowerCase());
     39     }
     40     tagsToRemove = builder.build();
     41   }
     42 
     43   @Override
     44   protected void visit(Reporter reporter, Javadoc javadoc, ASTRewrite rewrite) {
     45     for (TagElement tagElement : (List<TagElement>) javadoc.tags()) {
     46       String tagName = tagElement.getTagName();
     47       if (tagName == null) {
     48         continue;
     49       }
     50       if (tagsToRemove.contains(tagName.toLowerCase())) {
     51         rewrite.remove(tagElement, null /* editGroup */);
     52       }
     53     }
     54   }
     55 
     56   @Override public String toString() {
     57     return "RemoveJavaDocTags{" +
     58         "tagsToRemove=" + tagsToRemove +
     59         '}';
     60   }
     61 }
     62