List of usage examples for org.eclipse.jdt.core.dom CompilationUnit getColumnNumber
public int getColumnNumber(final int position)
From source file:com.google.gdt.eclipse.core.markers.GdtJavaProblem.java
License:Open Source License
protected GdtJavaProblem(ASTNode node, int offset, int length, T problemType, GdtProblemSeverity severity, String[] messageArguments, String[] problemArguments) { this.id = problemType.getProblemId(); this.filename = getFileNameFromASTNode(node); this.startPosition = offset; this.endPosition = offset + length - 1; CompilationUnit cu = (CompilationUnit) node.getRoot(); this.line = cu.getLineNumber(node.getStartPosition()); this.column = cu.getColumnNumber(node.getStartPosition()); this.problemType = problemType; this.severity = severity; this.message = MessageFormat.format(problemType.getMessage(), (Object[]) messageArguments); this.problemArguments = problemArguments; }
From source file:org.autorefactor.refactoring.ASTHelper.java
License:Open Source License
/** * Returns a string suitable for identifying a location in the source. * * @param node the node from which to retrieve the source location * @return a string suitable for identifying a location in the source *///from ww w.j a va2 s . co m public static String getSourceLocation(ASTNode node) { final ASTNode root = node != null ? node.getRoot() : null; if (root instanceof CompilationUnit) { final CompilationUnit cu = (CompilationUnit) root; final int position = node.getStartPosition(); final int line = cu.getLineNumber(position); final int column = cu.getColumnNumber(position) + 1; if (cu.getTypeRoot() != null) { return cu.getTypeRoot().getElementName() + ":" + line + ":" + column; } // it was not created from a file return line + ":" + column; } return ""; }
From source file:org.ebayopensource.dsf.javatojs.translate.TranslateHelper.java
License:Open Source License
public static int getColumnNumber(final ASTNode node) { if (node != null && node.getRoot() instanceof CompilationUnit) { CompilationUnit cu = (CompilationUnit) node.getRoot(); return cu.getColumnNumber(node.getStartPosition()); }/*from w ww.j a v a 2 s .c o m*/ return -1; }
From source file:org.eclipse.gmf.tests.setup.figures.FigureGeneratorUtil.java
License:Open Source License
public static void generateAndParse(FigureDescriptor fd, FigureGenerator generator) { String res = generator.go(fd); Assert.assertNotNull("Generation should produce code", res); ASTParser p = ASTParser.newParser(AST.JLS3); p.setSource(res.toCharArray());/*w w w .j a v a2s . c o m*/ ASTNode astNode = p.createAST(null); Assert.assertEquals("Generator is expected to produce cu", astNode.getNodeType(), ASTNode.COMPILATION_UNIT); CompilationUnit cu = (CompilationUnit) astNode; if (generator.getPackageName() != null) { Assert.assertNotNull("Generator initialized with packageName should produce package statement", cu.getPackage()); Assert.assertEquals("Package names are different", generator.getPackageName(), cu.getPackage().getName().getFullyQualifiedName()); } else { Assert.assertNull(cu.getPackage()); } IProblem[] problems = cu.getProblems(); for (int i = 0; i < problems.length; i++) { Assert.assertFalse(problems[i].getMessage() + ", line:" + problems[i].getSourceLineNumber() + ", pos:" + cu.getColumnNumber(problems[i].getSourceStart()), problems[i].isError()); } }
From source file:org.springframework.ide.vscode.boot.java.links.AtomSourceLinks.java
License:Open Source License
@Override protected String positionLink(CompilationUnit cu, String fqName) { if (cu != null) { Region region = findTypeRegion(cu, fqName); if (region != null) { int column = cu.getColumnNumber(region.getOffset()); int line = cu.getLineNumber(region.getOffset()); StringBuilder sb = new StringBuilder(); sb.append("&line="); sb.append(line);//from w w w. ja v a2s. c o m sb.append("&column="); sb.append(column + 1); // 1-based columns? return sb.toString(); } } return null; }
From source file:org.springframework.ide.vscode.boot.java.links.VSCodeSourceLinks.java
License:Open Source License
@Override protected String positionLink(CompilationUnit cu, String fqName) { if (cu != null) { Region region = findTypeRegion(cu, fqName); if (region != null) { int column = cu.getColumnNumber(region.getOffset()); int line = cu.getLineNumber(region.getOffset()); StringBuilder sb = new StringBuilder(); sb.append('#'); sb.append(line);/*ww w .jav a 2s . c o m*/ sb.append(','); sb.append(column + 1); // 1-based columns? return sb.toString(); } } return null; }