本文整理匯總了Java中org.eclipse.jdt.core.compiler.IProblem類的典型用法代碼示例。如果您正苦於以下問題:Java IProblem類的具體用法?Java IProblem怎麽用?Java IProblem使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IProblem類屬於org.eclipse.jdt.core.compiler包,在下文中一共展示了IProblem類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parse
import org.eclipse.jdt.core.compiler.IProblem; //導入依賴的package包/類
public void parse() throws ParseException {
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setSource(source.toCharArray());
Map<String, String> options = JavaCore.getOptions();
options.put("org.eclipse.jdt.core.compiler.source", "1.8");
parser.setCompilerOptions(options);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setUnitName("Program.java");
parser.setEnvironment(new String[] { classpath != null? classpath : "" },
new String[] { "" }, new String[] { "UTF-8" }, true);
parser.setResolveBindings(true);
cu = (CompilationUnit) parser.createAST(null);
List<IProblem> problems = Arrays.stream(cu.getProblems()).filter(p ->
p.isError() &&
p.getID() != IProblem.PublicClassMustMatchFileName && // we use "Program.java"
p.getID() != IProblem.ParameterMismatch // Evidence varargs
).collect(Collectors.toList());
if (problems.size() > 0)
throw new ParseException(problems);
}
示例2: getCorrections
import org.eclipse.jdt.core.compiler.IProblem; //導入依賴的package包/類
@Override
public IJavaCompletionProposal[] getCorrections(IInvocationContext context,
IProblemLocation[] locations) throws CoreException {
for (final IProblemLocation problem : locations) {
if ((problem.getProblemId() == IProblem.UnresolvedVariable
|| problem.getProblemId() == IProblem.UndefinedType)
&& Utils.isAPGAS(problem.getProblemArguments()[0])) {
if (!apgasInBuildPath(context.getCompilationUnit().getJavaProject())) {
return getAddAPGASToBuildPathProposals(context);
}
} else if (problem.getProblemId() == IProblem.UndefinedMethod
&& Utils.isAPGAS(problem.getProblemArguments()[1])) {
if (!apgasInBuildPath(context.getCompilationUnit().getJavaProject())) {
return getAddAPGASToBuildPathProposals(context);
} else {
return getImportStaticConstructsProposal(context);
}
}
}
return null;
}
示例3: getProblemKind
import org.eclipse.jdt.core.compiler.IProblem; //導入依賴的package包/類
private static int getProblemKind(IProblem problem) {
switch (problem.getID()) {
case IProblem.UndefinedField:
return FIELD;
case IProblem.UndefinedMethod:
return METHOD;
case IProblem.UndefinedLabel:
return LABEL;
case IProblem.UndefinedName:
case IProblem.UnresolvedVariable:
return NAME;
case IProblem.UndefinedType:
return TYPE;
}
return 0;
}
示例4: createRemoveUnusedCastFix
import org.eclipse.jdt.core.compiler.IProblem; //導入依賴的package包/類
public static UnusedCodeFix createRemoveUnusedCastFix(CompilationUnit compilationUnit, IProblemLocation problem) {
if (problem.getProblemId() != IProblem.UnnecessaryCast) {
return null;
}
ASTNode selectedNode= problem.getCoveringNode(compilationUnit);
ASTNode curr= selectedNode;
while (curr instanceof ParenthesizedExpression) {
curr= ((ParenthesizedExpression) curr).getExpression();
}
if (!(curr instanceof CastExpression)) {
return null;
}
return new UnusedCodeFix(FixMessages.UnusedCodeFix_RemoveCast_description, compilationUnit, new CompilationUnitRewriteOperation[] {new RemoveCastOperation((CastExpression)curr)});
}
示例5: convertRange
import org.eclipse.jdt.core.compiler.IProblem; //導入依賴的package包/類
@SuppressWarnings("restriction")
private static Range convertRange(IProblem problem) {
Position start = new Position();
Position end = new Position();
start.setLine(problem.getSourceLineNumber()-1);// VSCode is 0-based
end.setLine(problem.getSourceLineNumber()-1);
if(problem instanceof DefaultProblem){
DefaultProblem dProblem = (DefaultProblem)problem;
start.setCharacter(dProblem.getSourceColumnNumber() - 1);
int offset = 0;
if (dProblem.getSourceStart() != -1 && dProblem.getSourceEnd() != -1) {
offset = dProblem.getSourceEnd() - dProblem.getSourceStart() + 1;
}
end.setCharacter(dProblem.getSourceColumnNumber() - 1 + offset);
}
return new Range(start, end);
}
示例6: testCodeAction_removeUnusedImport
import org.eclipse.jdt.core.compiler.IProblem; //導入依賴的package包/類
@Test
public void testCodeAction_removeUnusedImport() throws Exception{
ICompilationUnit unit = getWorkingCopy(
"src/java/Foo.java",
"import java.sql.*; \n" +
"public class Foo {\n"+
" void foo() {\n"+
" }\n"+
"}\n");
CodeActionParams params = new CodeActionParams();
params.setTextDocument(new TextDocumentIdentifier(JDTUtils.toURI(unit)));
final Range range = getRange(unit, "java.sql");
params.setRange(range);
params.setContext(new CodeActionContext(Arrays.asList(getDiagnostic(Integer.toString(IProblem.UnusedImport), range))));
List<? extends Command> commands = server.codeAction(params).join();
Assert.assertNotNull(commands);
Assert.assertEquals(2, commands.size());
Command c = commands.get(0);
Assert.assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, c.getCommand());
}
示例7: testCodeAction_removeUnterminatedString
import org.eclipse.jdt.core.compiler.IProblem; //導入依賴的package包/類
@Test
public void testCodeAction_removeUnterminatedString() throws Exception{
ICompilationUnit unit = getWorkingCopy(
"src/java/Foo.java",
"public class Foo {\n"+
" void foo() {\n"+
"String s = \"some str\n" +
" }\n"+
"}\n");
CodeActionParams params = new CodeActionParams();
params.setTextDocument(new TextDocumentIdentifier(JDTUtils.toURI(unit)));
final Range range = getRange(unit, "some str");
params.setRange(range);
params.setContext(new CodeActionContext(Arrays.asList(getDiagnostic(Integer.toString(IProblem.UnterminatedString), range))));
List<? extends Command> commands = server.codeAction(params).join();
Assert.assertNotNull(commands);
Assert.assertEquals(1, commands.size());
Command c = commands.get(0);
Assert.assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, c.getCommand());
}
示例8: evaluateCodeActions
import org.eclipse.jdt.core.compiler.IProblem; //導入依賴的package包/類
protected List<Command> evaluateCodeActions(ICompilationUnit cu) throws JavaModelException {
CompilationUnit astRoot = SharedASTProvider.getInstance().getAST(cu, null);
IProblem[] problems = astRoot.getProblems();
Range range = getRange(cu, problems);
CodeActionParams parms = new CodeActionParams();
TextDocumentIdentifier textDocument = new TextDocumentIdentifier();
textDocument.setUri(JDTUtils.toURI(cu));
parms.setTextDocument(textDocument);
parms.setRange(range);
CodeActionContext context = new CodeActionContext();
context.setDiagnostics(DiagnosticsHandler.toDiagnosticsArray(Arrays.asList(problems)));
parms.setContext(context);
return new CodeActionHandler().getCodeActionCommands(parms, new NullProgressMonitor());
}
示例9: safeGetProblems
import org.eclipse.jdt.core.compiler.IProblem; //導入依賴的package包/類
/**
* Invoke CompilationResult#getProblems safely so that it works with
* 3.1.1 and more recent versions of the eclipse java compiler.
* See https://jsp.dev.java.net/issues/show_bug.cgi?id=13
*
* @param result The compilation result.
* @return The same object than CompilationResult#getProblems
*/
private static final IProblem[] safeGetProblems(CompilationResult result) {
if (!USE_INTROSPECTION_TO_INVOKE_GET_PROBLEM) {
try {
return result.getProblems();
} catch (NoSuchMethodError re) {
USE_INTROSPECTION_TO_INVOKE_GET_PROBLEM = true;
}
}
try {
if (GET_PROBLEM_METH == null) {
GET_PROBLEM_METH = result.getClass()
.getDeclaredMethod("getProblems", new Class[] {});
}
//an array of a particular type can be casted into an array of a super type.
return (IProblem[]) GET_PROBLEM_METH.invoke(result, null);
} catch (Throwable e) {
if (e instanceof RuntimeException) {
throw (RuntimeException)e;
} else {
throw new RuntimeException(e);
}
}
}
示例10: acceptResult
import org.eclipse.jdt.core.compiler.IProblem; //導入依賴的package包/類
@Override
public void acceptResult(CompilationResult result)
{
if (result.hasErrors())
{
IProblem[] problems = result.getProblems();
if (problemList == null)
problemList = new ArrayList<>(problems.length);
Collections.addAll(problemList, problems);
}
else
{
ClassFile[] classFiles = result.getClassFiles();
for (ClassFile classFile : classFiles)
targetClassLoader.addClass(className, classFile.getBytes());
}
}
示例11: assertNumberOfProblems
import org.eclipse.jdt.core.compiler.IProblem; //導入依賴的package包/類
protected static void assertNumberOfProblems(int nProblems, IProblem[] problems) {
if (problems.length != nProblems) {
StringBuffer buf = new StringBuffer("Wrong number of problems, is: ");
buf.append(problems.length).append(", expected: ").append(nProblems).append('\n');
for (int i = 0; i < problems.length; i++) {
buf.append(problems[i]);
buf.append('[')
.append(problems[i].getSourceStart())
.append(" ,")
.append(problems[i].getSourceEnd())
.append(']');
buf.append('\n');
}
assertTrue(buf.toString(), false);
}
}
示例12: getProblemKind
import org.eclipse.jdt.core.compiler.IProblem; //導入依賴的package包/類
private static int getProblemKind(IProblem problem) {
switch (problem.getID()) {
case IProblem.UndefinedField:
return FIELD;
case IProblem.UndefinedMethod:
return METHOD;
case IProblem.UndefinedLabel:
return LABEL;
case IProblem.UndefinedName:
case IProblem.UnresolvedVariable:
return NAME;
case IProblem.UndefinedType:
return TYPE;
}
return 0;
}
示例13: createCleanUp
import org.eclipse.jdt.core.compiler.IProblem; //導入依賴的package包/類
public static ICleanUpFix createCleanUp(
CompilationUnit compilationUnit, IProblemLocation[] locations, int problemID) {
ICompilationUnit cu = (ICompilationUnit) compilationUnit.getJavaElement();
if (!JavaModelUtil.is50OrHigher(cu.getJavaProject())) return null;
List<CompilationUnitRewriteOperation> operations =
new ArrayList<CompilationUnitRewriteOperation>();
if (locations == null) {
org.eclipse.jdt.core.compiler.IProblem[] problems = compilationUnit.getProblems();
locations = new IProblemLocation[problems.length];
for (int i = 0; i < problems.length; i++) {
if (problems[i].getID() == problemID) locations[i] = new ProblemLocation(problems[i]);
}
}
createAddNullAnnotationOperations(compilationUnit, locations, operations);
createRemoveRedundantNullAnnotationsOperations(compilationUnit, locations, operations);
if (operations.size() == 0) return null;
CompilationUnitRewriteOperation[] operationsArray =
operations.toArray(new CompilationUnitRewriteOperation[operations.size()]);
return new NullAnnotationsFix(
FixMessages.NullAnnotationsFix_add_annotation_change_name,
compilationUnit,
operationsArray);
}
示例14: createRemoveRedundantNullAnnotationsOperations
import org.eclipse.jdt.core.compiler.IProblem; //導入依賴的package包/類
private static void createRemoveRedundantNullAnnotationsOperations(
CompilationUnit compilationUnit,
IProblemLocation[] locations,
List<CompilationUnitRewriteOperation> result) {
for (int i = 0; i < locations.length; i++) {
IProblemLocation problem = locations[i];
if (problem == null) continue; // problem was filtered out by createCleanUp()
int problemId = problem.getProblemId();
if (problemId == IProblem.RedundantNullAnnotation
|| problemId == IProblem.RedundantNullDefaultAnnotationPackage
|| problemId == IProblem.RedundantNullDefaultAnnotationType
|| problemId == IProblem.RedundantNullDefaultAnnotationMethod) {
RemoveRedundantAnnotationRewriteOperation operation =
new RemoveRedundantAnnotationRewriteOperation(compilationUnit, problem);
result.add(operation);
}
}
}
示例15: getJavaCompilationErrors
import org.eclipse.jdt.core.compiler.IProblem; //導入依賴的package包/類
/**
*
*/
protected IProblem[] getJavaCompilationErrors(CompilationResult result) {
return result.getErrors();
//
// try {
// Method getErrorsMethod = result.getClass().getMethod("getErrors",
// (Class[]) null);
// return (IProblem[]) getErrorsMethod.invoke(result, (Object[]) null);
// } catch (SecurityException e) {
// throw new JRRuntimeException("Error resolving JDT methods", e);
// } catch (NoSuchMethodException e) {
// throw new JRRuntimeException("Error resolving JDT methods", e);
// } catch (IllegalArgumentException e) {
// throw new JRRuntimeException("Error invoking JDT methods", e);
// } catch (IllegalAccessException e) {
// throw new JRRuntimeException("Error invoking JDT methods", e);
// } catch (InvocationTargetException e) {
// throw new JRRuntimeException("Error invoking JDT methods", e);
// }
}