use of org.eclipse.jdt.core.compiler.IScanner in project flux by eclipse.
the class CodeTemplateContextType method isValidComment.
private boolean isValidComment(String template) {
IScanner scanner = ToolFactory.createScanner(true, false, false, false);
scanner.setSource(template.toCharArray());
try {
int next = scanner.getNextToken();
while (TokenScanner.isComment(next)) {
next = scanner.getNextToken();
}
return next == ITerminalSymbols.TokenNameEOF;
} catch (InvalidInputException e) {
}
return false;
}
use of org.eclipse.jdt.core.compiler.IScanner in project bndtools by bndtools.
the class NewTypeWizardPage method isValidComment.
private boolean isValidComment(String template) {
IScanner scanner = ToolFactory.createScanner(true, false, false, false);
scanner.setSource(template.toCharArray());
try {
int next = scanner.getNextToken();
while (TokenScanner.isComment(next)) {
next = scanner.getNextToken();
}
return next == ITerminalSymbols.TokenNameEOF;
} catch (InvalidInputException e) {
}
return false;
}
use of org.eclipse.jdt.core.compiler.IScanner in project che by eclipse.
the class StatementAnalyzer method checkSelectedNodes.
protected void checkSelectedNodes() {
ASTNode[] nodes = getSelectedNodes();
if (nodes.length == 0)
return;
ASTNode node = nodes[0];
int selectionOffset = getSelection().getOffset();
try {
int start = fScanner.getNextStartOffset(selectionOffset, true);
if (start == node.getStartPosition()) {
int lastNodeEnd = ASTNodes.getExclusiveEnd(nodes[nodes.length - 1]);
int pos = fScanner.getNextStartOffset(lastNodeEnd, true);
int selectionEnd = getSelection().getInclusiveEnd();
if (pos <= selectionEnd) {
IScanner scanner = fScanner.getScanner();
//see https://bugs.eclipse.org/324237
char[] token = scanner.getCurrentTokenSource();
if (start < lastNodeEnd && token.length == 1 && (token[0] == ';' || token[0] == ',')) {
setSelection(Selection.createFromStartEnd(start, lastNodeEnd - 1));
} else {
ISourceRange range = new SourceRange(lastNodeEnd, pos - lastNodeEnd);
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_end_of_selection, JavaStatusContext.create(fCUnit, range));
}
}
// success
return;
}
} catch (CoreException e) {
// fall through
}
ISourceRange range = new SourceRange(selectionOffset, node.getStartPosition() - selectionOffset + 1);
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_beginning_of_selection, JavaStatusContext.create(fCUnit, range));
}
use of org.eclipse.jdt.core.compiler.IScanner in project che by eclipse.
the class CommentAnalyzer method normalizeReference.
/**
* Removes comments and whitespace
* @param reference the type reference
* @return the reference only consisting of dots and java identifier characters
*/
public static String normalizeReference(String reference) {
IScanner scanner = ToolFactory.createScanner(false, false, false, false);
scanner.setSource(reference.toCharArray());
StringBuffer sb = new StringBuffer();
try {
int tokenType = scanner.getNextToken();
while (tokenType != ITerminalSymbols.TokenNameEOF) {
sb.append(scanner.getRawTokenSource());
tokenType = scanner.getNextToken();
}
} catch (InvalidInputException e) {
Assert.isTrue(false, reference);
}
reference = sb.toString();
return reference;
}
use of org.eclipse.jdt.core.compiler.IScanner in project che by eclipse.
the class Util method isJustWhitespaceOrComment.
private static boolean isJustWhitespaceOrComment(int start, int end, IBuffer buffer) {
if (start == end)
return true;
Assert.isTrue(start <= end);
String trimmedText = buffer.getText(start, end - start).trim();
if (0 == trimmedText.length()) {
return true;
} else {
IScanner scanner = ToolFactory.createScanner(false, false, false, null);
scanner.setSource(trimmedText.toCharArray());
try {
return scanner.getNextToken() == ITerminalSymbols.TokenNameEOF;
} catch (InvalidInputException e) {
return false;
}
}
}
Aggregations