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; 17 18 import com.google.currysrc.api.match.SourceMatcher; 19 import com.google.currysrc.api.match.SourceMatchers; 20 import com.google.currysrc.api.process.Context; 21 import com.google.currysrc.api.process.Processor; 22 import com.google.currysrc.api.process.ast.TypeLocator; 23 24 import org.eclipse.jdt.core.dom.CompilationUnit; 25 import org.eclipse.jdt.core.dom.Javadoc; 26 import org.eclipse.jdt.core.dom.TypeDeclaration; 27 import org.eclipse.jface.text.BadLocationException; 28 import org.eclipse.jface.text.Document; 29 30 /** 31 * Hack to fix upstream code comments before removing @stable tags. Failure to do this would cause 32 * use to remove all the text that followed. 33 */ 34 public class FixupBidiClassDoc implements Processor { 35 36 private final static TypeLocator LOCATOR = new TypeLocator("android.icu.text.Bidi"); 37 38 /** 39 * These tags appear in the middle of some javadoc, making the parser think they are related to 40 * the text that follows it. We just remove it here. 41 */ 42 private static final String BAD_TEXT = 43 " * @author Simon Montagu, Matitiahu Allouche (ported from C code written by Markus W. " 44 + "Scherer)\n * @stable ICU 3.8\n"; 45 46 public SourceMatcher matcher() { 47 return SourceMatchers.contains(LOCATOR); 48 } 49 50 @Override public void process(Context context, CompilationUnit cu) { 51 TypeDeclaration classNode = (TypeDeclaration) LOCATOR.find(cu); 52 Javadoc javadoc = classNode.getJavadoc(); 53 try { 54 Document document = context.document(); 55 String commentText = document.get(javadoc.getStartPosition(), javadoc.getLength()); 56 String newCommentText = commentText.replace(BAD_TEXT, ""); 57 document.replace(javadoc.getStartPosition(), javadoc.getLength(), newCommentText); 58 } catch (BadLocationException e) { 59 throw new AssertionError(e); 60 } 61 } 62 63 @Override 64 public String toString() { 65 return "FixupBidiClassDoc{}"; 66 } 67 } 68