Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Belle2019-03-17 17:44:38 -0400
committerJan Belle2019-03-17 17:58:48 -0400
commit45edc55dc57c577b5cbdcfb9e8c002406e4d2aac (patch)
tree7909f75a9145e72d1018e48882c426ff16af2b22 /plugins
parentb5c3ad1ba11cb5bc9d9ea3d6db7efea17358f617 (diff)
downloadorg.eclipse.etrice-45edc55dc57c577b5cbdcfb9e8c002406e4d2aac.tar.gz
org.eclipse.etrice-45edc55dc57c577b5cbdcfb9e8c002406e4d2aac.tar.xz
org.eclipse.etrice-45edc55dc57c577b5cbdcfb9e8c002406e4d2aac.zip
[core] Improve validation for import statements without uri
* No warning on imports with uri if modelpath isn't present. * Error on imports without uri if modelpath isn't present. Bug 545234 Change-Id: Id13947465abc6b483f3f663326f9ac233c0bd98d
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/ModelPathResourceSetInitializer.java5
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/WorkspaceModelPath.java5
-rw-r--r--plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/validation/BaseJavaValidator.java43
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/FileSystemModelPath.java5
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IModelPath.java12
5 files changed, 55 insertions, 15 deletions
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/ModelPathResourceSetInitializer.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/ModelPathResourceSetInitializer.java
index 964d125e3..d57181620 100644
--- a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/ModelPathResourceSetInitializer.java
+++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/ModelPathResourceSetInitializer.java
@@ -59,5 +59,10 @@ public class ModelPathResourceSetInitializer implements IResourceSetInitializer
public Optional<QualifiedName> getQualifiedName(URI uri) {
return ModelPathManager.INSTANCE.getModelPath(project).getQualifiedName(uri);
}
+
+ @Override
+ public boolean isEmpty() {
+ return ModelPathManager.INSTANCE.getModelPath(project).isEmpty();
+ }
}
}
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/WorkspaceModelPath.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/WorkspaceModelPath.java
index c153186a1..1dd0d496e 100644
--- a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/WorkspaceModelPath.java
+++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/WorkspaceModelPath.java
@@ -75,6 +75,11 @@ public class WorkspaceModelPath implements IModelPath {
return Optional.empty();
}
+ @Override
+ public boolean isEmpty() {
+ return paths.isEmpty();
+ }
+
public List<IContainer> getPaths() {
return paths;
}
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 c85c9c19a..20b8aa2ce 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
@@ -19,7 +19,6 @@ import java.util.HashSet;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
@@ -36,6 +35,8 @@ import org.eclipse.etrice.core.common.base.KeyValue;
import org.eclipse.etrice.core.common.base.RealLiteral;
import org.eclipse.etrice.core.common.base.SimpleAnnotationAttribute;
import org.eclipse.etrice.core.common.base.StringLiteral;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.etrice.generator.base.io.IModelPathProvider;
import org.eclipse.xtext.naming.IQualifiedNameConverter;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.IEObjectDescription;
@@ -64,6 +65,7 @@ public class BaseJavaValidator extends org.eclipse.etrice.core.common.validation
@Inject ImportUriResolver importUriResolver;
@Inject IGlobalScopeProvider globalScopeProvider;
@Inject IQualifiedNameConverter nameConverter;
+ @Inject IModelPathProvider modelPathProvider;
@Check
public void checkDocumentation(Documentation doc) {
@@ -198,7 +200,11 @@ public class BaseJavaValidator extends org.eclipse.etrice.core.common.validation
if(imp.getImportURI() == null) {
return;
}
- warning("import statements using uris are deprecated", BasePackage.Literals.IMPORT__IMPORT_URI, DEPRECATED_IMPORT_URI);
+
+ Resource resource = imp.eResource();
+ if(!modelPathProvider.get(resource).isEmpty()) {
+ warning("import statements using uris are deprecated", BasePackage.Literals.IMPORT__IMPORT_URI, DEPRECATED_IMPORT_URI);
+ }
String uriString = importUriResolver.resolve(imp);
if (uriString == null) {
@@ -208,8 +214,8 @@ public class BaseJavaValidator extends org.eclipse.etrice.core.common.validation
URI uri = URI.createURI(uriString);
- if(imp.eResource().getResourceSet() instanceof ResourceSetImpl) {
- ResourceSetImpl rs = (ResourceSetImpl) imp.eResource().getResourceSet();
+ if(resource.getResourceSet() instanceof ResourceSetImpl) {
+ ResourceSetImpl rs = (ResourceSetImpl) resource.getResourceSet();
if(rs.getURIResourceMap().containsKey(uri)) {
return;
}
@@ -238,17 +244,24 @@ public class BaseJavaValidator extends org.eclipse.etrice.core.common.validation
*/
@Check
public void checkImportedNamespace(Import imp) {
- 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) {
+ 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);
+ }
+ }
}
}
}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/FileSystemModelPath.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/FileSystemModelPath.java
index b087dc788..bb5df0043 100644
--- a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/FileSystemModelPath.java
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/FileSystemModelPath.java
@@ -77,6 +77,11 @@ public class FileSystemModelPath implements IModelPath {
}
@Override
+ public boolean isEmpty() {
+ return paths.isEmpty();
+ }
+
+ @Override
public String toString() {
return paths.toString();
}
diff --git a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IModelPath.java b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IModelPath.java
index ff44f2441..e654ec208 100644
--- a/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IModelPath.java
+++ b/plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IModelPath.java
@@ -48,6 +48,13 @@ public interface IModelPath {
*/
public Optional<QualifiedName> getQualifiedName(URI uri);
+ /**
+ * Checks whether the modelpath is empty.
+ *
+ * @return true if the modelpath is empty.
+ */
+ public boolean isEmpty();
+
static class EmptyModelPath implements IModelPath {
@Override
@@ -64,5 +71,10 @@ public interface IModelPath {
public Optional<QualifiedName> getQualifiedName(URI uri) {
return Optional.empty();
}
+
+ @Override
+ public boolean isEmpty() {
+ return true;
+ }
}
}

Back to the top