Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkolovos2015-07-26 07:40:51 -0400
committerdkolovos2015-07-26 07:40:51 -0400
commit4f873d43cc26ff262efc3cca297dcfb1f4e92a77 (patch)
treeec2b6abf56314e91dbeaaff27d05f8e6bab26209
parent41b5ad9899dfe6420503eb99ed5f8731f1a7fde4 (diff)
downloadorg.eclipse.emfatic-4f873d43cc26ff262efc3cca297dcfb1f4e92a77.tar.gz
org.eclipse.emfatic-4f873d43cc26ff262efc3cca297dcfb1f4e92a77.tar.xz
org.eclipse.emfatic-4f873d43cc26ff262efc3cca297dcfb1f4e92a77.zip
Added support for relative paths in import statements
-rw-r--r--plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/Connector.java15
-rw-r--r--plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/EcoreGenerator.java4
-rw-r--r--plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParserDriver.java10
-rw-r--r--plugins/org.eclipse.emf.emfatic.ui/src/org/eclipse/emf/emfatic/ui/editor/EmfaticSourceViewerConfiguration.java3
4 files changed, 24 insertions, 8 deletions
diff --git a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/Connector.java b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/Connector.java
index 09d171e..f0ebea1 100644
--- a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/Connector.java
+++ b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/Connector.java
@@ -64,6 +64,7 @@ import org.eclipse.emf.emfatic.core.lang.gen.ast.Wildcard;
import org.eclipse.emf.emfatic.core.util.EmfaticBasicTypes;
import org.eclipse.gymnast.runtime.core.ast.ASTNode;
import org.eclipse.gymnast.runtime.core.parser.ParseContext;
+import org.omg.CORBA._PolicyStub;
@@ -76,12 +77,14 @@ import org.eclipse.gymnast.runtime.core.parser.ParseContext;
private OneToOneMap<ASTNode, EObject> cstDecl2EcoreAST = null;
private OneToManyMap<EObject, ASTNode> ecoreDecl2cstUse = new OneToManyMap<EObject, ASTNode>();
-
+ protected URI uri = null;
+
public Connector(Builder b) {
this.cstDecl2EcoreAST = b.getCstDecl2EcoreASTMap();
}
public void connect(ParseContext parseContext, Resource resource, IProgressMonitor monitor) {
+ uri = resource.getURI();
ecoreDecl2cstUse.clear();
initParseContext(parseContext);
CompUnit compUnit = (CompUnit) parseContext.getParseRoot();
@@ -116,11 +119,17 @@ import org.eclipse.gymnast.runtime.core.parser.ParseContext;
private Resource tryLoadResource(URI uri) {
try {
+ if (uri != null && Connector.this.uri != null && uri.isRelative()) {
+ uri = uri.resolve(Connector.this.uri);
+ }
+
Resource resource = resourceSet.getResource(uri, true);
- if (resource != null && resource.isLoaded())
+ if (resource != null && resource.isLoaded()) {
return resource;
+ }
} catch (Exception ex) {
- ex.printStackTrace();
+ System.err.println(ex.getMessage());
+
}
return null;
}
diff --git a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/EcoreGenerator.java b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/EcoreGenerator.java
index e2d3cd7..6a5ed4f 100644
--- a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/EcoreGenerator.java
+++ b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/EcoreGenerator.java
@@ -45,7 +45,7 @@ public class EcoreGenerator {
public void generate(IFile emfFile, boolean writeEcore, IProgressMonitor monitor) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(emfFile.getContents()));
- EmfaticParserDriver parser = new EmfaticParserDriver();
+ EmfaticParserDriver parser = new EmfaticParserDriver(URI.createPlatformResourceURI(emfFile.getFullPath().toPortableString(), true));
ParseContext parseContext = parser.parse(reader);
String filePath = getEcoreFilePath(emfFile);
Resource resource = createResource(filePath, true);
@@ -77,7 +77,7 @@ public class EcoreGenerator {
public void generate(File emfFile, boolean writeEcore) throws Exception {
NullProgressMonitor monitor = new NullProgressMonitor();
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(emfFile)));
- EmfaticParserDriver parser = new EmfaticParserDriver();
+ EmfaticParserDriver parser = new EmfaticParserDriver(URI.createFileURI(emfFile.getAbsolutePath()));
ParseContext parseContext = parser.parse(reader);
String filePath = emfFile.getAbsolutePath().replaceAll("\\.emf$", ".ecore");
Resource resource = createResource(filePath, false);
diff --git a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParserDriver.java b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParserDriver.java
index 111f051..d77031c 100644
--- a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParserDriver.java
+++ b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParserDriver.java
@@ -9,6 +9,7 @@ import java.io.Reader;
import java.util.HashSet;
import java.util.Set;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
@@ -30,7 +31,13 @@ import org.eclipse.gymnast.runtime.core.parser.ParseError;
import org.eclipse.gymnast.runtime.core.parser.ParseMessage;
public class EmfaticParserDriver implements IParser {
-
+
+ protected URI uri = null;
+
+ public EmfaticParserDriver(URI uri) {
+ this.uri = uri;
+ }
+
public ParseContext parse(Reader input) {
ExtSimpleCharStream stream = new ExtSimpleCharStream(input);
@@ -53,7 +60,6 @@ public class EmfaticParserDriver implements IParser {
Builder builder = new Builder();
NullProgressMonitor npm = new NullProgressMonitor();
ResourceSet resourceSet = new ResourceSetImpl();
- URI uri = URI.createPlatformResourceURI("dummy");
if (Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().get("ecore") == null) {
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
diff --git a/plugins/org.eclipse.emf.emfatic.ui/src/org/eclipse/emf/emfatic/ui/editor/EmfaticSourceViewerConfiguration.java b/plugins/org.eclipse.emf.emfatic.ui/src/org/eclipse/emf/emfatic/ui/editor/EmfaticSourceViewerConfiguration.java
index 235cc8d..11edb76 100644
--- a/plugins/org.eclipse.emf.emfatic.ui/src/org/eclipse/emf/emfatic/ui/editor/EmfaticSourceViewerConfiguration.java
+++ b/plugins/org.eclipse.emf.emfatic.ui/src/org/eclipse/emf/emfatic/ui/editor/EmfaticSourceViewerConfiguration.java
@@ -16,6 +16,7 @@ package org.eclipse.emf.emfatic.ui.editor;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.emfatic.core.lang.gen.parser.EmfaticParserDriver;
import org.eclipse.emf.emfatic.ui.contentassist.CascadedContentAssistProcessor;
import org.eclipse.emf.emfatic.ui.contentassist.EmfaticContentAssistProcessor;
@@ -64,7 +65,7 @@ public class EmfaticSourceViewerConfiguration extends
}
public IParser getParser() {
- return new EmfaticParserDriver();
+ return new EmfaticParserDriver(URI.createPlatformResourceURI(_editor.getFile().getFullPath().toPortableString(), true));
}
public ITextHover getTextHover(ISourceViewer sourceViewer,

Back to the top