1 19 20 package org.netbeans.lib.lexer.inc; 21 22 import org.netbeans.api.lexer.TokenChange; 23 import org.netbeans.api.lexer.TokenHierarchyEventType; 24 import org.netbeans.api.lexer.TokenId; 25 import org.netbeans.lib.lexer.LexerApiPackageAccessor; 26 import org.netbeans.lib.lexer.LexerSpiPackageAccessor; 27 import org.netbeans.lib.lexer.TokenHierarchyOperation; 28 29 36 37 public final class TokenHierarchyEventInfo { 38 39 private final TokenHierarchyOperation<?,?> tokenHierarchyOperation; 40 41 private final TokenHierarchyEventType type; 42 43 private TokenChange<? extends TokenId> tokenChange; 44 45 private final int modificationOffset; 46 47 private final int removedLength; 48 49 private final CharSequence removedText; 50 51 private final int insertedLength; 52 53 private OriginalText originalText; 54 55 private int affectedStartOffset; 56 57 private int affectedEndOffset; 58 59 public TokenHierarchyEventInfo(TokenHierarchyOperation<?,? extends TokenId> tokenHierarchyOperation, 60 TokenHierarchyEventType type, int modificationOffset, int removedLength, CharSequence removedText, int insertedLength) { 61 if (modificationOffset < 0) { 63 throw new IllegalArgumentException ("modificationOffset=" + modificationOffset + " < 0"); } 65 if (removedLength < 0) { 66 throw new IllegalArgumentException ("removedLength=" + removedLength + " < 0"); } 68 if (insertedLength < 0) { 69 throw new IllegalArgumentException ("insertedLength=" + insertedLength + " < 0"); } 71 72 this.tokenHierarchyOperation = tokenHierarchyOperation; 73 this.type = type; 74 this.modificationOffset = modificationOffset; 75 this.removedLength = removedLength; 76 this.removedText = removedText; 77 this.insertedLength = insertedLength; 78 } 79 80 public TokenHierarchyOperation<?,? extends TokenId> tokenHierarchyOperation() { 81 return tokenHierarchyOperation; 82 } 83 84 public TokenHierarchyEventType type() { 85 return type; 86 } 87 88 public TokenChange<? extends TokenId> tokenChange() { 89 return tokenChange; 90 } 91 92 public void setTokenChangeInfo(TokenChangeInfo<? extends TokenId> info) { 93 this.tokenChange = LexerApiPackageAccessor.get().createTokenChange(info); 94 } 95 96 public int affectedStartOffset() { 97 return affectedStartOffset; 98 } 99 100 public void setAffectedStartOffset(int affectedStartOffset) { 101 this.affectedStartOffset = affectedStartOffset; 102 } 103 104 public int affectedEndOffset() { 105 return affectedEndOffset; 106 } 107 108 public void setAffectedEndOffset(int affectedEndOffset) { 109 this.affectedEndOffset = affectedEndOffset; 110 } 111 112 public int modificationOffset() { 113 return modificationOffset; 114 } 115 116 public int removedLength() { 117 return removedLength; 118 } 119 120 public CharSequence removedText() { 121 return removedText; 122 } 123 124 public int insertedLength() { 125 return insertedLength; 126 } 127 128 public OriginalText originalText() { 129 if (originalText == null) { 130 if (removedLength != 0 && removedText == null) { 131 throw new IllegalStateException ("Cannot obtain removed text for " + tokenHierarchyOperation.mutableInputSource() 133 + " which breaks token snapshots operation and" + " token text retaining after token's removal." + " Valid removedText in TokenHierarchyControl.textModified()" + " should be provided." ); 138 } 139 originalText = new OriginalText( 140 LexerSpiPackageAccessor.get().text(tokenHierarchyOperation.mutableTextInput()), 141 modificationOffset, removedText, insertedLength 142 ); 143 } 144 return originalText; 145 } 146 147 } 148 | Popular Tags |