Here you can find the source of isFirstAnnotationOfMethod(List
static boolean isFirstAnnotationOfMethod(List<String> lines, int lineNumber)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { static boolean isFirstAnnotationOfMethod(List<String> lines, int lineNumber) { String line = lines.get(lineNumber); if (isAnnotation(line) && (lineNumber == 0 || !isAnnotation(lines, lineNumber - 1))) { int i = lineNumber + 1; while (i < lines.size() && isAnnotation(lines.get(i))) { i++;// w ww .j a v a 2s .c o m } return isMethodDeclaration(lines, i); } return false; } static boolean isAnnotation(List<String> lines, int lineNumber) { return isAnnotation(lines.get(lineNumber)); } static boolean isAnnotation(String line) { return line.matches("^\\s*@.*"); } static boolean isMethodDeclaration(String line) { line = killComments(line); boolean isAbstract = (" " + line).contains(" abstract "); line = killOccurrences(line, "(public|private|protected|static|final|native|synchronized|abstract|transient|default)"); line = killOccurrences(line, "\\[\\s*\\]"); line = killOccurrences(line, "<[^<>]*>"); line = killOccurrences(line, "\\.\\.\\."); line = killStrings(line); if (matches(line, ".*\\.[a-z].*\\(.*")) return false; // a method call if (isAbstract) { return matches(line.trim(), "[a-zA-Z][^\\s\\.]*\\s+\\S+\\([^\\(\\)]*\\)\\s*(throws\\s+[^\\{\\;]*)?\\;$"); } else { return matches(line.trim(), "[a-zA-Z][^\\s\\.]*\\s+\\S+\\([^\\(\\)]*\\)\\s*(throws\\s+[^\\{\\;]*)?(\\{.*)?"); } } static boolean isMethodDeclaration(List<String> lines, int lineNumber) { return isMethodDeclaration(lines.get(lineNumber)); } private static boolean matches(String line, String regex) { String optionalStart = "^\\s*(/\\*.*\\*/)?\\s*"; String optionalEnd = "\\s*(//.*|/\\*.*)?\\s*$"; return line.matches(optionalStart + regex + optionalEnd); } private static boolean matches(List<String> lines, int lineNumber, String regex) { return matches(lines.get(lineNumber), regex); } private static String killComments(String lineToSearchIn) { String regexSingleLineComment = "//.*"; lineToSearchIn = lineToSearchIn.replaceAll(regexSingleLineComment, ""); String regexMultiComment = "/\\*[^\\*/]*\\*/"; String tmp = killOccurrences(lineToSearchIn, regexMultiComment); return tmp.replaceAll("/\\*.*", ""); } private static String killOccurrences(String line, String regex) { String tmp = line.replaceFirst(regex, ""); while (!tmp.equals(tmp.replaceFirst(regex, ""))) { tmp = tmp.replaceFirst(regex, ""); } return tmp; } static String killStrings(String line) { return killOccurrences(line.replaceAll("\\\\\"", ""), "\"[^\"]*[^\\\\]\""); } }