1 package com.puppycrawl.tools.checkstyle.api; 20 21 36 public final class FullIdent 37 { 38 39 private final StringBuffer mBuffer = new StringBuffer (); 40 41 private int mLineNo; 42 43 private int mColNo; 44 45 46 private FullIdent() 47 { 48 } 49 50 51 public String getText() 52 { 53 return mBuffer.toString(); 54 } 55 56 57 public int getLineNo() 58 { 59 return mLineNo; 60 } 61 62 63 public int getColumnNo() 64 { 65 return mColNo; 66 } 67 68 72 private void append(String aText) 73 { 74 mBuffer.append(aText); 75 } 76 77 82 private void append(DetailAST aAST) 83 { 84 mBuffer.append(aAST.getText()); 85 if (mLineNo == 0) { 86 mLineNo = aAST.getLineNo(); 87 } 88 else if (aAST.getLineNo() > 0) { 89 mLineNo = Math.min(mLineNo, aAST.getLineNo()); 90 } 91 if (mColNo == 0) { 93 mColNo = aAST.getColumnNo(); 94 } 95 else if (aAST.getColumnNo() > 0) { 96 mColNo = Math.min(mColNo, aAST.getColumnNo()); 97 } 98 } 99 100 105 public static FullIdent createFullIdent(DetailAST aAST) 106 { 107 final FullIdent fi = new FullIdent(); 108 extractFullIdent(fi, aAST); 109 return fi; 110 } 111 112 117 public static FullIdent createFullIdentBelow(DetailAST aAST) 118 { 119 return createFullIdent((DetailAST) aAST.getFirstChild()); 120 } 121 122 128 private static void extractFullIdent(FullIdent aFull, DetailAST aAST) 129 { 130 if (aAST == null) { 131 return; 132 } 133 134 if (aAST.getType() == TokenTypes.DOT) { 135 extractFullIdent(aFull, (DetailAST) aAST.getFirstChild()); 136 aFull.append("."); 137 extractFullIdent( 138 aFull, (DetailAST) aAST.getFirstChild().getNextSibling()); 139 } 140 else { 141 aFull.append(aAST); 142 } 143 } 144 145 146 public String toString() 147 { 148 return getText() + "[" + getLineNo() + "x" + getColumnNo() + "]"; 149 } 150 151 } 152 | Popular Tags |