From 8fb6b0acddb70a0d67f8a215466ca0bb922c7674 Mon Sep 17 00:00:00 2001 From: Jan Belle Date: Tue, 2 Apr 2019 23:29:18 +0200 Subject: [common.ui] Provide quickfixes for modelpath editing Change-Id: I62a98379ce13c298bbf679d4b0560f719c29257a --- .../common/ui/quickfix/BaseQuickfixProvider.xtend | 38 ++++++++++++++++++ .../core/common/validation/BaseJavaValidator.java | 46 ++++++++++++---------- 2 files changed, 64 insertions(+), 20 deletions(-) (limited to 'plugins') 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 + + // HOWTO define project dependency + // project + ''') + 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); } } } -- cgit v1.2.3