本文整理汇总了Java中org.eclipse.jdt.core.dom.CompilationUnit.getProblems方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnit.getProblems方法的具体用法?Java CompilationUnit.getProblems怎么用?Java CompilationUnit.getProblems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.CompilationUnit
的用法示例。
在下文中一共展示了CompilationUnit.getProblems方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluateCodeActions
import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的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());
}
示例2: testParse
import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
@Test
public void testParse() throws Exception {
IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true,true);
IFile impl = (IFile) ResourceManager
.getResource(project.getProject().getFullPath().append("src/test/java/SimpleImpl.java").toString());
ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(impl);
CompilationUnit cu = JDTManager.parse(compilationUnit);
IProblem[] pbs = cu.getProblems();
assertEquals(0, pbs.length);
}
示例3: testRenameClass
import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
@Test
public void testRenameClass() throws Exception {
IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true,true);
IFile impl = (IFile) ResourceManager
.getResource(project.getProject().getFullPath().append("src/test/java/SimpleImpl.java").toString());
// The rename method only renames the class name within the file. It does not rename the file and it is expected.
// See the comment of the JDTManager.renameClass (...) api
// And this is why we expect 1 pb "assertEquals(1, pbs.length);" below
IFile f = JDTManager.renameClass(impl, "SimpleImpl", "SimpleImpl1", new NullProgressMonitor());
Waiter.waitUntil(new ICondition () {
@Override
public boolean checkCondition() throws Exception {
IFolder folder = (IFolder) ResourceManager.getResource(project.getProject().getFullPath().append("src/test/java").toString());
IFile frenamed = folder.getFile("SimpleImpl1.java");
return frenamed.getName().equals("SimpleImpl1.java");
}
@Override
public String getFailureMessage() {
return "file not renamed";
}
});
ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(f);
CompilationUnit cu = JDTManager.parse(compilationUnit);
IProblem[] pbs = cu.getProblems();
assertEquals(1, pbs.length);
}
示例4: parse
import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
public void parse(ASTVisitor visitor) {
parser.setSource(this.source);
CompilationUnit unit = (CompilationUnit) parser.createAST(null);
// if(unit.getProblems().length > 0)
// throw new RuntimeException("code has compilation errors");
unit.accept(visitor);
hasErrors = unit.getProblems().length > 0;
}
示例5: determineUnresolvableImports
import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
private static Collection<ImportDeclaration> determineUnresolvableImports(CompilationUnit cu) {
Collection<ImportDeclaration> unresolvableImports= new ArrayList<>(cu.imports().size());
for (IProblem problem : cu.getProblems()) {
if (problem.getID() == IProblem.ImportNotFound) {
ImportDeclaration problematicImport= getProblematicImport(problem, cu);
if (problematicImport != null) {
unresolvableImports.add(problematicImport);
}
}
}
return unresolvableImports;
}
示例6: performValidation
import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
private IStatus performValidation(IProgressMonitor monitor) throws JavaModelException {
long start = System.currentTimeMillis();
List<ICompilationUnit> cusToReconcile = new ArrayList<>();
synchronized (toReconcile) {
cusToReconcile.addAll(toReconcile);
toReconcile.clear();
}
if (cusToReconcile.isEmpty()) {
return Status.OK_STATUS;
}
// first reconcile all units with content changes
SubMonitor progress = SubMonitor.convert(monitor, cusToReconcile.size() + 1);
for (ICompilationUnit cu : cusToReconcile) {
cu.reconcile(ICompilationUnit.NO_AST, true, null, progress.newChild(1));
}
this.sharedASTProvider.invalidateAll();
List<ICompilationUnit> toValidate = Arrays.asList(JavaCore.getWorkingCopies(null));
List<CompilationUnit> astRoots = this.sharedASTProvider.getASTs(toValidate, monitor);
for (CompilationUnit astRoot : astRoots) {
// report errors, even if there are no problems in the file: The client need to know that they got fixed.
ICompilationUnit unit = (ICompilationUnit) astRoot.getTypeRoot();
DiagnosticsHandler handler = new DiagnosticsHandler(connection, unit);
handler.beginReporting();
for (IProblem problem : astRoot.getProblems()) {
handler.acceptProblem(problem);
}
handler.endReporting();
}
JavaLanguageServerPlugin.logInfo("Reconciled " + toReconcile.size() + ", validated: " + toValidate.size() + ". Took " + (System.currentTimeMillis() - start) + " ms");
return Status.OK_STATUS;
}
示例7: testCreateCompilationUnit
import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
@Test
public void testCreateCompilationUnit() throws Exception {
IJavaProject javaProject = newEmptyProject();
// @formatter:off
String fooContent =
"package org;\n"+
"public class Foo {"+
"}\n";
String barContent =
"package org;\n"+
"public class Bar {\n"+
" Foo test() { return null; }\n" +
"}\n";
// @formatter:on
IFolder src = javaProject.getProject().getFolder("src");
javaProject.getPackageFragmentRoot(src);
File sourceDirectory = src.getRawLocation().makeAbsolute().toFile();
File org = new File(sourceDirectory, "org");
org.mkdir();
File file = new File(org, "Bar.java");
file.createNewFile();
FileUtils.writeStringToFile(file, barContent);
ICompilationUnit bar = JDTUtils.resolveCompilationUnit(file.toURI());
bar.getResource().refreshLocal(IResource.DEPTH_ONE, null);
assertNotNull("Bar doesn't exist", javaProject.findType("org.Bar"));
file = new File(org, "Foo.java");
file.createNewFile();
URI uri = file.toURI();
ICompilationUnit unit = JDTUtils.resolveCompilationUnit(uri);
openDocument(unit, "", 1);
FileUtils.writeStringToFile(file, fooContent);
changeDocumentFull(unit, fooContent, 1);
saveDocument(unit);
closeDocument(unit);
CompilationUnit astRoot = sharedASTProvider.getAST(bar, null);
IProblem[] problems = astRoot.getProblems();
assertEquals("Unexpected number of errors", 0, problems.length);
}
示例8: checkPackageDeclaration
import org.eclipse.jdt.core.dom.CompilationUnit; //导入方法依赖的package包/类
private ICompilationUnit checkPackageDeclaration(String uri, ICompilationUnit unit) {
if (unit.getResource() != null && unit.getJavaProject() != null && unit.getJavaProject().getProject().getName().equals(ProjectsManager.DEFAULT_PROJECT_NAME)) {
try {
CompilationUnit astRoot = SharedASTProvider.getInstance().getAST(unit, new NullProgressMonitor());
IProblem[] problems = astRoot.getProblems();
for (IProblem problem : problems) {
if (problem.getID() == IProblem.PackageIsNotExpectedPackage) {
IResource file = unit.getResource();
boolean toRemove = file.isLinked();
if (toRemove) {
IPath path = file.getParent().getProjectRelativePath();
if (path.segmentCount() > 0 && JDTUtils.SRC.equals(path.segments()[0])) {
String packageNameResource = path.removeFirstSegments(1).toString().replace(JDTUtils.PATH_SEPARATOR, JDTUtils.PERIOD);
path = file.getLocation();
if (path != null && path.segmentCount() > 0) {
path = path.removeLastSegments(1);
String pathStr = path.toString().replace(JDTUtils.PATH_SEPARATOR, JDTUtils.PERIOD);
if (pathStr.endsWith(packageNameResource)) {
toRemove = false;
}
}
}
}
if (toRemove) {
file.delete(true, new NullProgressMonitor());
sharedASTProvider.invalidate(unit);
unit.discardWorkingCopy();
unit = JDTUtils.resolveCompilationUnit(uri);
unit.becomeWorkingCopy(new NullProgressMonitor());
triggerValidation(unit);
}
break;
}
}
} catch (CoreException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
}
return unit;
}