Added support for relative paths in import statements
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.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 @@
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 @@
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 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 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.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.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 @@
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 @@
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 IParser getParser() {
- return new EmfaticParserDriver();
+ return new EmfaticParserDriver(URI.createPlatformResourceURI(_editor.getFile().getFullPath().toPortableString(), true));
}
public ITextHover getTextHover(ISourceViewer sourceViewer,