Skip to content

Commit 01272fe

Browse files
authored
Merge pull request #18 from MDSD-Tools/6_deactivate_first_variant
#6 The first variant always returns an empty model.
2 parents 546dc82 + 329cdfa commit 01272fe

File tree

1 file changed

+56
-33
lines changed

1 file changed

+56
-33
lines changed

jamopp.parser.jdt/src/main/java/tools/mdsd/jamopp/parser/jdt/JaMoPPJDTParser.java

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import org.eclipse.jdt.core.dom.FileASTRequestor;
3838

3939
import tools.mdsd.jamopp.model.java.JavaClasspath;
40+
import tools.mdsd.jamopp.model.java.containers.ContainersFactory;
41+
import tools.mdsd.jamopp.model.java.containers.EmptyModel;
4042
import tools.mdsd.jamopp.model.java.containers.JavaRoot;
4143
import tools.mdsd.jamopp.parser.api.JaMoPPParserAPI;
4244

@@ -46,22 +48,26 @@ public class JaMoPPJDTParser implements JaMoPPParserAPI {
4648

4749
@Override
4850
public JavaRoot parse(String fileName, InputStream input) {
49-
this.setUpResourceSet();
50-
StringBuilder builder = new StringBuilder();
51-
String lineSep = System.getProperty("line.separator");
52-
try(InputStreamReader inReader = new InputStreamReader(input); BufferedReader buffReader = new BufferedReader(inReader)) {
53-
buffReader.lines().forEach(line -> builder.append(line + lineSep));
54-
} catch (IOException e) {
55-
}
56-
String src = builder.toString();
57-
ASTNode ast = parseFileWithJDT(src, fileName);
58-
OrdinaryCompilationUnitJDTASTVisitorAndConverter converter = new OrdinaryCompilationUnitJDTASTVisitorAndConverter();
59-
converter.setSource(src);
60-
ast.accept(converter);
61-
TypeInstructionSeparationUtility.convertAll();
62-
JDTResolverUtility.completeResolution();
51+
// this.setUpResourceSet();
52+
// StringBuilder builder = new StringBuilder();
53+
// String lineSep = System.getProperty("line.separator");
54+
// try(InputStreamReader inReader = new InputStreamReader(input); BufferedReader buffReader = new BufferedReader(inReader)) {
55+
// buffReader.lines().forEach(line -> builder.append(line + lineSep));
56+
// } catch (IOException e) {
57+
// }
58+
// String src = builder.toString();
59+
// ASTNode ast = parseFileWithJDT(src, fileName);
60+
// OrdinaryCompilationUnitJDTASTVisitorAndConverter converter = new OrdinaryCompilationUnitJDTASTVisitorAndConverter();
61+
// converter.setSource(src);
62+
// ast.accept(converter);
63+
// TypeInstructionSeparationUtility.convertAll();
64+
// JDTResolverUtility.completeResolution();
65+
// this.resourceSet = null;
66+
// return converter.getConvertedElement();
67+
68+
var model = this.createEmptyModel();
6369
this.resourceSet = null;
64-
return converter.getConvertedElement();
70+
return model;
6571
}
6672

6773
private ASTNode parseFileWithJDT(String fileContent, String fileName) {
@@ -74,29 +80,38 @@ private ASTNode parseFileWithJDT(String fileContent, String fileName) {
7480

7581
@Override
7682
public Resource parseFile(Path file) {
77-
this.setUpResourceSet();
78-
Resource result = this.parseFilesWithJDT(new String[] {}, new String[] { file.toAbsolutePath().toString() },
79-
new String[] { DEFAULT_ENCODING }).get(0).eResource();
83+
// this.setUpResourceSet();
84+
// Resource result = this.parseFilesWithJDT(new String[] {}, new String[] { file.toAbsolutePath().toString() },
85+
// new String[] { DEFAULT_ENCODING }).get(0).eResource();
86+
// this.resourceSet = null;
87+
// return result;
88+
89+
var model = this.createEmptyModel();
8090
this.resourceSet = null;
81-
return result;
91+
return model.eResource();
8292
}
8393

8494
@Override
8595
public ResourceSet parseDirectory(Path dir) {
86-
this.setUpResourceSet();
87-
try {
88-
String[] sources = Files.walk(dir).filter(path -> Files.isRegularFile(path) && path.getFileName().toString().endsWith("java"))
89-
.map(Path::toAbsolutePath).map(Path::toString).toArray(i -> new String[i]);
90-
String[] encodings = new String[sources.length];
91-
for (int index = 0; index < encodings.length; index++) {
92-
encodings[index] = DEFAULT_ENCODING;
93-
}
94-
String[] classpathEntries = Files.walk(dir).filter(path -> Files.isRegularFile(path) && path.getFileName().toString().endsWith("jar"))
95-
.map(Path::toAbsolutePath).map(Path::toString).toArray(i -> new String[i]);
96-
this.parseFilesWithJDT(classpathEntries, sources, encodings);
97-
} catch (IOException e) {
98-
}
99-
ResourceSet result = this.resourceSet;
96+
// this.setUpResourceSet();
97+
// try {
98+
// String[] sources = Files.walk(dir).filter(path -> Files.isRegularFile(path) && path.getFileName().toString().endsWith("java"))
99+
// .map(Path::toAbsolutePath).map(Path::toString).toArray(i -> new String[i]);
100+
// String[] encodings = new String[sources.length];
101+
// for (int index = 0; index < encodings.length; index++) {
102+
// encodings[index] = DEFAULT_ENCODING;
103+
// }
104+
// String[] classpathEntries = Files.walk(dir).filter(path -> Files.isRegularFile(path) && path.getFileName().toString().endsWith("jar"))
105+
// .map(Path::toAbsolutePath).map(Path::toString).toArray(i -> new String[i]);
106+
// this.parseFilesWithJDT(classpathEntries, sources, encodings);
107+
// } catch (IOException e) {
108+
// }
109+
// ResourceSet result = this.resourceSet;
110+
// this.resourceSet = null;
111+
// return result;
112+
113+
this.createEmptyModel();
114+
var result = this.resourceSet;
100115
this.resourceSet = null;
101116
return result;
102117
}
@@ -139,6 +154,14 @@ public void acceptAST(String sourceFilePath, CompilationUnit node) {
139154
return result;
140155
}
141156

157+
private EmptyModel createEmptyModel() {
158+
this.setUpResourceSet();
159+
var container = this.resourceSet.createResource(URI.createURI("model://empty.java"));
160+
EmptyModel model = ContainersFactory.eINSTANCE.createEmptyModel();
161+
container.getContents().add(model);
162+
return model;
163+
}
164+
142165
private void setUpResourceSet() {
143166
if (this.resourceSet == null) {
144167
this.resourceSet = new ResourceSetImpl();

0 commit comments

Comments
 (0)