1 package com.puppycrawl.tools.checkstyle.api; 20 21 26 class Comment implements TextBlock 27 { 28 29 private final String [] mText; 30 31 32 private final int mFirstLine; 33 34 35 private final int mLastLine; 36 37 38 private final int mFirstCol; 39 40 41 private final int mLastCol; 42 43 50 public Comment(final String [] aText, final int aFirstCol, 51 final int aLastLine, final int aLastCol) 52 { 53 mText = new String [aText.length]; 54 System.arraycopy(aText, 0, mText, 0, mText.length); 55 mFirstLine = aLastLine - mText.length + 1; 56 mLastLine = aLastLine; 57 mFirstCol = aFirstCol; 58 mLastCol = aLastCol; 59 } 60 61 62 public final String [] getText() 63 { 64 return (String []) mText.clone(); 65 } 66 67 68 public final int getStartLineNo() 69 { 70 return mFirstLine; 71 } 72 73 74 public final int getEndLineNo() 75 { 76 return mLastLine; 77 } 78 79 80 public int getStartColNo() 81 { 82 return mFirstCol; 83 } 84 85 86 public int getEndColNo() 87 { 88 return mLastCol; 89 } 90 91 92 public boolean intersects(int aStartLineNo, int aStartColNo, 93 int aEndLineNo, int aEndColNo) 94 { 95 final long multiplier = Integer.MAX_VALUE; 98 final long thisStart = mFirstLine * multiplier + mFirstCol; 99 final long thisEnd = mLastLine * multiplier + mLastCol; 100 final long inStart = aStartLineNo * multiplier + aStartColNo; 101 final long inEnd = aEndLineNo * multiplier + aEndColNo; 102 103 return !((thisEnd < inStart) || (inEnd < thisStart)); 104 } 105 106 107 public String toString() 108 { 109 return "Comment[" + mFirstLine + ":" + mFirstCol + "-" 110 + mLastLine + ":" + mLastCol + "]"; 111 } 112 } 113 | Popular Tags |