Java Code Examples for org.eclipse.jdt.core.compiler.IProblem#getSourceEnd()
The following examples show how to use
org.eclipse.jdt.core.compiler.IProblem#getSourceEnd() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaASTUtils.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Returns <code>true</code> if any of the problems fall within the * {@link ASTNode}'s source range. */ public static boolean hasErrors(ASTNode node, IProblem[] problems) { int startPosition = node.getStartPosition(); int endPosition = startPosition + node.getLength() - 1; for (IProblem problem : problems) { if (!problem.isError()) { // Skip any problem that is not an error continue; } if (problem.getSourceStart() >= startPosition && problem.getSourceEnd() <= endPosition) { return true; } } return false; }
Example 2
Source File: CompilationUnitDocumentProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected Position createPositionFromProblem(IProblem problem) { int start= problem.getSourceStart(); int end= problem.getSourceEnd(); if (start == -1 && end == -1) return new Position(0); if (start == -1) return new Position(end); if (end == -1) return new Position(start); int length= end - start + 1; if (length < 0) return null; return new Position(start, length); }
Example 3
Source File: CompilationUnit.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns the list of messages reported by the compiler during the parsing * or the type checking of this compilation unit. This list might be a subset of * errors detected and reported by a Java compiler. * <p> * This list of messages is suitable for simple clients that do little * more than log the messages or display them to the user. Clients that * need further details should call <code>getProblems</code> to get * compiler problem objects. * </p> * * @return the list of messages, possibly empty * @see #getProblems() * @see ASTParser */ public Message[] getMessages() { if (this.messages == null) { int problemLength = this.problems.length; if (problemLength == 0) { this.messages = EMPTY_MESSAGES; } else { this.messages = new Message[problemLength]; for (int i = 0; i < problemLength; i++) { IProblem problem = this.problems[i]; int start = problem.getSourceStart(); int end = problem.getSourceEnd(); this.messages[i] = new Message(problem.getMessage(), start, end - start + 1); } } } return this.messages; }
Example 4
Source File: LinkedNodeFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static int getNameNodeProblemKind(IProblem[] problems, SimpleName nameNode) { int nameOffset= nameNode.getStartPosition(); int nameInclEnd= nameOffset + nameNode.getLength() - 1; for (int i= 0; i < problems.length; i++) { IProblem curr= problems[i]; if (curr.getSourceStart() == nameOffset && curr.getSourceEnd() == nameInclEnd) { int kind= getProblemKind(curr); if (kind != 0) { return kind; } } } return 0; }
Example 5
Source File: LinkedNodeFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static SimpleName[] findByProblems(ASTNode parent, SimpleName nameNode) { ArrayList<SimpleName> res= new ArrayList<SimpleName>(); ASTNode astRoot = parent.getRoot(); if (!(astRoot instanceof CompilationUnit)) { return null; } IProblem[] problems= ((CompilationUnit) astRoot).getProblems(); int nameNodeKind= getNameNodeProblemKind(problems, nameNode); if (nameNodeKind == 0) { // no problem on node return null; } int bodyStart= parent.getStartPosition(); int bodyEnd= bodyStart + parent.getLength(); String name= nameNode.getIdentifier(); for (int i= 0; i < problems.length; i++) { IProblem curr= problems[i]; int probStart= curr.getSourceStart(); int probEnd= curr.getSourceEnd() + 1; if (probStart > bodyStart && probEnd < bodyEnd) { int currKind= getProblemKind(curr); if ((nameNodeKind & currKind) != 0) { ASTNode node= NodeFinder.perform(parent, probStart, (probEnd - probStart)); if (node instanceof SimpleName && name.equals(((SimpleName) node).getIdentifier())) { res.add((SimpleName) node); } } } } return res.toArray(new SimpleName[res.size()]); }
Example 6
Source File: ProblemLocation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public ProblemLocation(IProblem problem) { fId= problem.getID(); fArguments= problem.getArguments(); fOffset= problem.getSourceStart(); fLength= problem.getSourceEnd() - fOffset + 1; fIsError= problem.isError(); fMarkerType= problem instanceof CategorizedProblem ? ((CategorizedProblem) problem).getMarkerType() : IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER; }
Example 7
Source File: Preprocessor.java From APDE with GNU General Public License v2.0 | 5 votes |
public CompilerProblem buildCompilerProblem(IProblem problem) throws TextTransform.LockException { // ECJ gives us the full path to the file, we just want the filename String filename = new File(new String(problem.getOriginatingFileName())).getName(); // Check to see if main file or not if (context.getSketchMainFilename().equals(filename)) { return buildCompilerProblem( new TextTransform.Range(problem.getSourceStart(), problem.getSourceEnd() - problem.getSourceStart() + 1), problem.isError(), problem.getMessage(), false); } else { // Check all java files for (SketchCode sketchFile : context.getSketchFiles()) { if (sketchFile.isJava() && sketchFile.getFilename().equals(filename)) { int absStart = problem.getSourceStart() - sketchFile.javaImportHeaderOffset; int line = sketchFile.lineForOffset(absStart); int start = absStart - sketchFile.offsetForLine(line); return new CompilerProblem(sketchFile, line, start, problem.getSourceEnd() - problem.getSourceStart() + 1, problem.isError(), problem.getMessage()); } } // If we can't find it System.err.println("Unable to find java file: " + filename); return new CompilerProblem(context.getSketchFiles().get(0), 0, 0, 1, problem.isError(), problem.getMessage()); } }
Example 8
Source File: JRJdtCompiler.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void acceptResult(CompilationResult result) { String className = ((CompilationUnit) result.getCompilationUnit()).className; int classIdx; for (classIdx = 0; classIdx < units.length; ++classIdx) { if (className.equals(units[classIdx].getName())) { break; } } if (result.hasErrors()) { //IProblem[] problems = result.getErrors(); IProblem[] problems = getJavaCompilationErrors(result); unitResults[classIdx].problems = problems; String sourceCode = units[classIdx].getSourceCode(); for (int i = 0; i < problems.length; i++) { IProblem problem = problems[i]; if (IProblem.UndefinedMethod == problem.getID()) { if ( problem.getSourceStart() >= 0 && problem.getSourceEnd() >= 0 ) { String methodName = sourceCode.substring( problem.getSourceStart(), problem.getSourceEnd() + 1 ); Method method = FunctionsUtil.getInstance(jasperReportsContext).getMethod4Function(methodName); if (method != null) { unitResults[classIdx].addMissingMethod(method); //continue; } } } } } else { ClassFile[] resultClassFiles = result.getClassFiles(); for (int i = 0; i < resultClassFiles.length; i++) { units[classIdx].setCompileData(resultClassFiles[i].getBytes()); } } }
Example 9
Source File: JRJdtCompiler.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
/** * */ public String getFormattedProblems() { StringBuilder problemBuilder = new StringBuilder(); for (int u = 0; u < units.length; u++) { String sourceCode = units[u].getSourceCode(); IProblem[] problems = unitResults[u].problems; if (problems != null && problems.length > 0) { for (int i = 0; i < problems.length; i++) { IProblem problem = problems[i]; problemBuilder.append(i + 1); problemBuilder.append(". "); problemBuilder.append(problem.getMessage()); if ( problem.getSourceStart() >= 0 && problem.getSourceEnd() >= 0 ) { int problemStartIndex = sourceCode.lastIndexOf("\n", problem.getSourceStart()) + 1; int problemEndIndex = sourceCode.indexOf("\n", problem.getSourceEnd()); if (problemEndIndex < 0) { problemEndIndex = sourceCode.length(); } problemBuilder.append("\n"); problemBuilder.append( sourceCode.substring( problemStartIndex, problemEndIndex ) ); problemBuilder.append("\n"); for(int j = problemStartIndex; j < problem.getSourceStart(); j++) { problemBuilder.append(" "); } if (problem.getSourceStart() == problem.getSourceEnd()) { problemBuilder.append("^"); } else { problemBuilder.append("<"); for(int j = problem.getSourceStart() + 1; j < problem.getSourceEnd(); j++) { problemBuilder.append("-"); } problemBuilder.append(">"); } problemBuilder.append("\n"); } } problemBuilder.append(problems.length); problemBuilder.append(" errors\n"); } } return problemBuilder.length() > 0 ? problemBuilder.toString() : null; }
Example 10
Source File: SourceRangeFactory.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public static ISourceRange create(IProblem problem) { return new SourceRange(problem.getSourceStart(), problem.getSourceEnd() - problem.getSourceStart() + 1); }
Example 11
Source File: SourceRange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public SourceRange(IProblem problem) { this(problem.getSourceStart(), problem.getSourceEnd() - problem.getSourceStart() + 1); }
Example 12
Source File: SourceRangeFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static ISourceRange create(IProblem problem) { return new SourceRange(problem.getSourceStart(), problem.getSourceEnd() - problem.getSourceStart() + 1); }