/** * This implementation of * {@link TargetSourceRangeComputer#computeSourceRange(ASTNode)} * is specialized to work in the case of internal AST rewriting, where the * original AST has been modified from its original form. This means that * one cannot trust that the root of the given node is the compilation unit. */ public SourceRange computeSourceRange(ASTNode node) { int extendedStartPosition = rootNode.getExtendedStartPosition(node); int extendedLength = rootNode.getExtendedLength(node); return new SourceRange(extendedStartPosition, extendedLength); } };
/** * This implementation of * {@link TargetSourceRangeComputer#computeSourceRange(ASTNode)} * is specialized to work in the case of internal AST rewriting, where the * original AST has been modified from its original form. This means that * one cannot trust that the root of the given node is the compilation unit. */ public SourceRange computeSourceRange(ASTNode node) { int extendedStartPosition = rootNode.getExtendedStartPosition(node); int extendedLength = rootNode.getExtendedLength(node); return new SourceRange(extendedStartPosition, extendedLength); } };
/** * This implementation of * {@link TargetSourceRangeComputer#computeSourceRange(ASTNode)} * is specialized to work in the case of internal AST rewriting, where the * original AST has been modified from its original form. This means that * one cannot trust that the root of the given node is the compilation unit. */ public SourceRange computeSourceRange(ASTNode node) { int extendedStartPosition = rootNode.getExtendedStartPosition(node); int extendedLength = rootNode.getExtendedLength(node); return new SourceRange(extendedStartPosition, extendedLength); } };
/** * This implementation of * {@link TargetSourceRangeComputer#computeSourceRange(ASTNode)} * is specialized to work in the case of internal AST rewriting, where the * original AST has been modified from its original form. This means that * one cannot trust that the root of the given node is the compilation unit. */ public SourceRange computeSourceRange(ASTNode node) { int extendedStartPosition = rootNode.getExtendedStartPosition(node); int extendedLength = rootNode.getExtendedLength(node); return new SourceRange(extendedStartPosition, extendedLength); } };
/** * This implementation of * {@link TargetSourceRangeComputer#computeSourceRange(ASTNode)} * is specialized to work in the case of internal AST rewriting, where the * original AST has been modified from its original form. This means that * one cannot trust that the root of the given node is the compilation unit. */ public SourceRange computeSourceRange(ASTNode node) { int extendedStartPosition = rootNode.getExtendedStartPosition(node); int extendedLength = rootNode.getExtendedLength(node); return new SourceRange(extendedStartPosition, extendedLength); } };
/** * This implementation of * {@link TargetSourceRangeComputer#computeSourceRange(ASTNode)} * is specialized to work in the case of internal AST rewriting, where the * original AST has been modified from its original form. This means that * one cannot trust that the root of the given node is the compilation unit. */ @Override public SourceRange computeSourceRange(ASTNode node) { int extendedStartPosition = rootNode.getExtendedStartPosition(node); int extendedLength = rootNode.getExtendedLength(node); return new SourceRange(extendedStartPosition, extendedLength); } };
public static boolean isValidExpression(String string){ String trimmed= string.trim(); if ("".equals(trimmed)) //speed up for a common case //$NON-NLS-1$ return false; StringBuilder cuBuff= new StringBuilder(); cuBuff.append(CONST_CLASS_DECL) .append("Object") //$NON-NLS-1$ .append(CONST_ASSIGN); int offset= cuBuff.length(); cuBuff.append(trimmed) .append(CONST_CLOSE); ASTParser p= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL); p.setSource(cuBuff.toString().toCharArray()); CompilationUnit cu= (CompilationUnit) p.createAST(null); Selection selection= Selection.createFromStartLength(offset, trimmed.length()); SelectionAnalyzer analyzer= new SelectionAnalyzer(selection, false); cu.accept(analyzer); ASTNode selected= analyzer.getFirstSelectedNode(); return (selected instanceof Expression) && trimmed.equals(cuBuff.substring(cu.getExtendedStartPosition(selected), cu.getExtendedStartPosition(selected) + cu.getExtendedLength(selected))); }
public static boolean isValidExpression(String string){ String trimmed= string.trim(); if ("".equals(trimmed)) //speed up for a common case //$NON-NLS-1$ return false; StringBuffer cuBuff= new StringBuffer(); cuBuff.append(CONST_CLASS_DECL) .append("Object") //$NON-NLS-1$ .append(CONST_ASSIGN); int offset= cuBuff.length(); cuBuff.append(trimmed) .append(CONST_CLOSE); ASTParser p= ASTParser.newParser(AST.JLS3); p.setSource(cuBuff.toString().toCharArray()); CompilationUnit cu= (CompilationUnit) p.createAST(null); Selection selection= Selection.createFromStartLength(offset, trimmed.length()); SelectionAnalyzer analyzer= new SelectionAnalyzer(selection, false); cu.accept(analyzer); ASTNode selected= analyzer.getFirstSelectedNode(); return (selected instanceof Expression) && trimmed.equals(cuBuff.substring(cu.getExtendedStartPosition(selected), cu.getExtendedStartPosition(selected) + cu.getExtendedLength(selected))); }
public static boolean isValidExpression(String string){ String trimmed= string.trim(); if ("".equals(trimmed)) //speed up for a common case //$NON-NLS-1$ return false; StringBuffer cuBuff= new StringBuffer(); cuBuff.append(CONST_CLASS_DECL) .append("Object") //$NON-NLS-1$ .append(CONST_ASSIGN); int offset= cuBuff.length(); cuBuff.append(trimmed) .append(CONST_CLOSE); ASTParser p= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL); p.setSource(cuBuff.toString().toCharArray()); CompilationUnit cu= (CompilationUnit) p.createAST(null); Selection selection= Selection.createFromStartLength(offset, trimmed.length()); SelectionAnalyzer analyzer= new SelectionAnalyzer(selection, false); cu.accept(analyzer); ASTNode selected= analyzer.getFirstSelectedNode(); return (selected instanceof Expression) && trimmed.equals(cuBuff.substring(cu.getExtendedStartPosition(selected), cu.getExtendedStartPosition(selected) + cu.getExtendedLength(selected))); }
private IRegion createRange(List statements, int end) { ASTNode first= (ASTNode)statements.get(0); ASTNode root= first.getRoot(); if (root instanceof CompilationUnit) { CompilationUnit unit= (CompilationUnit)root; int start= unit.getExtendedStartPosition(first); ASTNode last= (ASTNode)statements.get(end); int length = unit.getExtendedStartPosition(last) - start + unit.getExtendedLength(last); IRegion range= new Region(start, length); return range; } else { int start= first.getStartPosition(); ASTNode last= (ASTNode)statements.get(end); int length = last.getStartPosition() - start + last.getLength(); IRegion range= new Region(start, length); return range; } }
private IRegion evaluateReplaceRange(CompilationUnit root) { List imports= root.imports(); if (!imports.isEmpty()) { ImportDeclaration first= (ImportDeclaration) imports.get(0); ImportDeclaration last= (ImportDeclaration) imports.get(imports.size() - 1); int startPos= first.getStartPosition(); // no extended range for first: bug 121428 int endPos= root.getExtendedStartPosition(last) + root.getExtendedLength(last); int endLine= root.getLineNumber(endPos); if (endLine > 0) { int nextLinePos= root.getPosition(endLine + 1, 0); if (nextLinePos >= 0) { int firstTypePos= getFirstTypeBeginPos(root); if (firstTypePos != -1 && firstTypePos < nextLinePos) { endPos= firstTypePos; } else { endPos= nextLinePos; } } } return new Region(startPos, endPos - startPos); } else { int start= getPackageStatementEndPos(root); return new Region(start, 0); } }
private IRegion evaluateReplaceRange(CompilationUnit root) { List imports= root.imports(); if (!imports.isEmpty()) { ImportDeclaration first= (ImportDeclaration) imports.get(0); ImportDeclaration last= (ImportDeclaration) imports.get(imports.size() - 1); int startPos= first.getStartPosition(); // no extended range for first: bug 121428 int endPos= root.getExtendedStartPosition(last) + root.getExtendedLength(last); int endLine= root.getLineNumber(endPos); if (endLine > 0) { int nextLinePos= root.getPosition(endLine + 1, 0); if (nextLinePos >= 0) { int firstTypePos= getFirstTypeBeginPos(root); if (firstTypePos != -1 && firstTypePos < nextLinePos) { endPos= firstTypePos; } else { endPos= nextLinePos; } } } return new Region(startPos, endPos - startPos); } else { int start= getPackageStatementEndPos(root); return new Region(start, 0); } }
private IRegion evaluateReplaceRange(CompilationUnit root) { List imports= root.imports(); if (!imports.isEmpty()) { ImportDeclaration first= (ImportDeclaration) imports.get(0); ImportDeclaration last= (ImportDeclaration) imports.get(imports.size() - 1); int startPos= first.getStartPosition(); // no extended range for first: bug 121428 int endPos= root.getExtendedStartPosition(last) + root.getExtendedLength(last); int endLine= root.getLineNumber(endPos); if (endLine > 0) { int nextLinePos= root.getPosition(endLine + 1, 0); if (nextLinePos >= 0) { int firstTypePos= getFirstTypeBeginPos(root); if (firstTypePos != -1 && firstTypePos < nextLinePos) { endPos= firstTypePos; } else { endPos= nextLinePos; } } } return new Region(startPos, endPos - startPos); } else { int start= getPackageStatementEndPos(root); return new Region(start, 0); } }
int nodeEndPosition = compilationUnit.getExtendedStartPosition(node) + compilationUnit.getExtendedLength(node);
private IRegion createRange(ASTNode first, ASTNode last) { ASTNode root= first.getRoot(); if (root instanceof CompilationUnit) { CompilationUnit unit= (CompilationUnit)root; int start= unit.getExtendedStartPosition(first); int length = unit.getExtendedStartPosition(last) - start + unit.getExtendedLength(last); IRegion range= new Region(start, length); return range; } else { int start= first.getStartPosition(); int length = last.getStartPosition() - start + last.getLength(); IRegion range= new Region(start, length); return range; } }
private IRegion createRange(ASTNode first, ASTNode last) { ASTNode root= first.getRoot(); if (root instanceof CompilationUnit) { CompilationUnit unit= (CompilationUnit)root; int start= unit.getExtendedStartPosition(first); int length = unit.getExtendedStartPosition(last) - start + unit.getExtendedLength(last); IRegion range= new Region(start, length); return range; } else { int start= first.getStartPosition(); int length = last.getStartPosition() - start + last.getLength(); IRegion range= new Region(start, length); return range; } }
if (includeHangingCommentsOnly) rangeStartPos = compilationUnit.getExtendedStartPosition(previousNode) + compilationUnit.getExtendedLength(previousNode);
IBuffer buffer= typeRoot.getBuffer(); int offset= extendedRange ? astRoot.getExtendedStartPosition(node) : node.getStartPosition(); int length= extendedRange ? astRoot.getExtendedLength(node) : node.getLength(); String str= buffer.getText(offset, length); if (removeIndent) {
IBuffer buffer= typeRoot.getBuffer(); int offset= extendedRange ? astRoot.getExtendedStartPosition(node) : node.getStartPosition(); int length= extendedRange ? astRoot.getExtendedLength(node) : node.getLength(); String str= buffer.getText(offset, length); if (removeIndent) {
protected ISourceLocation getSourceLocation(ASTNode node) { try { int nodeLength = compilUnit.getExtendedLength(node); if (nodeLength > 0) { int start = compilUnit.getExtendedStartPosition(node); int end = start + nodeLength -1; if (end < start && ((node.getFlags() & 9) > 0)) { insert(messages, values.constructor(DATATYPE_RASCAL_MESSAGE_ERROR_NODE_TYPE, values.string("Recovered/Malformed node, guessing the length"), values.sourceLocation(loc, 0, 0))); nodeLength = node.toString().length(); end = start + nodeLength - 1; } return values.sourceLocation(loc, start, nodeLength, compilUnit.getLineNumber(start), compilUnit.getLineNumber(end), // TODO: only adding 1 at the end seems to work, need to test. compilUnit.getColumnNumber(start), compilUnit.getColumnNumber(end)+1); } } catch (IllegalArgumentException e) { insert(messages, values.constructor(DATATYPE_RASCAL_MESSAGE_ERROR_NODE_TYPE, values.string("Most probably missing dependency"), values.sourceLocation(loc, 0, 0))); } return values.sourceLocation(loc, 0, 0, 0, 0, 0, 0); }