本文整理匯總了Java中org.eclipse.jdt.core.compiler.IProblem.getSourceEnd方法的典型用法代碼示例。如果您正苦於以下問題:Java IProblem.getSourceEnd方法的具體用法?Java IProblem.getSourceEnd怎麽用?Java IProblem.getSourceEnd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.compiler.IProblem
的用法示例。
在下文中一共展示了IProblem.getSourceEnd方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: hasErrors
import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
/**
* 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;
}
示例2: getNameNodeProblemKind
import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
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;
}
示例3: findByProblems
import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
public static SimpleName[] findByProblems(ASTNode parent, SimpleName nameNode) {
ArrayList<SimpleName> res= new ArrayList<>();
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()]);
}
示例4: getNameNodeProblemKind
import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
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;
}
示例5: findByProblems
import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
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()]);
}
示例6: ProblemLocation
import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
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;
}
示例7: acceptResult
import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
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());
}
}
}
示例8: acceptResult
import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
@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());
}
}
}
示例9: getFormattedProblems
import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
/**
*
*/
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;
}
示例10: create
import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
public static ISourceRange create(IProblem problem) {
return new SourceRange(
problem.getSourceStart(), problem.getSourceEnd() - problem.getSourceStart() + 1);
}
示例11: getFormattedProblems
import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
/**
*
*/
public String getFormattedProblems() {
StringBuffer problemBuffer = new StringBuffer();
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];
problemBuffer.append(i + 1);
problemBuffer.append(". ");
problemBuffer.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();
}
problemBuffer.append("\n");
problemBuffer.append(sourceCode.substring(problemStartIndex, problemEndIndex));
problemBuffer.append("\n");
for (int j = problemStartIndex; j < problem.getSourceStart(); j++) {
problemBuffer.append(" ");
}
if (problem.getSourceStart() == problem.getSourceEnd()) {
problemBuffer.append("^");
} else {
problemBuffer.append("<");
for (int j = problem.getSourceStart() + 1; j < problem.getSourceEnd(); j++) {
problemBuffer.append("-");
}
problemBuffer.append(">");
}
problemBuffer.append("\n");
}
}
problemBuffer.append(problems.length);
problemBuffer.append(" errors\n");
}
}
return problemBuffer.length() > 0 ? problemBuffer.toString() : null;
}