1 19 package org.netbeans.modules.java.source.save; 20 21 import org.netbeans.api.java.lexer.JavaTokenId; 22 import org.netbeans.api.lexer.TokenSequence; 23 24 30 class TokenUtilities { 31 32 41 static int movePrevious(TokenSequence<JavaTokenId> tokenSequence, final int pos) { 42 tokenSequence.move(pos); 44 tokenSequence.movePrevious(); 45 JavaTokenId type = tokenSequence.token().id(); 46 while (JavaTokenId.WHITESPACE.equals(type) || 47 JavaTokenId.BLOCK_COMMENT.equals(type) || 48 JavaTokenId.LINE_COMMENT.equals(type) 49 ) { 50 if (tokenSequence.movePrevious() == false) 51 break; 52 type = tokenSequence.token().id(); 53 } 54 return tokenSequence.offset(); 55 } 56 57 66 static int moveNext(TokenSequence<JavaTokenId> tokenSequence, final int pos) { 67 tokenSequence.move(pos); 68 tokenSequence.moveNext(); JavaTokenId type = tokenSequence.token().id(); 70 while (JavaTokenId.WHITESPACE.equals(type) || 71 JavaTokenId.BLOCK_COMMENT.equals(type) || 72 JavaTokenId.LINE_COMMENT.equals(type) 73 ) { 74 if (tokenSequence.moveNext() == false) 75 break; 76 type = tokenSequence.token().id(); 77 } 78 return tokenSequence.offset(); 79 } 80 81 static int moveFwdToToken(TokenSequence<JavaTokenId> tokenSequence, 82 final int pos, 83 JavaTokenId id) 84 { 85 tokenSequence.move(pos); 86 tokenSequence.moveNext(); while (!id.equals(tokenSequence.token().id())) { 88 if (!tokenSequence.moveNext()) 89 return -1; 90 } 91 return tokenSequence.offset(); 92 } 93 94 static int moveBackToToken(TokenSequence<JavaTokenId> tokenSequence, 95 final int pos, 96 JavaTokenId id) 97 { 98 tokenSequence.move(pos); 99 tokenSequence.moveNext(); while (!id.equals(tokenSequence.token().id())) { 101 if (!tokenSequence.movePrevious()) 102 return -1; 103 } 104 return tokenSequence.offset(); 105 } 106 107 static int moveFwdToToken(TokenSequence<JavaTokenId> tokenSequence, 108 final int pos, 109 String text) 110 { 111 tokenSequence.move(pos); 112 tokenSequence.moveNext(); while (!text.equals(tokenSequence.token().text())) { 114 if (!tokenSequence.moveNext()) 115 return -1; 116 } 117 return tokenSequence.offset(); 118 } 119 120 static int moveBackToToken(TokenSequence<JavaTokenId> tokenSequence, 121 final int pos, 122 String text) 123 { 124 tokenSequence.move(pos); 125 tokenSequence.moveNext(); while (!text.equals(tokenSequence.token().text())) { 127 if (!tokenSequence.movePrevious()) 128 return -1; 129 } 130 return tokenSequence.offset(); 131 } 132 } 133 | Popular Tags |