Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Belle2019-04-02 17:29:18 -0400
committerJan Belle2019-04-02 17:29:18 -0400
commit8fb6b0acddb70a0d67f8a215466ca0bb922c7674 (patch)
tree516891b724f5c08fd9823b472d396af1840552eb /plugins
parent07bedae0385d5e2ec7bc474f585dd735ca38a71a (diff)
downloadorg.eclipse.etrice-8fb6b0acddb70a0d67f8a215466ca0bb922c7674.tar.gz
org.eclipse.etrice-8fb6b0acddb70a0d67f8a215466ca0bb922c7674.tar.xz
org.eclipse.etrice-8fb6b0acddb70a0d67f8a215466ca0bb922c7674.zip
[common.ui] Provide quickfixes for modelpath editing
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/quickfix/BaseQuickfixProvider.xtend38
-rw-r--r--plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/validation/BaseJavaValidator.java46
2 files changed, 64 insertions, 20 deletions
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/quickfix/BaseQuickfixProvider.xtend b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/quickfix/BaseQuickfixProvider.xtend
index 29de662ce..6e0a3af65 100644
--- a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/quickfix/BaseQuickfixProvider.xtend
+++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/quickfix/BaseQuickfixProvider.xtend
@@ -19,6 +19,12 @@ import org.eclipse.etrice.core.common.validation.BaseJavaValidator
import org.eclipse.xtext.validation.Issue
import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor
import org.eclipse.etrice.core.common.base.Import
+import org.eclipse.core.resources.ResourcesPlugin
+import org.eclipse.core.runtime.Path
+import org.eclipse.etrice.core.common.ui.modelpath.ModelPathManager
+import org.eclipse.ui.PlatformUI
+import org.eclipse.ui.ide.IDE
+import org.eclipse.xtext.util.StringInputStream
//import org.eclipse.xtext.ui.editor.quickfix.Fix
//import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor
@@ -38,6 +44,38 @@ class BaseQuickfixProvider extends DefaultQuickfixProvider {
imp.importURI = null
]
}
+
+ @Fix(BaseJavaValidator.MODELPATH_DESCRIPTION_MISSING)
+ @Fix(BaseJavaValidator.IMPORTED_NAMESPACE_MISSING)
+ def editModelpathDescription(Issue issue, IssueResolutionAcceptor acceptor) {
+ val resourceUri = issue.uriToProblem.trimFragment
+ if(resourceUri.platform) {
+ val path = new Path(resourceUri.toPlatformString(true))
+ val project = ResourcesPlugin.workspace.root.getFile(path).project
+ val file = project.getFile(ModelPathManager.MODELPATH_FILE)
+ if(!file.exists) {
+ acceptor.accept(issue, "Create modelpath description", "Create modelpath description file", null) [
+ val input = new StringInputStream('''
+ // modelpath description
+
+ // HOWTO define source directory
+ // srcDir <directory path>
+
+ // HOWTO define project dependency
+ // project <project name>
+ ''')
+ file.create(input, false, null);
+ IDE.openEditor(PlatformUI.workbench.activeWorkbenchWindow.activePage, file)
+ ]
+ }
+ else {
+ acceptor.accept(issue, "Edit modelpath description", "Edit modelpath description file to configure modelpath definitions", null) [
+ IDE.openEditor(PlatformUI.workbench.activeWorkbenchWindow.activePage, file)
+ ]
+ }
+
+ }
+ }
// @Fix(MyDslValidator::INVALID_NAME)
// def capitalizeName(Issue issue, IssueResolutionAcceptor acceptor) {
diff --git a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/validation/BaseJavaValidator.java b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/validation/BaseJavaValidator.java
index 20b8aa2ce..892a124c0 100644
--- a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/validation/BaseJavaValidator.java
+++ b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/validation/BaseJavaValidator.java
@@ -61,6 +61,8 @@ public class BaseJavaValidator extends org.eclipse.etrice.core.common.validation
public static final String UNDEFINED_ANNOTATION_ATTRIBUTE_VALUE = "BaseJavaValidator.UndfinedAnnotationAttributeValue";
public static final String DUPLICATE_ANNOTATION_ATTRIBUTE = "BaseJavaValidator.DuplicateAnnotationAttribute";
public static final String DEPRECATED_IMPORT_URI = "BaseJavaValidator.DeprecatedImportUri";
+ public static final String MODELPATH_DESCRIPTION_MISSING = "BaseJavaValidator.ModelpathDescriptionMissing";
+ public static final String IMPORTED_NAMESPACE_MISSING = "BaseJavaValidator.ImportedNamespaceMissing";
@Inject ImportUriResolver importUriResolver;
@Inject IGlobalScopeProvider globalScopeProvider;
@@ -244,26 +246,30 @@ public class BaseJavaValidator extends org.eclipse.etrice.core.common.validation
*/
@Check
public void checkImportedNamespace(Import imp) {
- if(imp.getImportURI() == null) {
- if(modelPathProvider.get(imp.eResource()).isEmpty()) {
- error("no modelpath definition present", BasePackage.Literals.IMPORT__IMPORTED_NAMESPACE);
- }
- else {
- String name = imp.getImportedNamespace();
- if(name != null) {
- QualifiedName importedNamespace = nameConverter.toQualifiedName(name);
- if(!importedNamespace.getLastSegment().equals("*")) {
- Resource context = imp.eResource();
- EReference reference = EcoreFactory.eINSTANCE.createEReference();
- reference.setEType(EcorePackage.eINSTANCE.getEObject());
- IScope scope = globalScopeProvider.getScope(context, reference, Predicates.alwaysTrue());
- IEObjectDescription eod = scope.getSingleElement(importedNamespace);
- if(eod == null) {
- error("could not find imported namespace " + importedNamespace, BasePackage.Literals.IMPORT__IMPORTED_NAMESPACE);
- }
- }
- }
- }
+ if(imp.getImportURI() != null) {
+ return;
+ }
+
+ String name = imp.getImportedNamespace();
+ if(name == null) {
+ return;
+ }
+ Resource resource = imp.eResource();
+ if(modelPathProvider.get(resource).isEmpty()) {
+ error("no modelpath definition present", BasePackage.Literals.IMPORT__IMPORTED_NAMESPACE, MODELPATH_DESCRIPTION_MISSING);
+ return;
+ }
+ QualifiedName importedNamespace = nameConverter.toQualifiedName(name);
+ if(importedNamespace.getLastSegment().equals("*")) {
+ return;
+ }
+
+ EReference reference = EcoreFactory.eINSTANCE.createEReference();
+ reference.setEType(EcorePackage.eINSTANCE.getEObject());
+ IScope scope = globalScopeProvider.getScope(resource, reference, Predicates.alwaysTrue());
+ IEObjectDescription eod = scope.getSingleElement(importedNamespace);
+ if(eod == null) {
+ error("could not find imported namespace " + importedNamespace, BasePackage.Literals.IMPORT__IMPORTED_NAMESPACE, IMPORTED_NAMESPACE_MISSING);
}
}
}

Back to the top