3737import org .eclipse .jdt .core .dom .FileASTRequestor ;
3838
3939import tools .mdsd .jamopp .model .java .JavaClasspath ;
40+ import tools .mdsd .jamopp .model .java .containers .ContainersFactory ;
41+ import tools .mdsd .jamopp .model .java .containers .EmptyModel ;
4042import tools .mdsd .jamopp .model .java .containers .JavaRoot ;
4143import 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