本文整理汇总了Java中org.eclipse.jdt.core.compiler.CategorizedProblem.getSourceStart方法的典型用法代码示例。如果您正苦于以下问题:Java CategorizedProblem.getSourceStart方法的具体用法?Java CategorizedProblem.getSourceStart怎么用?Java CategorizedProblem.getSourceStart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.compiler.CategorizedProblem
的用法示例。
在下文中一共展示了CategorizedProblem.getSourceStart方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateMissingAbstractMethods
import org.eclipse.jdt.core.compiler.CategorizedProblem; //导入方法依赖的package包/类
/**
* INTERNAL USE-ONLY
* Generate the byte for problem method infos that correspond to missing abstract methods.
* http://dev.eclipse.org/bugs/show_bug.cgi?id=3179
*
* @param methodDeclarations Array of all missing abstract methods
*/
public void generateMissingAbstractMethods(MethodDeclaration[] methodDeclarations, CompilationResult compilationResult) {
if (methodDeclarations != null) {
TypeDeclaration currentDeclaration = this.referenceBinding.scope.referenceContext;
int typeDeclarationSourceStart = currentDeclaration.sourceStart();
int typeDeclarationSourceEnd = currentDeclaration.sourceEnd();
for (int i = 0, max = methodDeclarations.length; i < max; i++) {
MethodDeclaration methodDeclaration = methodDeclarations[i];
MethodBinding methodBinding = methodDeclaration.binding;
String readableName = new String(methodBinding.readableName());
CategorizedProblem[] problems = compilationResult.problems;
int problemsCount = compilationResult.problemCount;
for (int j = 0; j < problemsCount; j++) {
CategorizedProblem problem = problems[j];
if (problem != null
&& problem.getID() == IProblem.AbstractMethodMustBeImplemented
&& problem.getMessage().indexOf(readableName) != -1
&& problem.getSourceStart() >= typeDeclarationSourceStart
&& problem.getSourceEnd() <= typeDeclarationSourceEnd) {
// we found a match
addMissingAbstractProblemMethod(methodDeclaration, methodBinding, problem, compilationResult);
}
}
}
}
}
示例2: isSuppressed
import org.eclipse.jdt.core.compiler.CategorizedProblem; //导入方法依赖的package包/类
public boolean isSuppressed(CategorizedProblem problem) {
if (this.suppressWarningsCount == 0) return false;
int irritant = ProblemReporter.getIrritant(problem.getID());
if (irritant == 0) return false;
int start = problem.getSourceStart();
int end = problem.getSourceEnd();
nextSuppress: for (int iSuppress = 0, suppressCount = this.suppressWarningsCount; iSuppress < suppressCount; iSuppress++) {
long position = this.suppressWarningScopePositions[iSuppress];
int startSuppress = (int) (position >>> 32);
int endSuppress = (int) position;
if (start < startSuppress) continue nextSuppress;
if (end > endSuppress) continue nextSuppress;
if (this.suppressWarningIrritants[iSuppress].isSet(irritant))
return true;
}
return false;
}
示例3: logXmlExtraProblem
import org.eclipse.jdt.core.compiler.CategorizedProblem; //导入方法依赖的package包/类
private void logXmlExtraProblem(CategorizedProblem problem, int globalErrorCount, int localErrorCount) {
final int sourceStart = problem.getSourceStart();
final int sourceEnd = problem.getSourceEnd();
boolean isError = problem.isError();
this.parameters.put(Logger.PROBLEM_SEVERITY, isError ? Logger.ERROR : Logger.WARNING);
this.parameters.put(Logger.PROBLEM_LINE, new Integer(problem.getSourceLineNumber()));
this.parameters.put(Logger.PROBLEM_SOURCE_START, new Integer(sourceStart));
this.parameters.put(Logger.PROBLEM_SOURCE_END, new Integer(sourceEnd));
printTag(Logger.EXTRA_PROBLEM_TAG, this.parameters, true, false);
this.parameters.put(Logger.VALUE, problem.getMessage());
printTag(Logger.PROBLEM_MESSAGE, this.parameters, true, true);
extractContext(problem, null);
endTag(Logger.EXTRA_PROBLEM_TAG);
}
示例4: logXmlProblem
import org.eclipse.jdt.core.compiler.CategorizedProblem; //导入方法依赖的package包/类
/**
* @param problem
* the given problem to log
* @param unitSource
* the given unit source
*/
private void logXmlProblem(CategorizedProblem problem, char[] unitSource) {
final int sourceStart = problem.getSourceStart();
final int sourceEnd = problem.getSourceEnd();
final int id = problem.getID();
this.parameters.put(Logger.ID, getFieldName(id)); // ID as field name
this.parameters.put(Logger.PROBLEM_ID, new Integer(id)); // ID as numeric value
boolean isError = problem.isError();
int severity = isError ? ProblemSeverities.Error : ProblemSeverities.Warning;
this.parameters.put(Logger.PROBLEM_SEVERITY, isError ? Logger.ERROR : Logger.WARNING);
this.parameters.put(Logger.PROBLEM_LINE, new Integer(problem.getSourceLineNumber()));
this.parameters.put(Logger.PROBLEM_SOURCE_START, new Integer(sourceStart));
this.parameters.put(Logger.PROBLEM_SOURCE_END, new Integer(sourceEnd));
String problemOptionKey = getProblemOptionKey(id);
if (problemOptionKey != null) {
this.parameters.put(Logger.PROBLEM_OPTION_KEY, problemOptionKey);
}
int categoryID = ProblemReporter.getProblemCategory(severity, id);
this.parameters.put(Logger.PROBLEM_CATEGORY_ID, new Integer(categoryID));
printTag(Logger.PROBLEM_TAG, this.parameters, true, false);
this.parameters.put(Logger.VALUE, problem.getMessage());
printTag(Logger.PROBLEM_MESSAGE, this.parameters, true, true);
extractContext(problem, unitSource);
String[] arguments = problem.getArguments();
final int length = arguments.length;
if (length != 0) {
printTag(Logger.PROBLEM_ARGUMENTS, null, true, false);
for (int i = 0; i < length; i++) {
this.parameters.put(Logger.PROBLEM_ARGUMENT_VALUE, arguments[i]);
printTag(Logger.PROBLEM_ARGUMENT, this.parameters, true, true);
}
endTag(Logger.PROBLEM_ARGUMENTS);
}
endTag(Logger.PROBLEM_TAG);
}
示例5: markIncludedProblems
import org.eclipse.jdt.core.compiler.CategorizedProblem; //导入方法依赖的package包/类
private boolean markIncludedProblems(int start, int end) {
boolean foundProblems = false;
next: for (int i = 0, max = this.problems.length; i < max; i++) {
CategorizedProblem problem = this.problems[i];
if(this.usedOrIrrelevantProblems[i]) continue next;
switch(problem.getID()) {
case IProblem.ParsingErrorOnKeywordNoSuggestion :
case IProblem.ParsingErrorOnKeyword :
case IProblem.ParsingError :
case IProblem.ParsingErrorNoSuggestion :
case IProblem.ParsingErrorInsertTokenBefore :
case IProblem.ParsingErrorInsertTokenAfter :
case IProblem.ParsingErrorDeleteToken :
case IProblem.ParsingErrorDeleteTokens :
case IProblem.ParsingErrorMergeTokens :
case IProblem.ParsingErrorInvalidToken :
case IProblem.ParsingErrorMisplacedConstruct :
case IProblem.ParsingErrorReplaceTokens :
case IProblem.ParsingErrorNoSuggestionForTokens :
case IProblem.ParsingErrorUnexpectedEOF :
case IProblem.ParsingErrorInsertToComplete :
case IProblem.ParsingErrorInsertToCompleteScope :
case IProblem.ParsingErrorInsertToCompletePhrase :
case IProblem.EndOfSource :
case IProblem.InvalidHexa :
case IProblem.InvalidOctal :
case IProblem.InvalidCharacterConstant :
case IProblem.InvalidEscape :
case IProblem.InvalidInput :
case IProblem.InvalidUnicodeEscape :
case IProblem.InvalidFloat :
case IProblem.NullSourceString :
case IProblem.UnterminatedString :
case IProblem.UnterminatedComment :
case IProblem.InvalidDigit :
break;
default:
this.usedOrIrrelevantProblems[i] = true;
continue next;
}
int problemStart = problem.getSourceStart();
int problemEnd = problem.getSourceEnd();
if ((start <= problemStart) && (problemStart <= end) ||
(start <= problemEnd) && (problemEnd <= end)) {
this.usedOrIrrelevantProblems[i] = true;
foundProblems = true;
}
}
return foundProblems;
}
示例6: checkAndTagAsMalformed
import org.eclipse.jdt.core.compiler.CategorizedProblem; //导入方法依赖的package包/类
private boolean checkAndTagAsMalformed(ASTNode node) {
boolean tagWithErrors = false;
search: for (int i = 0, max = this.problems.length; i < max; i++) {
CategorizedProblem problem = this.problems[i];
switch(problem.getID()) {
case IProblem.ParsingErrorOnKeywordNoSuggestion :
case IProblem.ParsingErrorOnKeyword :
case IProblem.ParsingError :
case IProblem.ParsingErrorNoSuggestion :
case IProblem.ParsingErrorInsertTokenBefore :
case IProblem.ParsingErrorInsertTokenAfter :
case IProblem.ParsingErrorDeleteToken :
case IProblem.ParsingErrorDeleteTokens :
case IProblem.ParsingErrorMergeTokens :
case IProblem.ParsingErrorInvalidToken :
case IProblem.ParsingErrorMisplacedConstruct :
case IProblem.ParsingErrorReplaceTokens :
case IProblem.ParsingErrorNoSuggestionForTokens :
case IProblem.ParsingErrorUnexpectedEOF :
case IProblem.ParsingErrorInsertToComplete :
case IProblem.ParsingErrorInsertToCompleteScope :
case IProblem.ParsingErrorInsertToCompletePhrase :
case IProblem.EndOfSource :
case IProblem.InvalidHexa :
case IProblem.InvalidOctal :
case IProblem.InvalidCharacterConstant :
case IProblem.InvalidEscape :
case IProblem.InvalidInput :
case IProblem.InvalidUnicodeEscape :
case IProblem.InvalidFloat :
case IProblem.NullSourceString :
case IProblem.UnterminatedString :
case IProblem.UnterminatedComment :
case IProblem.InvalidDigit :
break;
default:
continue search;
}
int position = problem.getSourceStart();
int start = node.getStartPosition();
int end = start + node.getLength();
if ((start <= position) && (position <= end)) {
node.setFlags(node.getFlags() | ASTNode.MALFORMED);
// clear the bits on parent
ASTNode currentNode = node.getParent();
while (currentNode != null) {
currentNode.setFlags(currentNode.getFlags() & ~ASTNode.MALFORMED);
currentNode = currentNode.getParent();
}
tagWithErrors = true;
}
}
return tagWithErrors;
}
示例7: errorReportSource
import org.eclipse.jdt.core.compiler.CategorizedProblem; //导入方法依赖的package包/类
private String errorReportSource(CategorizedProblem problem, char[] unitSource, int bits) {
//extra from the source the innacurate token
//and "highlight" it using some underneath ^^^^^
//put some context around too.
//this code assumes that the font used in the console is fixed size
//sanity .....
int startPosition = problem.getSourceStart();
int endPosition = problem.getSourceEnd();
if (unitSource == null) {
if (problem.getOriginatingFileName() != null) {
try {
unitSource = Util.getFileCharContent(new File(new String(problem.getOriginatingFileName())), null);
} catch (IOException e) {
// ignore;
}
}
}
int length;
if ((startPosition > endPosition)
|| ((startPosition < 0) && (endPosition < 0))
|| (unitSource == null)
|| (length = unitSource.length) == 0)
return Messages.problem_noSourceInformation;
StringBuffer errorBuffer = new StringBuffer();
if ((bits & Main.Logger.EMACS) == 0) {
errorBuffer.append(' ').append(Messages.bind(Messages.problem_atLine, String.valueOf(problem.getSourceLineNumber())));
errorBuffer.append(Util.LINE_SEPARATOR);
}
errorBuffer.append('\t');
char c;
final char SPACE = '\u0020';
final char MARK = '^';
final char TAB = '\t';
//the next code tries to underline the token.....
//it assumes (for a good display) that token source does not
//contain any \r \n. This is false on statements !
//(the code still works but the display is not optimal !)
// expand to line limits
int begin;
int end;
for (begin = startPosition >= length ? length - 1 : startPosition; begin > 0; begin--) {
if ((c = unitSource[begin - 1]) == '\n' || c == '\r') break;
}
for (end = endPosition >= length ? length - 1 : endPosition ; end+1 < length; end++) {
if ((c = unitSource[end + 1]) == '\r' || c == '\n') break;
}
// trim left and right spaces/tabs
while ((c = unitSource[begin]) == ' ' || c == '\t') begin++;
//while ((c = unitSource[end]) == ' ' || c == '\t') end--; TODO (philippe) should also trim right, but all tests are to be updated
// copy source
errorBuffer.append(unitSource, begin, end-begin+1);
errorBuffer.append(Util.LINE_SEPARATOR).append("\t"); //$NON-NLS-1$
// compute underline
for (int i = begin; i <startPosition; i++) {
errorBuffer.append((unitSource[i] == TAB) ? TAB : SPACE);
}
for (int i = startPosition; i <= (endPosition >= length ? length - 1 : endPosition); i++) {
errorBuffer.append(MARK);
}
return errorBuffer.toString();
}
示例8: extractContext
import org.eclipse.jdt.core.compiler.CategorizedProblem; //导入方法依赖的package包/类
private void extractContext(CategorizedProblem problem, char[] unitSource) {
//sanity .....
int startPosition = problem.getSourceStart();
int endPosition = problem.getSourceEnd();
if (unitSource == null) {
if (problem.getOriginatingFileName() != null) {
try {
unitSource = Util.getFileCharContent(new File(new String(problem.getOriginatingFileName())), null);
} catch(IOException e) {
// ignore
}
}
}
int length;
if ((startPosition > endPosition)
|| ((startPosition < 0) && (endPosition < 0))
|| (unitSource == null)
|| ((length = unitSource.length) <= 0)
|| (endPosition > length)) {
this.parameters.put(Logger.VALUE, Messages.problem_noSourceInformation);
this.parameters.put(Logger.SOURCE_START, "-1"); //$NON-NLS-1$
this.parameters.put(Logger.SOURCE_END, "-1"); //$NON-NLS-1$
printTag(Logger.SOURCE_CONTEXT, this.parameters, true, true);
return;
}
char c;
//the next code tries to underline the token.....
//it assumes (for a good display) that token source does not
//contain any \r \n. This is false on statements !
//(the code still works but the display is not optimal !)
// expand to line limits
int begin, end;
for (begin = startPosition >= length ? length - 1 : startPosition; begin > 0; begin--) {
if ((c = unitSource[begin - 1]) == '\n' || c == '\r') break;
}
for (end = endPosition >= length ? length - 1 : endPosition ; end+1 < length; end++) {
if ((c = unitSource[end + 1]) == '\r' || c == '\n') break;
}
// trim left and right spaces/tabs
while ((c = unitSource[begin]) == ' ' || c == '\t') begin++;
while ((c = unitSource[end]) == ' ' || c == '\t') end--;
// copy source
StringBuffer buffer = new StringBuffer();
buffer.append(unitSource, begin, end - begin + 1);
this.parameters.put(Logger.VALUE, String.valueOf(buffer));
this.parameters.put(Logger.SOURCE_START, Integer.toString(startPosition - begin));
this.parameters.put(Logger.SOURCE_END, Integer.toString(endPosition - begin));
printTag(Logger.SOURCE_CONTEXT, this.parameters, true, true);
}
示例9: addProblemMethod
import org.eclipse.jdt.core.compiler.CategorizedProblem; //导入方法依赖的package包/类
/**
* INTERNAL USE-ONLY
* Generate the byte for a problem method info that correspond to a boggus method.
*
* @param method org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration
* @param methodBinding org.eclipse.jdt.internal.compiler.nameloopkup.MethodBinding
* @param problems org.eclipse.jdt.internal.compiler.problem.Problem[]
*/
public void addProblemMethod(
AbstractMethodDeclaration method,
MethodBinding methodBinding,
CategorizedProblem[] problems) {
if (methodBinding.isAbstract() && methodBinding.declaringClass.isInterface()) {
method.abort(ProblemSeverities.AbortType, null);
}
// always clear the strictfp/native/abstract bit for a problem method
generateMethodInfoHeader(methodBinding, methodBinding.modifiers & ~(ClassFileConstants.AccStrictfp | ClassFileConstants.AccNative | ClassFileConstants.AccAbstract));
int methodAttributeOffset = this.contentsOffset;
int attributesNumber = generateMethodInfoAttributes(methodBinding);
// Code attribute
attributesNumber++;
int codeAttributeOffset = this.contentsOffset;
generateCodeAttributeHeader();
this.codeStream.reset(method, this);
String problemString = "" ; //$NON-NLS-1$
int problemLine = 0;
if (problems != null) {
int max = problems.length;
StringBuffer buffer = new StringBuffer(25);
int count = 0;
for (int i = 0; i < max; i++) {
CategorizedProblem problem = problems[i];
if ((problem != null)
&& (problem.isError())
&& (problem.getSourceStart() >= method.declarationSourceStart)
&& (problem.getSourceEnd() <= method.declarationSourceEnd)) {
buffer.append("\t" +problem.getMessage() + "\n" ); //$NON-NLS-1$ //$NON-NLS-2$
count++;
if (problemLine == 0) {
problemLine = problem.getSourceLineNumber();
}
problems[i] = null;
}
} // insert the top line afterwards, once knowing how many problems we have to consider
if (count > 1) {
buffer.insert(0, Messages.compilation_unresolvedProblems);
} else {
buffer.insert(0, Messages.compilation_unresolvedProblem);
}
problemString = buffer.toString();
}
// return codeStream.generateCodeAttributeForProblemMethod(comp.options.runtimeExceptionNameForCompileError, "")
this.codeStream.generateCodeAttributeForProblemMethod(problemString);
completeCodeAttributeForProblemMethod(
method,
methodBinding,
codeAttributeOffset,
((SourceTypeBinding) methodBinding.declaringClass)
.scope
.referenceCompilationUnit()
.compilationResult
.getLineSeparatorPositions(),
problemLine);
completeMethodInfo(methodBinding, methodAttributeOffset, attributesNumber);
}
示例10: getAllProblems
import org.eclipse.jdt.core.compiler.CategorizedProblem; //导入方法依赖的package包/类
public CategorizedProblem[] getAllProblems() {
CategorizedProblem[] onlyProblems = getProblems();
int onlyProblemCount = onlyProblems != null ? onlyProblems.length : 0;
CategorizedProblem[] onlyTasks = getTasks();
int onlyTaskCount = onlyTasks != null ? onlyTasks.length : 0;
if (onlyTaskCount == 0) {
return onlyProblems;
}
if (onlyProblemCount == 0) {
return onlyTasks;
}
int totalNumberOfProblem = onlyProblemCount + onlyTaskCount;
CategorizedProblem[] allProblems = new CategorizedProblem[totalNumberOfProblem];
int allProblemIndex = 0;
int taskIndex = 0;
int problemIndex = 0;
while (taskIndex + problemIndex < totalNumberOfProblem) {
CategorizedProblem nextTask = null;
CategorizedProblem nextProblem = null;
if (taskIndex < onlyTaskCount) {
nextTask = onlyTasks[taskIndex];
}
if (problemIndex < onlyProblemCount) {
nextProblem = onlyProblems[problemIndex];
}
// select the next problem
CategorizedProblem currentProblem = null;
if (nextProblem != null) {
if (nextTask != null) {
if (nextProblem.getSourceStart() < nextTask.getSourceStart()) {
currentProblem = nextProblem;
problemIndex++;
} else {
currentProblem = nextTask;
taskIndex++;
}
} else {
currentProblem = nextProblem;
problemIndex++;
}
} else {
if (nextTask != null) {
currentProblem = nextTask;
taskIndex++;
}
}
allProblems[allProblemIndex++] = currentProblem;
}
return allProblems;
}