-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ui] Print a warning when the errors in the editor and the resources …
…are not the same. see #661 Signed-off-by: Stéphane Galland <galland@arakhne.org>
- Loading branch information
1 parent
b8608b4
commit 56c77ad
Showing
5 changed files
with
229 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
main/coreplugins/io.sarl.lang.ui/src/io/sarl/lang/ui/editor/Messages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* $Id$ | ||
* | ||
* SARL is an general-purpose agent programming language. | ||
* More details on http://www.sarl.io | ||
* | ||
* Copyright (C) 2014-2018 the original authors or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.sarl.lang.ui.editor; | ||
|
||
import org.eclipse.osgi.util.NLS; | ||
|
||
/** Localized Messages. | ||
* @author $Author: sgalland$ | ||
* @version $FullVersion$ | ||
* @mavengroupid $GroupId$ | ||
* @mavenartifactid $ArtifactId$ | ||
* @ExcludeFromApidoc | ||
*/ | ||
@SuppressWarnings("all") | ||
public class Messages extends NLS { | ||
private static final String BUNDLE_NAME = Messages.class.getPackage().getName() + ".messages"; //$NON-NLS-1$ | ||
public static String SARLEditorErrorTickUpdater_0; | ||
static { | ||
// initialize resource bundle | ||
NLS.initializeMessages(BUNDLE_NAME, Messages.class); | ||
} | ||
|
||
private Messages() { | ||
} | ||
} |
172 changes: 172 additions & 0 deletions
172
main/coreplugins/io.sarl.lang.ui/src/io/sarl/lang/ui/editor/SARLEditorErrorTickUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
/* | ||
* $Id$ | ||
* | ||
* SARL is an general-purpose agent programming language. | ||
* More details on http://www.sarl.io | ||
* | ||
* Copyright (C) 2014-2018 the original authors or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.sarl.lang.ui.editor; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.resources.IStorage; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.Status; | ||
import org.eclipse.emf.common.util.URI; | ||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.eclipse.emf.ecore.resource.Resource.Diagnostic; | ||
import org.eclipse.emf.ecore.resource.ResourceSet; | ||
import org.eclipse.jface.text.source.Annotation; | ||
import org.eclipse.jface.text.source.IAnnotationModel; | ||
import org.eclipse.swt.widgets.Display; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.eclipse.xtend.ide.editor.XtendEditorErrorTickUpdater; | ||
import org.eclipse.xtext.ui.editor.XtextEditor; | ||
import org.eclipse.xtext.ui.resource.IResourceSetProvider; | ||
import org.eclipse.xtext.ui.resource.IStorage2UriMapper; | ||
import org.eclipse.xtext.xbase.lib.util.ReflectExtensions; | ||
|
||
import io.sarl.lang.ui.internal.LangActivator; | ||
|
||
/** Updater of the error ticks into the SARL editor. | ||
* | ||
* @author $Author: sgalland$ | ||
* @version $FullVersion$ | ||
* @mavengroupid $GroupId$ | ||
* @mavenartifactid $ArtifactId$ | ||
* @since 0.8.6 | ||
*/ | ||
public class SARLEditorErrorTickUpdater extends XtendEditorErrorTickUpdater { | ||
|
||
private static final String MARKER_TYPE = "org.eclipse.xtext.ui.editor.error"; //$NON-NLS-1$ | ||
|
||
@Inject | ||
private IResourceSetProvider resourceSetProvider; | ||
|
||
@Inject | ||
private IStorage2UriMapper uriMapper; | ||
|
||
@Inject | ||
private ReflectExtensions reflect; | ||
|
||
/** | ||
* Replies the editor that is linked to this updater. | ||
* | ||
* @return the linked editor, or {@code null} if no editor was linked. | ||
*/ | ||
protected XtextEditor getEditor() { | ||
// FIXME: Remove when Xbase is fixed. | ||
try { | ||
return (XtextEditor) this.reflect.get(this, "editor"); //$NON-NLS-1$ | ||
} catch (Exception exception) { | ||
throw new RuntimeException(exception); | ||
} | ||
} | ||
|
||
/** | ||
* Replies the current Xtext document that is supported by the linked editor. | ||
* | ||
* @return the Xtext document, or {@code null} if neither an editor nor a | ||
* Xtext document was linked. | ||
*/ | ||
protected Resource getXtextResource() { | ||
//FIXME: for helping to resolve #661 | ||
final XtextEditor editor = getEditor(); | ||
if (editor != null) { | ||
final IResource resource = editor.getResource(); | ||
if (resource instanceof IStorage) { | ||
final IProject project = resource.getProject(); | ||
if (project != null) { | ||
final ResourceSet resourceSet = this.resourceSetProvider.get(project); | ||
assert resourceSet != null; | ||
final URI uri = this.uriMapper.getUri((IStorage) resource); | ||
return resourceSet.getResource(uri, true); | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("checkstyle:nestedifdepth") | ||
public void modelChanged(IAnnotationModel model) { | ||
super.modelChanged(model); | ||
//FIXME: for helping to resolve #661 | ||
final XtextEditor editor = getEditor(); | ||
if (editor != null && editor.getInternalSourceViewer() != null) { | ||
final IAnnotationModel currentModel = editor.getInternalSourceViewer().getAnnotationModel(); | ||
if (currentModel != null && currentModel == model) { | ||
final Resource resource = getXtextResource(); | ||
if (isReconciliable(resource)) { | ||
final Set<String> markers = extractErrorMarkerMessages(currentModel); | ||
final List<Diagnostic> resourceErrors = resource.getErrors(); | ||
if (markers.size() != resourceErrors.size() || notSame(markers, resourceErrors)) { | ||
final Display display = PlatformUI.getWorkbench().getDisplay(); | ||
display.asyncExec(new Runnable() { | ||
@Override | ||
public void run() { | ||
LangActivator.getInstance().getLog().log( | ||
new Status(IStatus.ERROR, LangActivator.PLUGIN_ID, | ||
MessageFormat.format(Messages.SARLEditorErrorTickUpdater_0, resource.getURI()))); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static boolean isReconciliable(Resource resource) { | ||
//FIXME: for helping to resolve #661 | ||
if (resource != null) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
private static boolean notSame(Set<String> markers, List<Diagnostic> diagnostics) { | ||
//FIXME: for helping to resolve #661 | ||
for (final Diagnostic diag : diagnostics) { | ||
if (!markers.contains(diag.getMessage())) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private static Set<String> extractErrorMarkerMessages(IAnnotationModel currentModel) { | ||
//FIXME: for helping to resolve #661 | ||
final Iterator<Annotation> annotations = currentModel.getAnnotationIterator(); | ||
final Set<String> errors = new TreeSet<>(); | ||
while (annotations.hasNext()) { | ||
final Annotation annotation = annotations.next(); | ||
if (!annotation.isMarkedDeleted() && MARKER_TYPE.equals(annotation.getType())) { | ||
errors.add(annotation.getText()); | ||
} | ||
} | ||
return errors; | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
main/coreplugins/io.sarl.lang.ui/src/io/sarl/lang/ui/editor/messages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SARLEditorErrorTickUpdater_0=Possible inconsistency problem between the editor and the resource {0}. Reconciliation of the editor is forced. |