Java Code Examples for org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess#generateFile()
The following examples show how to use
org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess#generateFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractAntlrGrammarGenerator.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public void generate(final Grammar it, final AntlrOptions options, final IXtextGeneratorFileSystemAccess fsa) { this.keywordHelper = KeywordHelper.getHelper(it); this.originalGrammar = it; final RuleFilter filter = new RuleFilter(); filter.setDiscardUnreachableRules(options.isSkipUnusedRules()); final RuleNames ruleNames = RuleNames.getRuleNames(it, true); final Grammar flattened = new FlattenedGrammarAccess(ruleNames, filter).getFlattenedGrammar(); boolean _isCombinedGrammar = this.isCombinedGrammar(); new CombinedGrammarMarker(_isCombinedGrammar).attachToEmfObject(flattened); fsa.generateFile(this.getGrammarNaming().getParserGrammar(it).getGrammarFileName(), this.compileParser(flattened, options)); boolean _isCombinedGrammar_1 = this.isCombinedGrammar(); boolean _not = (!_isCombinedGrammar_1); if (_not) { fsa.generateFile(this.getGrammarNaming().getLexerGrammar(it).getGrammarFileName(), this.compileLexer(flattened, options)); } }
Example 2
Source File: AbstractAntlrGeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected void cleanupLexerTokensFile(final AntlrGrammar lexerGrammar, final KeywordHelper helper, final IXtextGeneratorFileSystemAccess fsa) { try { boolean _isBacktrackLexer = this.options.isBacktrackLexer(); if (_isBacktrackLexer) { final MutableTokenDefProvider provider = this.createLexerTokensProvider(lexerGrammar, helper, fsa); final Iterator<Map.Entry<Integer, String>> entries = provider.getTokenDefMap().entrySet().iterator(); while (entries.hasNext()) { { final String value = entries.next().getValue(); if ((((!helper.isKeywordRule(value)) && (!value.startsWith("RULE_"))) && (!value.startsWith("SUPER_")))) { entries.remove(); } } } final CharArrayWriter writer = new CharArrayWriter(); PrintWriter _printWriter = new PrintWriter(writer); provider.writeTokenFile(_printWriter); String _tokensFileName = lexerGrammar.getTokensFileName(); char[] _charArray = writer.toCharArray(); String _string = new String(_charArray); fsa.generateFile(_tokensFileName, _string); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 3
Source File: JFlexGeneratorFragment2.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public void generate() { Grammar grammar = getGrammar(); String macros = read(patternPath); String rules = read(additionalRulePath); final String encoding = codeConfig.getEncoding(); String fileName = "Internal" + GrammarUtil.getSimpleName(grammar) + "Flexer.flex"; final IXtextGeneratorFileSystemAccess fsa; final GrammarNaming grammarNaming; if (ui) { grammarNaming = contentAssistNaming; fsa = this.getProjectConfig().getGenericIde().getSrcGen(); } else { grammarNaming = productionNaming; fsa = this.getProjectConfig().getRuntime().getSrcGen(); } String srcGenPath = fsa.getPath(); String parserName = grammarNaming.getInternalParserClass(grammar).getName(); String baseName = grammarNaming.getParserGrammar(grammar).getGrammarFileName(); baseName = baseName.substring(0, baseName.lastIndexOf('/')); String directory = srcGenPath + "/" + baseName; String contents = templatex.generateFlexer(grammar, parserName, macros, rules, codeConfig); fsa.generateFile(baseName + "/" + fileName, contents); String javaFileName = directory + "/" + "Internal" + GrammarUtil.getSimpleName(grammar) + "Flexer.java"; String[] args = new String[] { "-d", directory, directory + "/" + fileName }; main.runJFlex(args); Charset charset = Charset.forName(encoding); String javaCode = readFileIntoString(javaFileName, charset); javaCode = new NewlineNormalizer(codeConfig.getLineDelimiter()).normalizeLineDelimiters(javaCode); javaCode = removeTimestamps(javaCode); writeStringIntoFile(javaFileName, javaCode, charset); }
Example 4
Source File: AbstractAntlrGeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void splitParserClassFile(final IXtextGeneratorFileSystemAccess fsa, final TypeReference parser) { final String content = fsa.readTextFile(parser.getJavaPath()).toString(); int _fieldsPerClass = this.getOptions().getFieldsPerClass(); final AntlrParserSplitter splitter = new AntlrParserSplitter(content, _fieldsPerClass); String _transform = splitter.transform(); int _methodsPerClass = this.getOptions().getMethodsPerClass(); final PartialClassExtractor extractor = new PartialClassExtractor(_transform, _methodsPerClass); fsa.generateFile(parser.getJavaPath(), extractor.transform()); }
Example 5
Source File: AbstractAntlrGeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void simplifyUnorderedGroupPredicates(final IXtextGeneratorFileSystemAccess fsa, final TypeReference parser) { final String content = fsa.readTextFile(parser.getJavaPath()).toString(); UnorderedGroupsSplitter splitter = new UnorderedGroupsSplitter(content); String transformed = splitter.transform(); SyntacticPredicateFixup fixup = new SyntacticPredicateFixup(transformed); transformed = fixup.transform(); BacktrackingGuardForUnorderedGroupsRemover remover = new BacktrackingGuardForUnorderedGroupsRemover(transformed); String newContent = remover.transform(); fsa.generateFile(parser.getJavaPath(), newContent); }
Example 6
Source File: AbstractAntlrGeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void normalizeTokens(final IXtextGeneratorFileSystemAccess fsa, final String tokenFile) { String content = fsa.readTextFile(tokenFile).toString(); content = this.newLineNormalizer.postProcess(fsa.getURI(tokenFile), content).toString(); final List<String> splitted = Strings.split(content, this.codeConfig.getLineDelimiter()); Collections.<String>sort(splitted); String _concat = Strings.concat(this.codeConfig.getLineDelimiter(), splitted); String _lineDelimiter = this.codeConfig.getLineDelimiter(); String _plus = (_concat + _lineDelimiter); content = _plus; fsa.generateFile(tokenFile, content); }
Example 7
Source File: AbstractAntlrGeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void improveParserCodeQuality(final IXtextGeneratorFileSystemAccess fsa, final TypeReference parser) { String parserContent = fsa.readTextFile(parser.getJavaPath()).toString(); parserContent = this.codeQualityHelper.stripUnnecessaryComments(parserContent, this.options); parserContent = this.codeQualityHelper.removeDuplicateBitsets(parserContent, this.options); parserContent = this.codeQualityHelper.removeDuplicateDFAs(parserContent, this.options); fsa.generateFile(parser.getJavaPath(), parserContent); }
Example 8
Source File: AbstractAntlrGeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void cleanupParserTokensFile(final AntlrGrammar lexerGrammar, final AntlrGrammar parserGrammar, final KeywordHelper helper, final IXtextGeneratorFileSystemAccess fsa) { try { final MutableTokenDefProvider provider = this.createLexerTokensProvider(lexerGrammar, helper, fsa); Set<Map.Entry<Integer, String>> _entrySet = provider.getTokenDefMap().entrySet(); for (final Map.Entry<Integer, String> entry : _entrySet) { { final String value = entry.getValue(); boolean _isKeywordRule = helper.isKeywordRule(value); if (_isKeywordRule) { final String keywordAsAntlrString = AntlrGrammarGenUtil.toAntlrString(helper.getKeywordValue(value)); entry.setValue((("\'" + keywordAsAntlrString) + "\'")); } else { boolean _startsWith = value.startsWith("\'"); if (_startsWith) { String _antlrString = AntlrGrammarGenUtil.toAntlrString(value); String _plus = ("\'" + _antlrString); String _plus_1 = (_plus + "\'"); entry.setValue(_plus_1); } } } } final CharArrayWriter writer = new CharArrayWriter(); PrintWriter _printWriter = new PrintWriter(writer); provider.writeTokenFile(_printWriter); String _tokensFileName = parserGrammar.getTokensFileName(); char[] _charArray = writer.toCharArray(); String _string = new String(_charArray); fsa.generateFile(_tokensFileName, _string); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 9
Source File: XtextGenerator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void mergeManifest(final ManifestAccess manifest, final IXtextGeneratorFileSystemAccess metaInf) throws IOException { InputStream in = null; try { in = metaInf.readBinaryFile(manifest.getPath()); String _bundleName = manifest.getBundleName(); final MergeableManifest2 merge = new MergeableManifest2(in, _bundleName); merge.setLineDelimiter(this.codeConfig.getLineDelimiter()); merge.addExportedPackages(manifest.getExportedPackages()); merge.addRequiredBundles(manifest.getRequiredBundles()); merge.addImportedPackages(manifest.getImportedPackages()); if (((manifest.getActivator() != null) && StringExtensions.isNullOrEmpty(merge.getBundleActivator()))) { merge.setBundleActivator(manifest.getActivator().getName()); } boolean _isModified = merge.isModified(); if (_isModified) { final ByteArrayOutputStream out = new ByteArrayOutputStream(); merge.write(out); String _path = manifest.getPath(); byte[] _byteArray = out.toByteArray(); ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray); metaInf.generateFile(_path, _byteArrayInputStream); } } finally { if ((in != null)) { in.close(); } } }
Example 10
Source File: AbstractAntlrGeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void splitLexerClassFile(final IXtextGeneratorFileSystemAccess fsa, final TypeReference lexer) { final String content = fsa.readTextFile(lexer.getJavaPath()).toString(); AntlrLexerSplitter splitter = new AntlrLexerSplitter(content); splitter.setCasesPerSpecialStateSwitch(this.options.getCasesPerSpecialStateSwitch()); fsa.generateFile(lexer.getJavaPath(), splitter.transform()); }
Example 11
Source File: AbstractAntlrGeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void suppressWarnings(final IXtextGeneratorFileSystemAccess fsa, final TypeReference type) { final String content = fsa.readTextFile(type.getJavaPath()).toString(); final String newContent = new SuppressWarningsProcessor().process(content); fsa.generateFile(type.getJavaPath(), newContent); }
Example 12
Source File: AbstractAntlrGeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void normalizeLineDelimiters(final IXtextGeneratorFileSystemAccess fsa, final TypeReference type) { String content = fsa.readTextFile(type.getJavaPath()).toString(); content = this.newLineNormalizer.postProcess(fsa.getURI(type.getJavaPath()), content).toString(); content = content.replaceAll("\"\\+(\\r)?\\n\\s+\"", ""); fsa.generateFile(type.getJavaPath(), content); }
Example 13
Source File: AbstractAntlrGeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void improveLexerCodeQuality(final IXtextGeneratorFileSystemAccess fsa, final TypeReference lexer) { String lexerContent = fsa.readTextFile(lexer.getJavaPath()).toString(); lexerContent = this.codeQualityHelper.stripUnnecessaryComments(lexerContent, this.options); fsa.generateFile(lexer.getJavaPath(), lexerContent); }
Example 14
Source File: AbstractAntlrGeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void removeBackTrackingGuards(final IXtextGeneratorFileSystemAccess fsa, final TypeReference parser, final int lookaheadThreshold) { final String content = fsa.readTextFile(parser.getJavaPath()).toString(); final BacktrackingGuardRemover remover = new BacktrackingGuardRemover(content, lookaheadThreshold); final String newContent = remover.transform(); fsa.generateFile(parser.getJavaPath(), newContent); }