项目:vscode-javac
文件:Lints.java
static Optional<Diagnostic> convert(javax.tools.Diagnostic<? extends JavaFileObject> error) {
if (error.getStartPosition() != javax.tools.Diagnostic.nopOS) {
Range range = position(error);
Diagnostic diagnostic = new Diagnostic();
DiagnosticSeverity severity = severity(error.getKind());
diagnostic.setSeverity(severity);
diagnostic.setRange(range);
diagnostic.setCode(error.getCode());
diagnostic.setMessage(error.getMessage(null));
return Optional.of(diagnostic);
} else {
LOG.warning("Skipped " + error.getMessage(Locale.getDefault()));
return Optional.empty();
}
}
项目:vscode-javac
文件:Lints.java
private static Range position(javax.tools.Diagnostic<? extends JavaFileObject> error) {
if (error instanceof ClientCodeWrapper.DiagnosticSourceUnwrapper)
error = ((ClientCodeWrapper.DiagnosticSourceUnwrapper) error).d;
JCDiagnostic diagnostic = (JCDiagnostic) error;
DiagnosticSource source = diagnostic.getDiagnosticSource();
long start = error.getStartPosition(),end = error.getEndPosition();
if (end == start) end = start + 1;
return new Range(
new Position(
source.getLineNumber((int) start) - 1,source.getColumnNumber((int) start,true) - 1),new Position(
source.getLineNumber((int) end) - 1,source.getColumnNumber((int) end,true) - 1));
}
项目:SOMns-vscode
文件:SomLint.java
private static void checkFileNameMatchesModule(final MixinDeFinition def,final String fileName,final List<Diagnostic> diagnostics) {
String moduleName = fileName;
if (moduleName.contains(".")) {
moduleName = moduleName.substring(0,moduleName.indexOf("."));
}
if (!moduleName.equals(def.getName().getString())) {
diagnostics.add(new Diagnostic(
toRange(def.getNameSourceSection()),"Module name '" + def.getName().getString() + "' does not match file name '"
+ fileName
+ "'.",DiagnosticSeverity.information,LINT_NAME));
}
}
项目:SOMns-vscode
文件:SomAdapter.java
private void loadWorkspaceAndLint(final File workspace) {
Map<String,List<Diagnostic>> allDiagnostics = new HashMap<>();
loadFolder(workspace,allDiagnostics);
for (Entry<String,List<Diagnostic>> e : allDiagnostics.entrySet()) {
try {
lintSends(e.getKey(),e.getValue());
} catch (URISyntaxException ex) {
/*
* at this point,there is nothing to be done anymore,* would have been problematic earlier
*/
}
reportDiagnostics(e.getValue(),e.getKey());
}
}
项目:SOMns-vscode
文件:SomAdapter.java
private void loadFolder(final File folder,final Map<String,List<Diagnostic>> allDiagnostics) {
for (File f : folder.listFiles()) {
if (f.isDirectory()) {
loadFolder(f,allDiagnostics);
} else if (f.getName().endsWith(FILE_ENDING)) {
try {
byte[] content = Files.readAllBytes(f.toPath());
String str = new String(content,StandardCharsets.UTF_8);
String uri = f.toURI().toString();
List<Diagnostic> diagnostics = parse(str,uri);
allDiagnostics.put(uri,diagnostics);
} catch (IOException | URISyntaxException e) {
// if loading fails,we don't do anything,just move on to the next file
}
}
}
}
项目:eclipse.jdt.ls
文件:DocumentLifeCycleHandlerTest.java
private void assertNewProblemReported(ExpectedProblemReport... expectedReports) {
List<PublishDiagnosticsParams> diags = getClientRequests("publishDiagnostics");
assertEquals(expectedReports.length,diags.size());
for (int i = 0; i < expectedReports.length; i++) {
PublishDiagnosticsParams diag = diags.get(i);
ExpectedProblemReport expected = expectedReports[i];
assertEquals(JDTUtils.toURI(expected.cu),diag.getUri());
if (expected.problemCount != diag.getDiagnostics().size()) {
String message = "";
for (Diagnostic d : diag.getDiagnostics()) {
message += d.getMessage() + ",";
}
assertEquals(message,expected.problemCount,diag.getDiagnostics().size());
}
}
diags.clear();
}
项目:eclipse.jdt.ls
文件:WorkspaceDiagnosticsHandlerTest.java
@Test
public void testMavenMarkers() throws Exception {
String msg1 = "Some dependency is missing";
IMarker m1 = createMavenMarker(IMarker.SEVERITY_ERROR,msg1,2,95,100);
IDocument d = mock(IDocument.class);
when(d.getLineOffset(1)).thenReturn(90);
List<Diagnostic> diags = handler.toDiagnosticsArray(d,new IMarker[]{m1,null});
assertEquals(1,diags.size());
Range r;
Diagnostic d1 = diags.get(0);
assertEquals(msg1,d1.getMessage());
assertEquals(DiagnosticSeverity.Error,d1.getSeverity());
r = d1.getRange();
assertEquals(1,r.getStart().getLine());
assertEquals(95,r.getStart().getCharacter());
assertEquals(1,r.getEnd().getLine());
assertEquals(100,r.getEnd().getCharacter());
}
项目:xtext-core
文件:ServerTest.java
@Test
public void testinitializeBuildWithError() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Test {");
_builder.newLine();
_builder.append(" ");
_builder.append("NonExisting foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
this.writeFile("MyType1.testlang",_builder);
this.initialize();
Diagnostic _head = IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values()));
String _message = null;
if (_head!=null) {
_message=_head.getMessage();
}
this.assertEquals("Couldn\'t resolve reference to TypeDeclaration \'NonExisting\'.",_message);
Assert.assertEquals(1,IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values())).getRange().getStart().getLine());
Assert.assertEquals(4,IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values())).getRange().getStart().getCharacter());
Assert.assertEquals(1,IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values())).getRange().getEnd().getLine());
Assert.assertEquals(15,IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values())).getRange().getEnd().getCharacter());
}
项目:xtext-core
文件:CodeActionService.java
@Override
public List<? extends Command> getCodeActions(final Document document,final XtextResource resource,final CodeActionParams params,final CancelIndicator indicator) {
final ArrayList<Command> commands = CollectionLiterals.<Command>newArrayList();
List<Diagnostic> _diagnostics = params.getContext().getDiagnostics();
for (final Diagnostic d : _diagnostics) {
String _code = d.getCode();
if (_code != null) {
switch (_code) {
case TestLanguageValidator.INVALID_NAME:
Command _fixInvalidName = this.fixInvalidName(d,document,resource,params);
commands.add(_fixInvalidName);
break;
case TestLanguageValidator.UNSORTED_MEMBERS:
Command _fixUnsortedMembers = this.fixUnsortedMembers(d,params);
commands.add(_fixUnsortedMembers);
break;
}
}
}
return commands;
}
项目:xtext-core
文件:AbstractLanguageServerTest.java
protected Map<String,List<Diagnostic>> getDiagnostics() {
try {
final Function1<CancelIndicator,HashMap<String,List<Diagnostic>>> _function = (CancelIndicator it) -> {
final HashMap<String,List<Diagnostic>> result = CollectionLiterals.<String,List<Diagnostic>>newHashMap();
final Function1<Pair<String,Object>,Object> _function_1 = (Pair<String,Object> it_1) -> {
return it_1.getValue();
};
Iterable<PublishDiagnosticsParams> _filter = Iterables.<PublishDiagnosticsParams>filter(ListExtensions.<Pair<String,Object>map(this.notifications,_function_1),PublishDiagnosticsParams.class);
for (final PublishDiagnosticsParams diagnostic : _filter) {
result.put(diagnostic.getUri(),diagnostic.getDiagnostics());
}
return result;
};
return this.languageServer.getRequestManager().<HashMap<String,List<Diagnostic>>>runRead(_function).get();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
项目:che
文件:PublishDiagnosticsProcessor.java
public void processDiagnostics(ExtendedPublishDiagnosticsParams diagnosticsMessage) {
EditorPartPresenter openedEditor =
editorAgent.getopenedEditor(new Path(diagnosticsMessage.getParams().getUri()));
// Todo add markers
if (openedEditor == null) {
return;
}
if (openedEditor instanceof TextEditor) {
TextEditorConfiguration editorConfiguration = ((TextEditor) openedEditor).getConfiguration();
AnnotationModel annotationModel = editorConfiguration.getAnnotationModel();
if (annotationModel != null && annotationModel instanceof DiagnosticCollector) {
DiagnosticCollector collector = (DiagnosticCollector) annotationModel;
String languageServerId = diagnosticsMessage.getLanguageServerId();
collector.beginReporting(languageServerId);
try {
for (Diagnostic diagnostic : diagnosticsMessage.getParams().getDiagnostics()) {
collector.acceptDiagnostic(languageServerId,diagnostic);
}
} finally {
collector.endReporting(languageServerId);
}
}
}
}
项目:vscode-javac
文件:CodeActions.java
private Stream<Command> codeActionsFor(Diagnostic diagnostic) {
if (diagnostic.getCode().equals("compiler.err.cant.resolve.location")) {
return cannotFindSymbolClassName(diagnostic.getMessage())
.map(Stream::of)
.orElseGet(Stream::empty)
.flatMap(this::addImportActions);
} else return Stream.empty();
}
项目:vscode-javac
文件:Lints.java
private static DiagnosticSeverity severity(javax.tools.Diagnostic.Kind kind) {
switch (kind) {
case ERROR:
return DiagnosticSeverity.Error;
case WARNING:
case MANDATORY_WARNING:
return DiagnosticSeverity.Warning;
case NOTE:
case OTHER:
default:
return DiagnosticSeverity.information;
}
}
项目:SOMns-vscode
文件:SomLanguageServer.java
private void parseDocument(final String documentUri,final String text) {
try {
List<Diagnostic> diagnostics = som.parse(text,documentUri);
som.lintSends(documentUri,diagnostics);
som.reportDiagnostics(diagnostics,documentUri);
} catch (URISyntaxException ex) {
ex.printstacktrace(ServerLauncher.errWriter());
}
}
项目:SOMns-vscode
文件:SomLint.java
public static void checkModuleName(final String filepath,final MixinDeFinition def,final List<Diagnostic> diagnostics) {
File f = new File(filepath);
String name = f.getName();
checkFileEnding(name,diagnostics);
checkFileNameMatchesModule(def,name,diagnostics);
}
项目:SOMns-vscode
文件:SomLint.java
public static void checkSends(final Map<String,SomStructures> structuralProbes,final SomStructures newProbe,final List<Diagnostic> diagnostics) {
Collection<SomStructures> probes;
synchronized (structuralProbes) {
probes = new ArrayList<>(structuralProbes.values());
}
List<Call> calls = newProbe.getCalls();
for (Call c : calls) {
if (newProbe.defines(c.selector)) {
continue;
}
boolean defined = false;
for (SomStructures p : probes) {
if (p.defines(c.selector)) {
defined = true;
break;
}
}
if (!defined) {
Range r = new Range(pos(c.sections[0].getStartLine(),c.sections[0].getStartColumn()),pos(c.sections[c.sections.length - 1].getEndLine(),c.sections[c.sections.length - 1].getEndColumn() + 1));
diagnostics.add(new Diagnostic(r,"No " + c.selector.getString() + " defined. Might cause run time error.",DiagnosticSeverity.Warning,LINT_NAME));
}
}
}
项目:SOMns-vscode
文件:SomAdapter.java
项目:SOMns-vscode
文件:SomAdapter.java
private List<Diagnostic> toDiagnostics(final ParseError e,final List<Diagnostic> diagnostics) {
Diagnostic d = new Diagnostic();
d.setSeverity(DiagnosticSeverity.Error);
SourceCoordinate coord = e.getSourceCoordinate();
d.setRange(toRangeMax(coord));
d.setMessage(e.getMessage());
d.setSource("Parser");
diagnostics.add(d);
return diagnostics;
}
项目:SOMns-vscode
文件:SomAdapter.java
private List<Diagnostic> toDiagnostics(final SemanticDeFinitionError e,final List<Diagnostic> diagnostics) {
SourceSection source = e.getSourceSection();
Diagnostic d = new Diagnostic();
d.setSeverity(DiagnosticSeverity.Error);
d.setRange(toRange(source));
d.setMessage(e.getMessage());
d.setSource("Parser");
diagnostics.add(d);
return diagnostics;
}
项目:SOMns-vscode
文件:SomAdapter.java
private List<Diagnostic> toDiagnostics(final String msg,final List<Diagnostic> diagnostics) {
Diagnostic d = new Diagnostic();
d.setSeverity(DiagnosticSeverity.Error);
d.setMessage(msg);
d.setSource("Parser");
diagnostics.add(d);
return diagnostics;
}
项目:SOMns-vscode
文件:SomAdapter.java
项目:eclipse.jdt.ls
文件:BuildWorkspaceHandler.java
private void publishDiagnostics(List<IMarker> markers) {
Map<IResource,List<IMarker>> map = markers.stream().collect(Collectors.groupingBy(IMarker::getResource));
for (Map.Entry<IResource,List<IMarker>> entry : map.entrySet()) {
IResource resource = entry.getKey();
// ignore problems caused by standalone files
if (JavaLanguageServerPlugin.getProjectsManager().getDefaultProject().equals(resource.getProject())) {
continue;
}
IFile file = resource.getAdapter(IFile.class);
if (file == null) {
continue;
}
IDocument document = null;
String uri = JDTUtils.getFileURI(resource);
if (JavaCore.isJavaLikeFileName(file.getName())) {
Icompilationunit cu = JDTUtils.resolvecompilationunit(uri);
try {
document = JsonRpcHelpers.todocument(cu.getBuffer());
} catch (JavaModelException e) {
logException("Failed to publish diagnostics.",e);
}
}
else if (projectsManager.isBuildFile(file)) {
document = JsonRpcHelpers.todocument(file);
}
if (document != null) {
List<Diagnostic> diagnostics = WorkspaceDiagnosticsHandler.toDiagnosticsArray(document,entry.getValue().toArray(new IMarker[0]));
connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri),diagnostics));
}
}
}
项目:eclipse.jdt.ls
文件:DiagnosticsHandler.java
public static List<Diagnostic> toDiagnosticsArray(List<IProblem> problems) {
List<Diagnostic> array = new ArrayList<>(problems.size());
for (IProblem problem : problems) {
Diagnostic diag = new Diagnostic();
diag.setSource(JavaLanguageServerPlugin.SERVER_SOURCE_ID);
diag.setMessage(problem.getMessage());
diag.setCode(Integer.toString(problem.getID()));
diag.setSeverity(convertSeverity(problem));
diag.setRange(convertRange(problem));
array.add(diag);
}
return array;
}
项目:eclipse.jdt.ls
文件:WorkspaceDiagnosticsHandler.java
/**
* Transforms {@link IMarker}s of a {@link IDocument} into a list of {@link Diagnostic}s.
*
* @param document
* @param markers
* @return a list of {@link Diagnostic}s
*/
public static List<Diagnostic> toDiagnosticsArray(IDocument document,IMarker[] markers) {
List<Diagnostic> diagnostics = Stream.of(markers)
.map(m -> toDiagnostic(document,m))
.filter(d -> d != null)
.collect(Collectors.toList());
return diagnostics;
}
项目:eclipse.jdt.ls
文件:WorkspaceDiagnosticsHandler.java
private static Diagnostic toDiagnostic(IDocument document,IMarker marker) {
if (marker == null || !marker.exists()) {
return null;
}
Diagnostic d = new Diagnostic();
d.setSource(JavaLanguageServerPlugin.SERVER_SOURCE_ID);
d.setMessage(marker.getAttribute(IMarker.MESSAGE,""));
d.setCode(String.valueOf(marker.getAttribute(IJavaModelMarker.ID,0)));
d.setSeverity(convertSeverity(marker.getAttribute(IMarker.SEVERITY,-1)));
d.setRange(convertRange(document,marker));
return d;
}
项目:eclipse.jdt.ls
文件:CodeActionHandler.java
private IProblemLocation[] getProblemLocations(Icompilationunit unit,List<Diagnostic> diagnostics) {
IProblemLocation[] locations = new IProblemLocation[diagnostics.size()];
for (int i = 0; i < diagnostics.size(); i++) {
Diagnostic diagnostic = diagnostics.get(i);
int problemId = getProblemId(diagnostic);
int start = DiagnosticsHelper.getStartOffset(unit,diagnostic.getRange());
int end = DiagnosticsHelper.getEndOffset(unit,diagnostic.getRange());
boolean isError = diagnostic.getSeverity() == DiagnosticSeverity.Error;
locations[i] = new ProblemLocation(start,end - start,problemId,isError);
}
return locations;
}
项目:eclipse.jdt.ls
文件:CodeActionHandler.java
private int getProblemId(Diagnostic diagnostic) {
int $ = 0;
try {
$ = Integer.parseInt(diagnostic.getCode());
} catch (NumberFormatException e) {
// return 0
}
return $;
}
项目:eclipse.jdt.ls
文件:CodeActionHandlerTest.java
private Diagnostic getDiagnostic(String code,Range range){
Diagnostic $ = new Diagnostic();
$.setCode(code);
$.setRange(range);
$.setSeverity(DiagnosticSeverity.Error);
$.setMessage("Test Diagnostic");
return $;
}
项目:eclipse.jdt.ls
文件:DocumentLifeCycleHandlerTest.java
@Test
public void testDidOpenStandaloneFileWithSyntaxError() throws Exception {
IJavaProject javaProject = newDefaultProject();
IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
IPackageFragment pack1 = sourceFolder.createPackageFragment("java",false,null);
// @formatter:off
String standaloneFileContent =
"package java;\n"+
"public class Foo extends UnkNownType {\n"+
" public void method1(){\n"+
" super.whatever()\n"+
" }\n"+
"}";
// @formatter:on
Icompilationunit cu1 = pack1.createcompilationunit("Foo.java",standaloneFileContent,null);
opendocument(cu1,cu1.getSource(),1);
List<PublishDiagnosticsParams> diagnosticReports = getClientRequests("publishDiagnostics");
assertEquals(1,diagnosticReports.size());
PublishDiagnosticsParams diagParam = diagnosticReports.get(0);
assertEquals("Unexpected number of errors " + diagParam.getDiagnostics(),1,diagParam.getDiagnostics().size());
Diagnostic d = diagParam.getDiagnostics().get(0);
assertEquals("Syntax error,insert \";\" to complete BlockStatements",d.getMessage());
assertRange(3,17,18,d.getRange());
}
项目:eclipse.jdt.ls
文件:DocumentLifeCycleHandlerTest.java
@Test
public void testDidOpenStandaloneFileWithNonSyntaxErrors() throws Exception {
IJavaProject javaProject = newDefaultProject();
IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
IPackageFragment pack1 = sourceFolder.createPackageFragment("java",null);
// @formatter:off
String standaloneFileContent =
"package java;\n"+
"public class Foo {\n"+
" public static void notthis(){\n"+
" System.out.println(this);\n"+
" }\n"+
" public void method1(){\n"+
" }\n"+
" public void method1(){\n"+
" }\n"+
"}";
// @formatter:on
Icompilationunit cu1 = pack1.createcompilationunit("Foo.java",diagnosticReports.size());
PublishDiagnosticsParams diagParam = diagnosticReports.get(0);
assertEquals("Unexpected number of errors " + diagParam.getDiagnostics(),3,diagParam.getDiagnostics().size());
Diagnostic d = diagParam.getDiagnostics().get(0);
assertEquals("Cannot use this in a static context",21,25,d.getRange());
d = diagParam.getDiagnostics().get(1);
assertEquals("Duplicate method method1() in type Foo",d.getMessage());
assertRange(5,13,22,d.getRange());
d = diagParam.getDiagnostics().get(2);
assertEquals("Duplicate method method1() in type Foo",d.getMessage());
assertRange(7,d.getRange());
}
项目:eclipse.jdt.ls
文件:WorkspaceDiagnosticsHandlerTest.java
@Test
public void testMarkerListening() throws Exception {
InitHandler initHandler = new InitHandler(projectsManager,preferenceManager,connection);
initHandler.addWorkspaceDiagnosticsHandler();
//import project
importProjects("maven/broken");
ArgumentCaptor<PublishDiagnosticsParams> captor = ArgumentCaptor.forClass(PublishDiagnosticsParams.class);
verify(connection,atLeastOnce()).publishDiagnostics(captor.capture());
List<PublishDiagnosticsParams> allCalls = captor.getAllValues();
Collections.reverse(allCalls);
projectsManager.setConnection(client);
Optional<PublishDiagnosticsParams> fooDiags = allCalls.stream().filter(p -> p.getUri().endsWith("Foo.java")).findFirst();
assertTrue("No Foo.java errors were found",fooDiags.isPresent());
List<Diagnostic> diags = fooDiags.get().getDiagnostics();
Comparator<Diagnostic> comparator = (Diagnostic d1,Diagnostic d2) -> {
int diff = d1.getRange().getStart().getLine() - d2.getRange().getStart().getLine();
if (diff == 0) {
diff = d1.getMessage().compareto(d2.getMessage());
}
return diff;
};
Collections.sort(diags,comparator );
assertEquals(diags.toString(),diags.size());
assertEquals("The import org cannot be resolved",diags.get(0).getMessage());
assertEquals("StringUtils cannot be resolved",diags.get(1).getMessage());
Optional<PublishDiagnosticsParams> pomDiags = allCalls.stream().filter(p -> p.getUri().endsWith("pom.xml")).findFirst();
assertTrue("No pom.xml errors were found",pomDiags.isPresent());
diags = pomDiags.get().getDiagnostics();
Collections.sort(diags,comparator);
assertEquals(diags.toString(),diags.size());
assertTrue(diags.get(0).getMessage()
.startsWith("For artifact {org.apache.commons:commons-lang3:null:jar}: The version cannot be empty. (org.apache.maven.plugins:maven-resources-plugin:2.6:resources:default-resources:process-resources)"));
assertTrue(diags.get(1).getMessage()
.startsWith("For artifact {org.apache.commons:commons-lang3:null:jar}: The version cannot be empty. (org.apache.maven.plugins:maven-resources-plugin:2.6:testResources:default-testResources:process-test-resources)"));
assertEquals("Project build error: 'dependencies.dependency.version' for org.apache.commons:commons-lang3:jar is missing.",diags.get(2).getMessage());
}
项目:xtext-core
文件:opendocumentTest.java
@Test
public void testOpenedDocumentShadowsPersistedFile() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Test {");
_builder.newLine();
_builder.append(" ");
_builder.append("NonExisting foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String firstFile = this.writeFile("MyType1.testlang",_builder);
this.initialize();
this.assertEquals("Couldn\'t resolve reference to TypeDeclaration \'NonExisting\'.",IterableExtensions.<Diagnostic>head(this.getDiagnostics().get(firstFile)).getMessage());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("type Foo {");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
final String path = this.writeFile("MyType2.testlang",_builder_1);
WorkspaceService _workspaceService = this.languageServer.getWorkspaceService();
FileEvent _fileEvent = new FileEvent(path,FileChangeType.Created);
DidChangeWatchedFilesParams _didChangeWatchedFilesParams = new DidChangeWatchedFilesParams(
Collections.<FileEvent>unmodifiableList(CollectionLiterals.<FileEvent>newArrayList(_fileEvent)));
_workspaceService.didChangeWatchedFiles(_didChangeWatchedFilesParams);
this.assertEquals("Couldn\'t resolve reference to TypeDeclaration \'NonExisting\'.",IterableExtensions.<Diagnostic>head(this.getDiagnostics().get(firstFile)).getMessage());
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("type NonExisting {");
_builder_2.newLine();
_builder_2.append("}");
_builder_2.newLine();
this.open(path,_builder_2.toString());
Assert.assertNull(IterableExtensions.<Diagnostic>head(this.getDiagnostics().get(firstFile)));
this.close(path);
this.assertEquals("Couldn\'t resolve reference to TypeDeclaration \'NonExisting\'.",IterableExtensions.<Diagnostic>head(this.getDiagnostics().get(firstFile)).getMessage());
}
项目:xtext-core
文件:ServerTest.java
@Test
public void testinitializeBuild() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Test {");
_builder.newLine();
_builder.append(" ");
_builder.append("string foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
this.writeFile("MyType1.testlang",_builder);
this.initialize();
Assert.assertTrue(IterableExtensions.join(this.getDiagnostics().entrySet(),","),IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values()).isEmpty());
}
项目:xtext-core
文件:ServerTest.java
@Test
public void testIncrementalBuildWithError() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Test {");
_builder.newLine();
_builder.append(" ");
_builder.append("NonExisting foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
this.writeFile("MyType1.testlang",IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values())).getMessage());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("type NonExisting {");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
final String path = this.writeFile("MyType2.testlang",FileChangeType.Created);
DidChangeWatchedFilesParams _didChangeWatchedFilesParams = new DidChangeWatchedFilesParams(Collections.<FileEvent>unmodifiableList(CollectionLiterals.<FileEvent>newArrayList(_fileEvent)));
_workspaceService.didChangeWatchedFiles(_didChangeWatchedFilesParams);
Assert.assertNotNull(this.getDiagnostics().get(path));
final Function1<List<Diagnostic>,Boolean> _function = (List<Diagnostic> it) -> {
return Boolean.valueOf(it.isEmpty());
};
Assert.assertTrue(IterableExtensions.join(this.getDiagnostics().values(),IterableExtensions.<List<Diagnostic>>forall(this.getDiagnostics().values(),_function));
}
项目:che
文件:DiagnosticAnnotation.java
public DiagnosticAnnotation(Diagnostic diagnostic) {
this.diagnostic = diagnostic;
DiagnosticSeverity severity = diagnostic.getSeverity();
if (severity == null) {
layer = ERROR_LAYER;
setType(ERROR_ANNOTATION_TYPE);
} else {
switch (severity) {
case Error:
layer = ERROR_LAYER;
setType(ERROR_ANNOTATION_TYPE);
break;
case Warning:
layer = WARNING_LAYER;
setType(WARNING_ANNOTATION_TYPE);
break;
case information:
layer = INFO_LAYER;
setType(INFO_ANNOTATION_TYPE);
break;
case Hint:
layer = HINT_LAYER;
setType(HINT_ANNOTATION_TYPE);
break;
default:
layer = ERROR_LAYER;
setType(ERROR_ANNOTATION_TYPE);
break;
}
}
}
项目:che
文件:LanguageServerAnnotationModel.java
protected Position createPositionFromDiagnostic(final Diagnostic diagnostic) {
DocumentHandle documentHandle = getDocumentHandle();
Document document = documentHandle.getDocument();
Range range = diagnostic.getRange();
int start =
document.getIndexFromPosition(
new TextPosition(range.getStart().getLine(),range.getStart().getCharacter()));
int end =
document.getIndexFromPosition(
new TextPosition(range.getEnd().getLine(),range.getEnd().getCharacter()));
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;
if (length < 0) {
return null;
}
return new Position(start,length);
}
public void reconcilePath(String fileLocation,String projectPath) {
String fileName = new Path(fileLocation).lastSegment();
if (!POM_FILE_NAME.equals(fileName)) {
return;
}
EditorWorkingcopy workingcopy = editorWorkingcopyManager.getWorkingcopy(fileLocation);
if (workingcopy == null) {
return;
}
String newPomContent = workingcopy.getContentAsstring();
if (isNullOrEmpty(newPomContent)) {
return;
}
List<Problem> problems;
try {
problems = reconcile(fileLocation,projectPath,newPomContent);
List<Diagnostic> diagnostics = convertProblems(newPomContent,problems);
client.publishDiagnostics(
new PublishDiagnosticsParams(LanguageServiceUtils.prefixURI(fileLocation),diagnostics));
} catch (ServerException | NotFoundException e) {
LOG.error(e.getMessage(),e);
client.showMessage(new MessageParams(MessageType.Error,"Error reconciling " + fileLocation));
}
}
public void reconcileUri(String uri,String text) {
try {
String pomPath = LanguageServiceUtils.removePrefixUri(uri);
List<Problem> problems = reconcile(pomPath,new File(pomPath).getParent(),text);
List<Diagnostic> diagnostics = convertProblems(text,problems);
client.publishDiagnostics(new PublishDiagnosticsParams(uri,diagnostics));
} catch (ServerException | NotFoundException e) {
LOG.error("Error reconciling content: " + uri,"Error reconciling " + uri));
}
}
private static List<Diagnostic> convertProblems(String text,List<Problem> problems) {
Map<Integer,Position> positions = mapPositions(text,problems);
List<Diagnostic> diagnostics =
problems
.stream()
.map((Problem p) -> convertProblem(positions,p))
.filter(o -> o != null)
.collect(Collectors.toList());
return diagnostics;
}
private static Diagnostic convertProblem(Map<Integer,Position> positionMap,Problem problem) {
Diagnostic result = new Diagnostic();
Position start = positionMap.get(problem.getSourceStart());
Position end = positionMap.get(problem.getSourceEnd());
if (start == null || end == null) {
LOG.error("Could not map problem range: " + problem);
return null;
}
result.setRange(new Range(start,end));
result.setMessage(problem.getMessage());
result.setSeverity(problem.isError() ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning);
return result;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。