@Override public void generateFile(final String fileName, final String outputConfigurationName, final CharSequence contents) { super.generateFile(fileName, outputConfigurationName, contents); final String path = this.getPath(fileName, outputConfigurationName); String _xifexpression = null; boolean _endsWith = fileName.endsWith(".java"); if (_endsWith) { int _length = fileName.length(); int _minus = (_length - 5); _xifexpression = fileName.substring(0, _minus).replace("/", "."); } final String javaName = _xifexpression; RegisteringFileSystemAccess.GeneratedFile _generatedFile = new RegisteringFileSystemAccess.GeneratedFile(path, javaName, contents); this.generatedFiles.add(_generatedFile); }
protected String getPath(final String fileName, final String outputConfigurationName) { final String path = this.getPathes().get(outputConfigurationName); return ((((("/" + this.projectName) + "/") + path) + "/") + fileName); }
protected void doGenerate() { if (access == null) { doValidation(); access = fileSystemAccessProvider.get(); access.setOutputConfigurations(outputConfigurations); for (Resource resource : sources) { if (resource instanceof XtextResource) { access.setProjectName(PROJECT_NAME); XtextResource xtextResource = (XtextResource) resource; IResourceServiceProvider resourceServiceProvider = xtextResource.getResourceServiceProvider(); GeneratorDelegate generator = resourceServiceProvider.get(GeneratorDelegate.class); if (generator != null) { GeneratorContext context = new GeneratorContext(); context.setCancelIndicator(CancelIndicator.NullImpl); generator.generate(xtextResource, access, context); } } } generatedCode = newHashMap(); for (final GeneratedFile e : access.getGeneratedFiles()) { if (e.getJavaClassName() != null) { generatedCode.put(e.getJavaClassName(), e.getContents().toString()); } } } }
/** * @return all generated resources. the key is the file path and the value denotes the generated text. */ public Map<String, CharSequence> getAllGeneratedResources() { doGenerate(); Map<String,CharSequence> result = newHashMap(); for (GeneratedFile f: access.getGeneratedFiles()) { result.put(f.getPath(), f.getContents()); } return result; }
/** * Convenience method for the common case, that only one file is generated. */ public String getSingleGeneratedCode() { doGenerate(); Set<GeneratedFile> generatedFiles = access.getGeneratedFiles(); if (generatedFiles.size() == 1) return generatedFiles.iterator().next().getContents().toString(); else if (generatedFiles.isEmpty()) return "NO FILE WAS GENERATED"; String separator = System.getProperty("line.separator"); if (separator == null) separator = "\n"; List<GeneratedFile> files = newArrayList(generatedFiles); Collections.sort(files, new Comparator<GeneratedFile>() { @Override public int compare(GeneratedFile o1, GeneratedFile o2) { return o1.getPath().toString().compareTo(o2.getPath().toString()); } }); StringBuilder result = new StringBuilder("MULTIPLE FILES WERE GENERATED"+separator+separator); int i = 1; for (GeneratedFile file: files) { result.append("File "+i+" : "+file.getPath().toString()+separator+separator); result.append(file.getContents()).append(separator); i++; } return result.toString(); }