Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/org.eclipse.etrice.template.c/build.gradle2
-rw-r--r--examples/org.eclipse.etrice.template.c/generate_Template.launch4
-rw-r--r--examples/org.eclipse.etrice.template.c/model/TemplateMapping.etmap (renamed from examples/org.eclipse.etrice.template.c/model/Mapping.etmap)0
-rw-r--r--examples/org.eclipse.etrice.template.c/model/TemplatePhysical.etphys (renamed from examples/org.eclipse.etrice.template.c/model/Physical.etphys)0
-rw-r--r--examples/org.eclipse.etrice.template.cpp/build.gradle2
-rw-r--r--examples/org.eclipse.etrice.template.cpp/generate_Template.launch4
-rw-r--r--examples/org.eclipse.etrice.template.cpp/model/TemplateMapping.etmap (renamed from examples/org.eclipse.etrice.template.cpp/model/Mapping.etmap)0
-rw-r--r--examples/org.eclipse.etrice.template.cpp/model/TemplatePhysical.etphys (renamed from examples/org.eclipse.etrice.template.cpp/model/Physical.etphys)0
-rw-r--r--examples/org.eclipse.etrice.tutorials.c/model/HelloWorld/Mapping.etmap2
-rw-r--r--examples/org.eclipse.etrice.tutorials.c/model/HelloWorld/Physical.etphys2
-rw-r--r--examples/org.eclipse.etrice.tutorials.c/model/PingPong/Mapping.etmap2
-rw-r--r--examples/org.eclipse.etrice.tutorials.c/model/PingPong/Physical.etphys2
-rw-r--r--examples/org.eclipse.etrice.tutorials.cpp/model/HelloWorld/Mapping.etmap2
-rw-r--r--examples/org.eclipse.etrice.tutorials.cpp/model/HelloWorld/Physical.etphys2
-rw-r--r--examples/org.eclipse.etrice.tutorials.cpp/model/PingPong/Mapping.etmap2
-rw-r--r--examples/org.eclipse.etrice.tutorials.cpp/model/PingPong/Physical.etphys2
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/ModelPathResourceSetInitializer.java4
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/WorkspaceModelPath.java56
-rw-r--r--plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/base/util/ImportHelpers.java3
-rw-r--r--plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/scoping/ModelPathFileExtensionFilter.java10
-rw-r--r--plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/scoping/ModelPathGlobalScopeProvider.java98
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/RoomJavaValidator.java2
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/FileSystemModelPath.java54
-rw-r--r--plugins/org.eclipse.etrice.generator.base/src/org/eclipse/etrice/generator/base/io/IModelPath.java50
24 files changed, 169 insertions, 136 deletions
diff --git a/examples/org.eclipse.etrice.template.c/build.gradle b/examples/org.eclipse.etrice.template.c/build.gradle
index 9d65f8813..5a470ddb8 100644
--- a/examples/org.eclipse.etrice.template.c/build.gradle
+++ b/examples/org.eclipse.etrice.template.c/build.gradle
@@ -6,7 +6,7 @@ dependencies {
}
def models = [
- 'model/Mapping.etmap',
+ 'model/TemplateMapping.etmap',
'model/TemplateModel.room'
]
diff --git a/examples/org.eclipse.etrice.template.c/generate_Template.launch b/examples/org.eclipse.etrice.template.c/generate_Template.launch
index e71340b22..e81b235db 100644
--- a/examples/org.eclipse.etrice.template.c/generate_Template.launch
+++ b/examples/org.eclipse.etrice.template.c/generate_Template.launch
@@ -10,9 +10,9 @@
<booleanAttribute key="MSC" value="true"/>
<stringAttribute key="MainMethodName" value="main"/>
<listAttribute key="ModelFiles">
+<listEntry value="${workspace_loc:/org.eclipse.etrice.template.c/model/TemplateMapping.etmap}"/>
<listEntry value="${workspace_loc:/org.eclipse.etrice.template.c/model/TemplateModel.room}"/>
-<listEntry value="${workspace_loc:/org.eclipse.etrice.template.c/model/Physical.etphys}"/>
-<listEntry value="${workspace_loc:/org.eclipse.etrice.template.c/model/Mapping.etmap}"/>
+<listEntry value="${workspace_loc:/org.eclipse.etrice.template.c/model/TemplatePhysical.etphys}"/>
</listAttribute>
<booleanAttribute key="OldStyleTransitionData" value="false"/>
<booleanAttribute key="OverrideDirectories" value="false"/>
diff --git a/examples/org.eclipse.etrice.template.c/model/Mapping.etmap b/examples/org.eclipse.etrice.template.c/model/TemplateMapping.etmap
index 814d5a38d..814d5a38d 100644
--- a/examples/org.eclipse.etrice.template.c/model/Mapping.etmap
+++ b/examples/org.eclipse.etrice.template.c/model/TemplateMapping.etmap
diff --git a/examples/org.eclipse.etrice.template.c/model/Physical.etphys b/examples/org.eclipse.etrice.template.c/model/TemplatePhysical.etphys
index 2bf93c456..2bf93c456 100644
--- a/examples/org.eclipse.etrice.template.c/model/Physical.etphys
+++ b/examples/org.eclipse.etrice.template.c/model/TemplatePhysical.etphys
diff --git a/examples/org.eclipse.etrice.template.cpp/build.gradle b/examples/org.eclipse.etrice.template.cpp/build.gradle
index f949de376..c7a8dea00 100644
--- a/examples/org.eclipse.etrice.template.cpp/build.gradle
+++ b/examples/org.eclipse.etrice.template.cpp/build.gradle
@@ -6,7 +6,7 @@ dependencies {
}
def models = [
- 'model/Mapping.etmap',
+ 'model/TemplateMapping.etmap',
'model/TemplateModel.room'
]
diff --git a/examples/org.eclipse.etrice.template.cpp/generate_Template.launch b/examples/org.eclipse.etrice.template.cpp/generate_Template.launch
index d245262a9..918b58dbe 100644
--- a/examples/org.eclipse.etrice.template.cpp/generate_Template.launch
+++ b/examples/org.eclipse.etrice.template.cpp/generate_Template.launch
@@ -10,9 +10,9 @@
<booleanAttribute key="MSC" value="true"/>
<stringAttribute key="MainMethodName" value="main"/>
<listAttribute key="ModelFiles">
+<listEntry value="${workspace_loc:/org.eclipse.etrice.template.cpp/model/TemplateMapping.etmap}"/>
<listEntry value="${workspace_loc:/org.eclipse.etrice.template.cpp/model/TemplateModel.room}"/>
-<listEntry value="${workspace_loc:/org.eclipse.etrice.template.cpp/model/Physical.etphys}"/>
-<listEntry value="${workspace_loc:/org.eclipse.etrice.template.cpp/model/Mapping.etmap}"/>
+<listEntry value="${workspace_loc:/org.eclipse.etrice.template.cpp/model/TemplatePhysical.etphys}"/>
</listAttribute>
<booleanAttribute key="OldStyleTransitionData" value="false"/>
<booleanAttribute key="OverrideDirectories" value="false"/>
diff --git a/examples/org.eclipse.etrice.template.cpp/model/Mapping.etmap b/examples/org.eclipse.etrice.template.cpp/model/TemplateMapping.etmap
index 814d5a38d..814d5a38d 100644
--- a/examples/org.eclipse.etrice.template.cpp/model/Mapping.etmap
+++ b/examples/org.eclipse.etrice.template.cpp/model/TemplateMapping.etmap
diff --git a/examples/org.eclipse.etrice.template.cpp/model/Physical.etphys b/examples/org.eclipse.etrice.template.cpp/model/TemplatePhysical.etphys
index 2bf93c456..2bf93c456 100644
--- a/examples/org.eclipse.etrice.template.cpp/model/Physical.etphys
+++ b/examples/org.eclipse.etrice.template.cpp/model/TemplatePhysical.etphys
diff --git a/examples/org.eclipse.etrice.tutorials.c/model/HelloWorld/Mapping.etmap b/examples/org.eclipse.etrice.tutorials.c/model/HelloWorld/Mapping.etmap
index 087453f68..75a57085b 100644
--- a/examples/org.eclipse.etrice.tutorials.c/model/HelloWorld/Mapping.etmap
+++ b/examples/org.eclipse.etrice.tutorials.c/model/HelloWorld/Mapping.etmap
@@ -5,7 +5,7 @@
*/
MappingModel TemplateMapping {
- import TemplatePhysical.TemplatePhysicalSystem
+ import Physical.TemplatePhysicalSystem
import HelloWorld.LogSys
Mapping LogSys -> TemplatePhysicalSystem {
diff --git a/examples/org.eclipse.etrice.tutorials.c/model/HelloWorld/Physical.etphys b/examples/org.eclipse.etrice.tutorials.c/model/HelloWorld/Physical.etphys
index 2bf93c456..83c6c4460 100644
--- a/examples/org.eclipse.etrice.tutorials.c/model/HelloWorld/Physical.etphys
+++ b/examples/org.eclipse.etrice.tutorials.c/model/HelloWorld/Physical.etphys
@@ -1,4 +1,4 @@
-PhysicalModel TemplatePhysical {
+PhysicalModel Physical {
PhysicalSystem TemplatePhysicalSystem {
NodeRef node : DefaultNodeClass
diff --git a/examples/org.eclipse.etrice.tutorials.c/model/PingPong/Mapping.etmap b/examples/org.eclipse.etrice.tutorials.c/model/PingPong/Mapping.etmap
index a19b9d930..570a824ea 100644
--- a/examples/org.eclipse.etrice.tutorials.c/model/PingPong/Mapping.etmap
+++ b/examples/org.eclipse.etrice.tutorials.c/model/PingPong/Mapping.etmap
@@ -5,7 +5,7 @@
*/
MappingModel TemplateMapping {
- import TemplatePhysical.TemplatePhysicalSystem
+ import Physical.TemplatePhysicalSystem
import PingPong.LogSys
Mapping LogSys -> TemplatePhysicalSystem {
diff --git a/examples/org.eclipse.etrice.tutorials.c/model/PingPong/Physical.etphys b/examples/org.eclipse.etrice.tutorials.c/model/PingPong/Physical.etphys
index 2bf93c456..83c6c4460 100644
--- a/examples/org.eclipse.etrice.tutorials.c/model/PingPong/Physical.etphys
+++ b/examples/org.eclipse.etrice.tutorials.c/model/PingPong/Physical.etphys
@@ -1,4 +1,4 @@
-PhysicalModel TemplatePhysical {
+PhysicalModel Physical {
PhysicalSystem TemplatePhysicalSystem {
NodeRef node : DefaultNodeClass
diff --git a/examples/org.eclipse.etrice.tutorials.cpp/model/HelloWorld/Mapping.etmap b/examples/org.eclipse.etrice.tutorials.cpp/model/HelloWorld/Mapping.etmap
index 087453f68..75a57085b 100644
--- a/examples/org.eclipse.etrice.tutorials.cpp/model/HelloWorld/Mapping.etmap
+++ b/examples/org.eclipse.etrice.tutorials.cpp/model/HelloWorld/Mapping.etmap
@@ -5,7 +5,7 @@
*/
MappingModel TemplateMapping {
- import TemplatePhysical.TemplatePhysicalSystem
+ import Physical.TemplatePhysicalSystem
import HelloWorld.LogSys
Mapping LogSys -> TemplatePhysicalSystem {
diff --git a/examples/org.eclipse.etrice.tutorials.cpp/model/HelloWorld/Physical.etphys b/examples/org.eclipse.etrice.tutorials.cpp/model/HelloWorld/Physical.etphys
index 2bf93c456..83c6c4460 100644
--- a/examples/org.eclipse.etrice.tutorials.cpp/model/HelloWorld/Physical.etphys
+++ b/examples/org.eclipse.etrice.tutorials.cpp/model/HelloWorld/Physical.etphys
@@ -1,4 +1,4 @@
-PhysicalModel TemplatePhysical {
+PhysicalModel Physical {
PhysicalSystem TemplatePhysicalSystem {
NodeRef node : DefaultNodeClass
diff --git a/examples/org.eclipse.etrice.tutorials.cpp/model/PingPong/Mapping.etmap b/examples/org.eclipse.etrice.tutorials.cpp/model/PingPong/Mapping.etmap
index a19b9d930..570a824ea 100644
--- a/examples/org.eclipse.etrice.tutorials.cpp/model/PingPong/Mapping.etmap
+++ b/examples/org.eclipse.etrice.tutorials.cpp/model/PingPong/Mapping.etmap
@@ -5,7 +5,7 @@
*/
MappingModel TemplateMapping {
- import TemplatePhysical.TemplatePhysicalSystem
+ import Physical.TemplatePhysicalSystem
import PingPong.LogSys
Mapping LogSys -> TemplatePhysicalSystem {
diff --git a/examples/org.eclipse.etrice.tutorials.cpp/model/PingPong/Physical.etphys b/examples/org.eclipse.etrice.tutorials.cpp/model/PingPong/Physical.etphys
index 2bf93c456..83c6c4460 100644
--- a/examples/org.eclipse.etrice.tutorials.cpp/model/PingPong/Physical.etphys
+++ b/examples/org.eclipse.etrice.tutorials.cpp/model/PingPong/Physical.etphys
@@ -1,4 +1,4 @@
-PhysicalModel TemplatePhysical {
+PhysicalModel Physical {
PhysicalSystem TemplatePhysicalSystem {
NodeRef node : DefaultNodeClass
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 21803f6bf..752887798 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
@@ -48,12 +48,12 @@ public class ModelPathResourceSetInitializer implements IResourceSetInitializer
}
@Override
- public Stream<URI> getFiles(QualifiedName name) {
+ public Stream<ModelFile> getFiles(QualifiedName name) {
return ModelPathManager.INSTANCE.getModelPath(project).getFiles(name);
}
@Override
- public Stream<URI> getAllFiles() {
+ public Stream<ModelFile> getAllFiles() {
return ModelPathManager.INSTANCE.getModelPath(project).getAllFiles();
}
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 1dd0d496e..58c0a3af1 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
@@ -39,27 +39,25 @@ public class WorkspaceModelPath implements IModelPath {
/**
* Constructs a new modelpath.
*
- * @param paths the paths to seach for model files
+ * @param paths the paths to search for model files
*/
public WorkspaceModelPath(List<IContainer> paths) {
this.paths = paths;
}
@Override
- public Stream<URI> getFiles(QualifiedName name) {
- Stream<URI> stream = Stream.empty();
- while(!name.isEmpty()) {
- name = name.skipLast(1);
- stream = Stream.concat(stream, getPackage(name));
- }
- return stream;
+ public Stream<ModelFile> getFiles(QualifiedName name) {
+ QualifiedName pkgName = name.skipLast(1);
+ String fileName = name.getLastSegment();
+ return getPackage(pkgName)
+ .filter(mf -> mf.name.getLastSegment().equals(fileName));
}
@Override
- public Stream<URI> getAllFiles() {
+ public Stream<ModelFile> getAllFiles() {
return paths.stream()
.filter(container -> container.isAccessible())
- .flatMap(container -> getAllFiles(container));
+ .flatMap(container -> listAllFiles(container, QualifiedName.EMPTY));
}
@Override
@@ -90,60 +88,64 @@ public class WorkspaceModelPath implements IModelPath {
}
/**
- * Constructrs a stream of file contained in the specified package.
+ * Constructs a stream of files contained in the specified package.
*
* @param name the fully qualified name of the package
- * @return a stream of file uris
+ * @return a stream of files
*/
- private Stream<URI> getPackage(QualifiedName name) {
- String pathStr = name.toString().replace('.', '/');
- Path path = new Path(pathStr);
+ private Stream<ModelFile> getPackage(QualifiedName name) {
+ Path path = new Path(name.toString("/"));
return paths.stream()
.map(container -> container.getFolder(path))
.filter(folder -> folder.exists())
- .flatMap(folder -> getFiles(folder));
+ .flatMap(folder -> listFiles(folder, name));
}
/**
* Constructs a stream of files contained in the specified container.
*
* @param container the container to be searched for files
+ * @param name the qualified name of the container
* @return a stream of file uris
*/
- private Stream<URI> getFiles(IContainer container) {
+ private Stream<ModelFile> listFiles(IContainer container, QualifiedName name) {
return getMembers(container)
.filter(resource -> resource.getType() == IResource.FILE)
- .map(IFile.class::cast)
- .map(file -> createURI(file));
+ .map(file -> createModelFile((IFile) file, name));
}
/**
* Constructs a stream that contains all files in the container including files of subfolders.
*
* @param container the container to be searched for files
+ * @param name the qualified name of the container
* @return a stream of file uris
*/
- private Stream<URI> getAllFiles(IContainer container) {
+ private Stream<ModelFile> listAllFiles(IContainer container, QualifiedName name) {
return getMembers(container)
.flatMap(resource -> {
if(resource.getType() == IResource.FILE) {
- IFile file = (IFile) resource;
- URI uri = createURI(file);
- return Stream.of(uri);
+ return Stream.of(createModelFile((IFile) resource, name));
}
else if(resource.getType() == IResource.FOLDER) {
IFolder subfolder = (IFolder) resource;
- return getAllFiles(subfolder);
+ return listAllFiles(subfolder, name.append(subfolder.getName()));
}
return Stream.empty();
});
}
/**
- * Creates an uri for the passed file.
+ * Creates a model file from an eclipse file and the name of the package.
+ *
+ * @param file the eclipse file
+ * @param pkg the qualified name of the package
+ * @return the new model file
*/
- private URI createURI(IResource resource) {
- return URI.createPlatformResourceURI(resource.getFullPath().toString(), true);
+ private ModelFile createModelFile(IFile file, QualifiedName pkg) {
+ URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
+ String fileName = file.getName();
+ return ModelFile.create(uri, pkg, fileName);
}
/**
diff --git a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/base/util/ImportHelpers.java b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/base/util/ImportHelpers.java
index 87f6da735..c6e5625c3 100644
--- a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/base/util/ImportHelpers.java
+++ b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/base/util/ImportHelpers.java
@@ -179,9 +179,6 @@ public class ImportHelpers {
IScope scope = getVisibleScope(resource, type);
scope.getAllElements().forEach((eObjDesc) -> {
if(eObjDesc.getName().getLastSegment().equalsIgnoreCase(issueString)) {
- // - Bug 549427 - hide element that cannot be resolved (why is it here?)
- if(scope.getSingleElement(eObjDesc.getName()) == null) return;
- // -
Import imp = BaseFactory.eINSTANCE.createImport();
imp.setImportedNamespace((wildcard) ? eObjDesc.getQualifiedName().skipLast(1) + ".*" : eObjDesc.getQualifiedName().toString());
result.add(imp);
diff --git a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/scoping/ModelPathFileExtensionFilter.java b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/scoping/ModelPathFileExtensionFilter.java
index b6899729d..47c3aeee2 100644
--- a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/scoping/ModelPathFileExtensionFilter.java
+++ b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/scoping/ModelPathFileExtensionFilter.java
@@ -16,8 +16,8 @@ package org.eclipse.etrice.core.common.scoping;
import java.util.Arrays;
-import org.eclipse.emf.common.util.URI;
import org.eclipse.etrice.core.common.scoping.ModelPathGlobalScopeProvider.IModelPathFileFilter;
+import org.eclipse.etrice.generator.base.io.IModelPath.ModelFile;
/**
* Filters the model path by file extension.
@@ -37,12 +37,8 @@ public class ModelPathFileExtensionFilter implements IModelPathFileFilter {
}
@Override
- public boolean apply(URI uri) {
- String fileExtension = uri.fileExtension();
- if(fileExtension != null) {
- return Arrays.binarySearch(legalFileExtensions, fileExtension) >= 0;
- }
- return false;
+ public boolean apply(ModelFile file) {
+ return Arrays.binarySearch(legalFileExtensions, file.extension) >= 0;
}
}
diff --git a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/scoping/ModelPathGlobalScopeProvider.java b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/scoping/ModelPathGlobalScopeProvider.java
index c2555c368..c35d7f337 100644
--- a/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/scoping/ModelPathGlobalScopeProvider.java
+++ b/plugins/org.eclipse.etrice.core.common/src/org/eclipse/etrice/core/common/scoping/ModelPathGlobalScopeProvider.java
@@ -15,10 +15,11 @@
package org.eclipse.etrice.core.common.scoping;
-import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import java.util.stream.Stream.Builder;
import java.util.stream.StreamSupport;
+
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
@@ -26,6 +27,7 @@ import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.etrice.generator.base.io.IModelPath;
+import org.eclipse.etrice.generator.base.io.IModelPath.ModelFile;
import org.eclipse.etrice.generator.base.io.IModelPathProvider;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.naming.QualifiedName;
@@ -50,7 +52,7 @@ public class ModelPathGlobalScopeProvider extends AbstractGlobalScopeProvider {
* Filters the model files.
*/
@FunctionalInterface
- public static interface IModelPathFileFilter extends Predicate<URI> {}
+ public static interface IModelPathFileFilter extends Predicate<ModelFile> {}
private IModelPathProvider modelPathProvider;
private IQualifiedNameProvider qualifiedNameProvider;
@@ -98,53 +100,59 @@ public class ModelPathGlobalScopeProvider extends AbstractGlobalScopeProvider {
@Override
protected IEObjectDescription getSingleLocalElementByName(QualifiedName name) {
- Stream<IResourceDescription> resourceDescriptions = getResourceDescriptionsByName(name);
- return getExportedObjectsByName(resourceDescriptions, name).findFirst().orElse(null);
+ return getResourceDescriptionsByName(name)
+ .flatMap(fdp -> getExportedObjectsByName(fdp, name))
+ .findFirst().orElse(null);
}
@Override
protected Iterable<IEObjectDescription> getLocalElementsByName(final QualifiedName name) {
- Stream<IResourceDescription> resourceDescriptions = getResourceDescriptionsByName(name);
- return getExportedObjectsByName(resourceDescriptions, name).collect(Collectors.toList());
+ return getResourceDescriptionsByName(name)
+ .flatMap(fdp -> getExportedObjectsByName(fdp, name))
+ .collect(Collectors.toList());
}
+
// @Override
// protected IEObjectDescription getSingleLocalElementByEObject(final EObject object, final URI uri) {
-// Stream<IResourceDescription> resourceDescriptions = getResourceDescriptionsByObject(object);
-// return getExportedObjectsByObject(resourceDescriptions, object).findFirst().orElse(null);
+// return getResourceDescriptionsByObject(object)
+// .flatMap(fdp -> getExportedObjectsByObject(fdp, object))
+// .findFirst().orElse(null);
// }
@Override
protected Iterable<IEObjectDescription> getLocalElementsByEObject(final EObject object, final URI uri) {
- Stream<IResourceDescription> resourceDescriptions = getResourceDescriptionsByObject(object);
- return getExportedObjectsByObject(resourceDescriptions, object).collect(Collectors.toList());
+ return getResourceDescriptionsByObject(object)
+ .flatMap(fdp -> getExportedObjectsByObject(fdp, object))
+ .collect(Collectors.toList());
}
@Override
protected Iterable<IEObjectDescription> getAllLocalElements() {
- Stream<IResourceDescription> resourceDescriptions = getAllResourceDescriptions();
- return getExportedObjectsByType(resourceDescriptions, type).collect(Collectors.toList());
+ return getAllResourceDescriptions()
+ .flatMap(fdp -> getExportedObjectsByType(fdp, type))
+ .collect(Collectors.toList());
+ }
+
+ private Stream<IEObjectDescription> getExportedObjectsByName(FileDescriptionPair fdp, QualifiedName name) {
+ return filterEObjectDescriptions(fdp.rd.getExportedObjects(type, name, isIgnoreCase()), fdp.mf);
}
- private Stream<IEObjectDescription> getExportedObjectsByName(Stream<IResourceDescription> resourceDescriptions, QualifiedName name) {
- return resourceDescriptions.map(rd -> rd.getExportedObjects(type, name, isIgnoreCase()))
- .flatMap(eods -> StreamSupport.stream(eods.spliterator(), false))
- .filter(filter::apply);
+ private Stream<IEObjectDescription> getExportedObjectsByType(FileDescriptionPair fdp, EClass type) {
+ return filterEObjectDescriptions(fdp.rd.getExportedObjectsByType(type), fdp.mf);
}
- private Stream<IEObjectDescription> getExportedObjectsByType(Stream<IResourceDescription> resourceDescriptions, EClass type) {
- return resourceDescriptions.map(rd -> rd.getExportedObjectsByType(type))
- .flatMap(eods -> StreamSupport.stream(eods.spliterator(), false))
- .filter(filter::apply);
+ private Stream<IEObjectDescription> getExportedObjectsByObject(FileDescriptionPair fdp, EObject object) {
+ return filterEObjectDescriptions(fdp.rd.getExportedObjectsByObject(object), fdp.mf);
}
- private Stream<IEObjectDescription> getExportedObjectsByObject(Stream<IResourceDescription> resourceDescriptions, EObject object) {
- return resourceDescriptions.map(rd -> rd.getExportedObjectsByObject(object))
- .flatMap(eods -> StreamSupport.stream(eods.spliterator(), false))
- .filter(filter::apply);
+ private Stream<IEObjectDescription> filterEObjectDescriptions(Iterable<IEObjectDescription> eods, ModelFile mf) {
+ return StreamSupport.stream(eods.spliterator(), false)
+ .filter(eo -> eo.getQualifiedName().startsWith(mf.name))
+ .filter(filter::apply);
}
- private Stream<IResourceDescription> getResourceDescriptionsByObject(EObject object) {
+ private Stream<FileDescriptionPair> getResourceDescriptionsByObject(EObject object) {
QualifiedName name = qualifiedNameProvider.getFullyQualifiedName(object);
if(name != null) {
return getResourceDescriptionsByName(name);
@@ -152,24 +160,27 @@ public class ModelPathGlobalScopeProvider extends AbstractGlobalScopeProvider {
return Stream.empty();
}
- private Stream<IResourceDescription> getResourceDescriptionsByName(QualifiedName name) {
+ private Stream<FileDescriptionPair> getResourceDescriptionsByName(QualifiedName name) {
IModelPath modelPath = modelPathProvider.get(context);
- Stream<URI> files = modelPath.getFiles(name);
+ Builder<QualifiedName> builder = Stream.builder();
+ while(!name.isEmpty()) {
+ builder.add(name);
+ name = name.skipLast(1);
+ }
+ Stream<ModelFile> files = builder.build().flatMap(n -> modelPath.getFiles(n));
return getResourceDescriptions(files);
}
- private Stream<IResourceDescription> getAllResourceDescriptions() {
+ private Stream<FileDescriptionPair> getAllResourceDescriptions() {
IModelPath modelPath = modelPathProvider.get(context);
- Stream<URI> files = modelPath.getAllFiles();
- return getResourceDescriptions(files);
+ return getResourceDescriptions(modelPath.getAllFiles());
}
- private Stream<IResourceDescription> getResourceDescriptions(Stream<URI> files) {
+ private Stream<FileDescriptionPair> getResourceDescriptions(Stream<ModelFile> files) {
IResourceDescriptions descriptions = ModelPathGlobalScopeProvider.this.getResourceDescriptions(context);
ResourceSet resourceSet = context.getResourceSet();
return files.filter(modelPathFileFilter)
- .map(uri -> getResourceDescription(uri, descriptions, resourceSet))
- .flatMap(rd -> streamOptional(rd));
+ .flatMap(mf -> getResourceDescription(mf.uri, descriptions, resourceSet).map(rd -> new FileDescriptionPair(mf, rd)));
}
/**
@@ -181,11 +192,11 @@ public class ModelPathGlobalScopeProvider extends AbstractGlobalScopeProvider {
* @param resourceSet a resource set used to load the resource
* @return an optional of the requested resource descriptions
*/
- private Optional<IResourceDescription> getResourceDescription(URI uri, IResourceDescriptions descriptions, ResourceSet resourceSet) {
+ private Stream<IResourceDescription> getResourceDescription(URI uri, IResourceDescriptions descriptions, ResourceSet resourceSet) {
uri = resolveURI(uri);
IResourceDescription resourceDescription = descriptions.getResourceDescription(uri);
if(resourceDescription != null) {
- return Optional.of(resourceDescription);
+ return Stream.of(resourceDescription);
}
else {
IResourceServiceProvider resourceServiceProvider = resourceServiceProviderRegistry.getResourceServiceProvider(uri);
@@ -193,10 +204,10 @@ public class ModelPathGlobalScopeProvider extends AbstractGlobalScopeProvider {
Resource resource = resourceSet.getResource(uri, true);
IResourceDescription.Manager descriptionManager = resourceServiceProvider.getResourceDescriptionManager();
resourceDescription = descriptionManager.getResourceDescription(resource);
- return Optional.of(resourceDescription);
+ return Stream.of(resourceDescription);
}
}
- return Optional.empty();
+ return Stream.empty();
}
private URI resolveURI(URI uri) {
@@ -205,11 +216,14 @@ public class ModelPathGlobalScopeProvider extends AbstractGlobalScopeProvider {
}
}
- /**
- * This method for {@link Optional} is first introduced in Java 9 :(
- */
- private static <T> Stream<T> streamOptional(Optional<T> optional) {
- return optional.isPresent() ? Stream.of(optional.get()) : Stream.empty();
+ private static final class FileDescriptionPair {
+ public final ModelFile mf;
+ public final IResourceDescription rd;
+
+ public FileDescriptionPair(ModelFile modelFile, IResourceDescription resourceDescription) {
+ this.mf = modelFile;
+ this.rd = resourceDescription;
+ }
}
}
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/RoomJavaValidator.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/RoomJavaValidator.java
index 75ab3b211..b9089e545 100644
--- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/RoomJavaValidator.java
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/RoomJavaValidator.java
@@ -139,7 +139,7 @@ public class RoomJavaValidator extends AbstractRoomJavaValidator {
IModelPath modelpath = modelPathProvider.get(resource);
modelpath.getQualifiedName(resource.getURI()).ifPresent(fileName -> {
if(!fileName.equals(modelName)) {
- warning("model name doesn't match its file name and its location on the modelpath", RoomPackage.Literals.ROOM_MODEL__NAME,
+ error("model name doesn't match its file name and its location on the modelpath", RoomPackage.Literals.ROOM_MODEL__NAME,
WRONG_MODEL_NAME, nameConverter.toString(modelName), nameConverter.toString(fileName));
}
});
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 bb5df0043..8462c3ad8 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
@@ -37,7 +37,7 @@ import org.eclipse.xtext.naming.QualifiedName;
public class FileSystemModelPath implements IModelPath {
private List<Path> paths;
- private HashMap<QualifiedName, List<URI>> packages;
+ private HashMap<QualifiedName, List<ModelFile>> packages;
/**
* Creates a new modelpath that contains all files in the passed paths.
@@ -50,17 +50,15 @@ public class FileSystemModelPath implements IModelPath {
}
@Override
- public Stream<URI> getFiles(QualifiedName name) {
- Stream<URI> stream = Stream.empty();
- while(!name.isEmpty()) {
- name = name.skipLast(1);
- stream = Stream.concat(stream, getPackage(name));
- }
- return stream;
+ public Stream<ModelFile> getFiles(QualifiedName name) {
+ QualifiedName pkgName = name.skipLast(1);
+ String fileName = name.getLastSegment();
+ return packages.computeIfAbsent(pkgName, n -> createPackage(n)).stream()
+ .filter(mf -> mf.name.getLastSegment().equals(fileName));
}
@Override
- public Stream<URI> getAllFiles() {
+ public Stream<ModelFile> getAllFiles() {
throw new UnsupportedOperationException();
}
@@ -87,27 +85,16 @@ public class FileSystemModelPath implements IModelPath {
}
/**
- * Returns all files that are contained in the package with the specified name.
- *
- * @param name the fully qualified name of the package
- * @return a stream of all file uris
- */
- private Stream<URI> getPackage(QualifiedName name) {
- List<URI> pkg = packages.computeIfAbsent(name, n -> createPackage(n));
- return pkg.stream();
- }
-
- /**
* Searches for all files that are contained in the package with the specified name.
*
* @param name the fully qualified name of the package
* @return a list of all file uris
*/
- private List<URI> createPackage(QualifiedName name) {
+ private List<ModelFile> createPackage(QualifiedName name) {
return paths.stream()
- .map(path -> createPackagePath(name, path))
+ .map(path -> createPackagePath(path, name))
.filter(path -> Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS))
- .flatMap(dir -> collectFiles(dir))
+ .flatMap(dir -> listFiles(dir, name))
.collect(Collectors.toList());
}
@@ -115,13 +102,14 @@ public class FileSystemModelPath implements IModelPath {
* Lists all files of the passed directory.
*
* @param dir the path of a folder
+ * @param name the qualified name of the directory
* @return a stream of file uris
*/
- private Stream<URI> collectFiles(Path dir) {
+ private Stream<ModelFile> listFiles(Path dir, QualifiedName name) {
try {
return Files.list(dir)
.filter(path -> Files.isRegularFile(path))
- .map(file -> createURI(file));
+ .map(file -> createModelFile(file, name));
}
catch (IOException e) {
throw new UncheckedIOException(e);
@@ -129,20 +117,26 @@ public class FileSystemModelPath implements IModelPath {
}
/**
- * Creates an uri for a given path.
+ * Creates a new model file from the path and package.
+ *
+ * @param file the path of the file
+ * @param pkg the qualified name of the package
+ * @return the new model file
*/
- private URI createURI(Path path) {
- return URI.createURI(path.toUri().toString());
+ private ModelFile createModelFile(Path file, QualifiedName pkg) {
+ URI uri = URI.createURI(file.toUri().toString());
+ String fileName = file.getFileName().toString();
+ return ModelFile.create(uri, pkg, fileName);
}
/**
* Creates the path of a specific package within the passed directory.
*
- * @param name the fully qualified name of the package
* @param dir the folder which the package path is based on
+ * @param name the fully qualified name of the package
* @return the path of the package
*/
- private Path createPackagePath(QualifiedName name, Path dir) {
+ private Path createPackagePath(Path dir, QualifiedName name) {
if(!name.isEmpty()) {
String firstSegment = name.getFirstSegment();
String[] segments = new String[name.getSegmentCount() - 1];
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 e654ec208..f7bf9466e 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
@@ -26,19 +26,19 @@ public interface IModelPath {
public static final IModelPath EMPTY = new EmptyModelPath();
/**
- * Returns all files that could contain the object with the specified name.
+ * Returns all files on this modelpath with the specified name.
*
- * @param name the fully qualified name of the object
- * @return a stream of file uris
+ * @param name the name of the desired files
+ * @return a stream of files
*/
- public Stream<URI> getFiles(QualifiedName name);
+ public Stream<ModelFile> getFiles(QualifiedName name);
/**
* Returns all files on this modelpath.
*
- * @return a stream of file uris
+ * @return a stream of files
*/
- public Stream<URI> getAllFiles();
+ public Stream<ModelFile> getAllFiles();
/**
* Returns a qualified name for the model objects in the file.
@@ -51,19 +51,49 @@ public interface IModelPath {
/**
* Checks whether the modelpath is empty.
*
- * @return true if the modelpath is empty.
+ * @return true if the modelpath is empty
*/
public boolean isEmpty();
- static class EmptyModelPath implements IModelPath {
+ public static final class ModelFile {
+ public final URI uri;
+ public final QualifiedName name;
+ public final String extension;
+
+ public ModelFile(URI uri, QualifiedName name, String extension) {
+ this.uri = uri;
+ this.name = name;
+ this.extension = extension;
+ }
+
+ /**
+ * Computes the name and extension of the new model file from package and file name.
+ *
+ * @param uri the uri of the file
+ * @param pkg the package of the file
+ * @param fileName the name of the file
+ * @return a new model file
+ */
+ public static ModelFile create(URI uri, QualifiedName pkg, String fileName) {
+ int periodIndex = fileName.lastIndexOf('.');
+ if(periodIndex != -1) {
+ String name = fileName.substring(0, periodIndex);
+ String extension = fileName.substring(periodIndex + 1);
+ return new ModelFile(uri, pkg.append(name), extension);
+ }
+ return new ModelFile(uri, pkg.append(fileName), "");
+ }
+ }
+
+ public static class EmptyModelPath implements IModelPath {
@Override
- public Stream<URI> getFiles(QualifiedName name) {
+ public Stream<ModelFile> getFiles(QualifiedName name) {
return Stream.empty();
}
@Override
- public Stream<URI> getAllFiles() {
+ public Stream<ModelFile> getAllFiles() {
return Stream.empty();
}

Back to the top