org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess Java Examples

The following examples show how to use org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess. 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: AbstractGeneratorFragmentTests.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public RuntimeProjectConfig getRuntime() {
  return new RuntimeProjectConfig() {
    @Override
    public String getName() {
      return "projectName";
    }
    
    @Override
    public String getEcoreModelFolder() {
      return "rootFolder/ecoreFolder";
    }
    
    @Override
    public IXtextGeneratorFileSystemAccess getSrcGen() {
      return new XtextGeneratorFileSystemAccess("rootFolder/src-gen", false);
    }
    
    @Override
    public IXtextGeneratorFileSystemAccess getRoot() {
      return new XtextGeneratorFileSystemAccess("rootFolder", false);
    }
  };
}
 
Example #2
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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 #3
Source File: AbstractAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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 #4
Source File: XtextAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doGenerate() {
  Grammar _grammar = this.getGrammar();
  boolean _isIgnoreCase = this.getOptions().isIgnoreCase();
  new KeywordHelper(_grammar, _isIgnoreCase, this.grammarUtil);
  boolean _isCombinedGrammar = this.isCombinedGrammar();
  new CombinedGrammarMarker(_isCombinedGrammar).attachToEmfObject(this.getGrammar());
  if (this.debugGrammar) {
    this.generateDebugGrammar();
  }
  this.generateProductionGrammar();
  IXtextGeneratorFileSystemAccess _srcGen = this.getProjectConfig().getGenericIde().getSrcGen();
  boolean _tripleNotEquals = (_srcGen != null);
  if (_tripleNotEquals) {
    this.generateContentAssistGrammar();
    this.addIdeBindingsAndImports();
  }
  this.generateProductionParser().writeTo(this.getProjectConfig().getRuntime().getSrcGen());
  this.generateAntlrTokenFileProvider().writeTo(this.getProjectConfig().getRuntime().getSrcGen());
  this.generateContentAssistParser().writeTo(this.getProjectConfig().getGenericIde().getSrcGen());
  boolean _hasSyntheticTerminalRule = this.hasSyntheticTerminalRule();
  if (_hasSyntheticTerminalRule) {
    this.generateProductionTokenSource().writeTo(this.getProjectConfig().getRuntime().getSrc());
    this.generateContentAssistTokenSource().writeTo(this.getProjectConfig().getGenericIde().getSrc());
  }
  this.addRuntimeBindingsAndImports();
  this.addIdeBindingsAndImports();
  this.addUiBindingsAndImports();
}
 
Example #5
Source File: AbstractAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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 #6
Source File: AbstractAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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 #7
Source File: AbstractAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void splitParserAndLexerIfEnabled(final IXtextGeneratorFileSystemAccess fsa, final TypeReference parser, final TypeReference lexer) {
  this.improveCodeQuality(fsa, lexer, parser);
  boolean _isClassSplitting = this.getOptions().isClassSplitting();
  if (_isClassSplitting) {
    this.splitLexerClassFile(fsa, lexer);
    this.splitParserClassFile(fsa, parser);
  }
}
 
Example #8
Source File: AbstractAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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 #9
Source File: AbstractAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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 #10
Source File: AbstractAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected MutableTokenDefProvider createLexerTokensProvider(final AntlrGrammar lexerGrammar, final KeywordHelper helper, final IXtextGeneratorFileSystemAccess fsa) {
  Charset _forName = Charset.forName(this.codeConfig.getEncoding());
  final MutableTokenDefProvider provider = new MutableTokenDefProvider(helper, _forName);
  final IAntlrTokenFileProvider _function = () -> {
    return fsa.readBinaryFile(lexerGrammar.getTokensFileName());
  };
  provider.setAntlrTokenFileProvider(_function);
  return provider;
}
 
Example #11
Source File: AbstractAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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 #12
Source File: XtextAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void generateProductionGrammar() {
  @Extension
  final GrammarNaming naming = this.productionNaming;
  final IXtextGeneratorFileSystemAccess fsa = this.getProjectConfig().getRuntime().getSrcGen();
  this.productionGenerator.generate(this.getGrammar(), this.getOptions(), fsa);
  this.runAntlr(naming.getParserGrammar(this.getGrammar()), naming.getLexerGrammar(this.getGrammar()), fsa);
  this.simplifyUnorderedGroupPredicatesIfRequired(this.getGrammar(), fsa, naming.getInternalParserClass(this.getGrammar()));
  this.splitParserAndLexerIfEnabled(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
  this.normalizeTokens(fsa, naming.getLexerGrammar(this.getGrammar()).getTokensFileName());
  this.suppressWarnings(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
  this.normalizeLineDelimiters(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
}
 
Example #13
Source File: XtextAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void generateContentAssistGrammar() {
  @Extension
  final ContentAssistGrammarNaming naming = this.contentAssistNaming;
  final IXtextGeneratorFileSystemAccess fsa = this.getProjectConfig().getGenericIde().getSrcGen();
  this.contentAssistGenerator.generate(this.getGrammar(), this.getOptions(), fsa);
  this.runAntlr(naming.getParserGrammar(this.getGrammar()), naming.getLexerGrammar(this.getGrammar()), fsa);
  this.simplifyUnorderedGroupPredicatesIfRequired(this.getGrammar(), fsa, naming.getInternalParserClass(this.getGrammar()));
  this.splitParserAndLexerIfEnabled(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
  this.normalizeTokens(fsa, naming.getLexerGrammar(this.getGrammar()).getTokensFileName());
  this.suppressWarnings(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
  this.normalizeLineDelimiters(fsa, naming.getLexerClass(this.getGrammar()), naming.getInternalParserClass(this.getGrammar()));
  if (this.removeBacktrackingGuards) {
    this.removeBackTrackingGuards(fsa, naming.getInternalParserClass(this.getGrammar()), this.lookaheadThreshold);
  }
}
 
Example #14
Source File: XtextGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void generateExecutableExtensionFactory(final IXtextGeneratorLanguage language) {
  IXtextGeneratorFileSystemAccess _srcGen = this.projectConfig.getEclipsePlugin().getSrcGen();
  boolean _tripleNotEquals = (_srcGen != null);
  if (_tripleNotEquals) {
    this.templates.createEclipsePluginExecutableExtensionFactory(language, IterableExtensions.<XtextGeneratorLanguage>head(this.languageConfigs)).writeTo(this.projectConfig.getEclipsePlugin().getSrcGen());
  }
}
 
Example #15
Source File: XtextGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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 #16
Source File: OutlineTreeProviderFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate() {
  ManifestAccess _manifest = this.getProjectConfig().getEclipsePlugin().getManifest();
  boolean _tripleNotEquals = (_manifest != null);
  if (_tripleNotEquals) {
    Set<String> _requiredBundles = this.getProjectConfig().getEclipsePlugin().getManifest().getRequiredBundles();
    _requiredBundles.add("org.eclipse.xtext.ui");
  }
  boolean _isGenerateStub = this.isGenerateStub();
  boolean _not = (!_isGenerateStub);
  if (_not) {
    return;
  }
  IXtextGeneratorFileSystemAccess _src = this.getProjectConfig().getEclipsePlugin().getSrc();
  boolean _tripleNotEquals_1 = (_src != null);
  if (_tripleNotEquals_1) {
    boolean _isGenerateXtendStub = this.isGenerateXtendStub();
    if (_isGenerateXtendStub) {
      this.generateXtendOutlineTreeProvider();
    } else {
      this.generateJavaOutlineTreeProvider();
    }
  }
  GuiceModuleAccess.BindingFactory _bindingFactory = new GuiceModuleAccess.BindingFactory();
  TypeReference _typeReference = new TypeReference("org.eclipse.xtext.ui.editor.outline.IOutlineTreeProvider");
  GuiceModuleAccess.BindingFactory _addTypeToType = _bindingFactory.addTypeToType(_typeReference, 
    this.getOutlineTreeProviderClass(this.getGrammar()));
  TypeReference _typeReference_1 = new TypeReference("org.eclipse.xtext.ui.editor.outline.impl.IOutlineTreeStructureProvider");
  _addTypeToType.addTypeToType(_typeReference_1, 
    this.getOutlineTreeProviderClass(this.getGrammar())).contributeTo(this.getLanguage().getEclipsePluginGenModule());
}
 
Example #17
Source File: JFlexGeneratorFragment2.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@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 #18
Source File: AbstractAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
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 #19
Source File: AbstractAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
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);
}
 
Example #20
Source File: XtextAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void runAntlr(final AntlrGrammar parserGrammar, final AntlrGrammar lexerGrammar, final IXtextGeneratorFileSystemAccess fsa) {
  final String encoding = this.getCodeConfig().getEncoding();
  StringConcatenation _builder = new StringConcatenation();
  String _path = fsa.getPath();
  _builder.append(_path);
  _builder.append("/");
  String _grammarFileName = lexerGrammar.getGrammarFileName();
  _builder.append(_grammarFileName);
  final String lexerGrammarFile = _builder.toString();
  final ArrayList<String> lexerAntlrParams = CollectionLiterals.<String>newArrayList(this.getAntlrParams());
  lexerAntlrParams.add("-fo");
  final String lexerOutputDir = lexerGrammarFile.substring(0, lexerGrammarFile.lastIndexOf("/"));
  lexerAntlrParams.add(lexerOutputDir);
  boolean _isCombinedGrammar = this.isCombinedGrammar();
  boolean _not = (!_isCombinedGrammar);
  if (_not) {
    this.getAntlrTool().runWithEncodingAndParams(lexerGrammarFile, encoding, ((String[])Conversions.unwrapArray(lexerAntlrParams, String.class)));
    this.cleanupLexerTokensFile(lexerGrammar, KeywordHelper.getHelper(this.getGrammar()), fsa);
  }
  StringConcatenation _builder_1 = new StringConcatenation();
  String _path_1 = fsa.getPath();
  _builder_1.append(_path_1);
  _builder_1.append("/");
  String _grammarFileName_1 = parserGrammar.getGrammarFileName();
  _builder_1.append(_grammarFileName_1);
  final String parserGrammarFile = _builder_1.toString();
  final ArrayList<String> parserAntlrParams = CollectionLiterals.<String>newArrayList(this.getAntlrParams());
  parserAntlrParams.add("-fo");
  String _substring = parserGrammarFile.substring(0, parserGrammarFile.lastIndexOf("/"));
  parserAntlrParams.add(_substring);
  boolean _isCombinedGrammar_1 = this.isCombinedGrammar();
  boolean _not_1 = (!_isCombinedGrammar_1);
  if (_not_1) {
    parserAntlrParams.add("-lib");
    parserAntlrParams.add(lexerOutputDir);
  }
  this.getAntlrTool().runWithEncodingAndParams(parserGrammarFile, encoding, ((String[])Conversions.unwrapArray(parserAntlrParams, String.class)));
  boolean _isCombinedGrammar_2 = this.isCombinedGrammar();
  boolean _not_2 = (!_isCombinedGrammar_2);
  if (_not_2) {
    this.cleanupParserTokensFile(lexerGrammar, parserGrammar, KeywordHelper.getHelper(this.getGrammar()), fsa);
  }
}
 
Example #21
Source File: XtextAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void generateDebugGrammar() {
  final IXtextGeneratorFileSystemAccess fsa = this.getProjectConfig().getRuntime().getSrcGen();
  this.debugGenerator.generate(this.getGrammar(), this.getOptions(), fsa);
}
 
Example #22
Source File: RuntimeProjectConfig.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Pure
@Override
public IXtextGeneratorFileSystemAccess getEcoreModel() {
  return this.ecoreModel;
}
 
Example #23
Source File: AbstractAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
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 #24
Source File: AbstractAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void improveCodeQuality(final IXtextGeneratorFileSystemAccess fsa, final TypeReference lexer, final TypeReference parser) {
  this.improveLexerCodeQuality(fsa, lexer);
  this.improveParserCodeQuality(fsa, parser);
}
 
Example #25
Source File: ContentAssistFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void generate() {
  ManifestAccess _manifest = this.getProjectConfig().getEclipsePlugin().getManifest();
  boolean _tripleNotEquals = (_manifest != null);
  if (_tripleNotEquals) {
    Set<String> _requiredBundles = this.getProjectConfig().getEclipsePlugin().getManifest().getRequiredBundles();
    _requiredBundles.add("org.eclipse.xtext.ui");
  }
  GuiceModuleAccess.BindingFactory _bindingFactory = new GuiceModuleAccess.BindingFactory();
  TypeReference _typeReference = new TypeReference("org.eclipse.xtext.ui.editor.contentassist.IContentProposalProvider");
  _bindingFactory.addTypeToType(_typeReference, 
    this.getProposalProviderClass(this.getGrammar())).contributeTo(this.getLanguage().getEclipsePluginGenModule());
  IXtextGeneratorFileSystemAccess _srcGen = this.getProjectConfig().getEclipsePlugin().getSrcGen();
  boolean _tripleNotEquals_1 = (_srcGen != null);
  if (_tripleNotEquals_1) {
    this.generateGenJavaProposalProvider();
  }
  if ((this.isGenerateStub() && (this.getProjectConfig().getEclipsePlugin().getSrc() != null))) {
    boolean _isGenerateXtendStub = this.isGenerateXtendStub();
    if (_isGenerateXtendStub) {
      this.generateXtendProposalProviderStub();
      ManifestAccess _manifest_1 = this.getProjectConfig().getEclipsePlugin().getManifest();
      boolean _tripleNotEquals_2 = (_manifest_1 != null);
      if (_tripleNotEquals_2) {
        Set<String> _requiredBundles_1 = this.getProjectConfig().getEclipsePlugin().getManifest().getRequiredBundles();
        String _xbaseLibVersionLowerBound = this.getProjectConfig().getRuntime().getXbaseLibVersionLowerBound();
        String _plus = ("org.eclipse.xtext.xbase.lib;bundle-version=\"" + _xbaseLibVersionLowerBound);
        String _plus_1 = (_plus + "\"");
        _requiredBundles_1.add(_plus_1);
        Set<String> _requiredBundles_2 = this.getProjectConfig().getEclipsePlugin().getManifest().getRequiredBundles();
        _requiredBundles_2.add("org.eclipse.xtend.lib;resolution:=optional");
      }
    } else {
      this.generateJavaProposalProviderStub();
    }
  }
  ManifestAccess _manifest_2 = this.getProjectConfig().getEclipsePlugin().getManifest();
  boolean _tripleNotEquals_3 = (_manifest_2 != null);
  if (_tripleNotEquals_3) {
    Set<String> _exportedPackages = this.getProjectConfig().getEclipsePlugin().getManifest().getExportedPackages();
    String _packageName = this.getProposalProviderClass(this.getGrammar()).getPackageName();
    _exportedPackages.add(_packageName);
  }
}
 
Example #26
Source File: QuickfixProviderFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void generate() {
  GuiceModuleAccess.BindingFactory _bindingFactory = new GuiceModuleAccess.BindingFactory();
  TypeReference _typeReference = new TypeReference("org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider");
  _bindingFactory.addTypeToType(_typeReference, 
    this.getQuickfixProviderClass(this.getGrammar())).contributeTo(this.getLanguage().getEclipsePluginGenModule());
  boolean _isGenerateStub = this.isGenerateStub();
  if (_isGenerateStub) {
    IBundleProjectConfig _eclipsePlugin = this.getProjectConfig().getEclipsePlugin();
    IXtextGeneratorFileSystemAccess _src = null;
    if (_eclipsePlugin!=null) {
      _src=_eclipsePlugin.getSrc();
    }
    boolean _tripleNotEquals = (_src != null);
    if (_tripleNotEquals) {
      boolean _isGenerateXtendStub = this.isGenerateXtendStub();
      if (_isGenerateXtendStub) {
        this.generateXtendQuickfixProvider();
      } else {
        this.generateJavaQuickfixProvider();
      }
    }
    ManifestAccess _manifest = this.getProjectConfig().getEclipsePlugin().getManifest();
    boolean _tripleNotEquals_1 = (_manifest != null);
    if (_tripleNotEquals_1) {
      Set<String> _exportedPackages = this.getProjectConfig().getEclipsePlugin().getManifest().getExportedPackages();
      String _packageName = this.getQuickfixProviderClass(this.getGrammar()).getPackageName();
      _exportedPackages.add(_packageName);
    }
    PluginXmlAccess _pluginXml = this.getProjectConfig().getEclipsePlugin().getPluginXml();
    boolean _tripleNotEquals_2 = (_pluginXml != null);
    if (_tripleNotEquals_2) {
      this.addRegistrationToPluginXml();
    }
  } else {
    IBundleProjectConfig _eclipsePlugin_1 = this.getProjectConfig().getEclipsePlugin();
    IXtextGeneratorFileSystemAccess _srcGen = null;
    if (_eclipsePlugin_1!=null) {
      _srcGen=_eclipsePlugin_1.getSrcGen();
    }
    boolean _tripleNotEquals_3 = (_srcGen != null);
    if (_tripleNotEquals_3) {
      this.generateGenQuickfixProvider();
    }
    ManifestAccess _manifest_1 = this.getProjectConfig().getEclipsePlugin().getManifest();
    boolean _tripleNotEquals_4 = (_manifest_1 != null);
    if (_tripleNotEquals_4) {
      Set<String> _exportedPackages_1 = this.getProjectConfig().getEclipsePlugin().getManifest().getExportedPackages();
      String _packageName_1 = this.getQuickfixProviderClass(this.getGrammar()).getPackageName();
      _exportedPackages_1.add(_packageName_1);
    }
  }
}
 
Example #27
Source File: AbstractAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void normalizeLineDelimiters(final IXtextGeneratorFileSystemAccess fsa, final TypeReference... types) {
  final Consumer<TypeReference> _function = (TypeReference it) -> {
    this.normalizeLineDelimiters(fsa, it);
  };
  ((List<TypeReference>)Conversions.doWrapArray(types)).forEach(_function);
}
 
Example #28
Source File: SubProjectConfig.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public IXtextGeneratorFileSystemAccess getMetaInf() {
	return metaInf;
}
 
Example #29
Source File: FragmentAdapter.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected Naming createNaming() {
  final IXtextGeneratorLanguage config2 = this.getLanguage();
  Naming _naming = new Naming();
  final Procedure1<Naming> _function = (Naming it) -> {
    IXtextGeneratorFileSystemAccess _root = this.getProjectConfig().getRuntime().getRoot();
    String _path = null;
    if (_root!=null) {
      _path=_root.getPath();
    }
    it.setProjectNameRt(this.getLastSegment(_path));
    IXtextGeneratorFileSystemAccess _root_1 = this.getProjectConfig().getGenericIde().getRoot();
    String _path_1 = null;
    if (_root_1!=null) {
      _path_1=_root_1.getPath();
    }
    it.setProjectNameIde(this.getLastSegment(_path_1));
    IXtextGeneratorFileSystemAccess _root_2 = this.getProjectConfig().getEclipsePlugin().getRoot();
    String _path_2 = null;
    if (_root_2!=null) {
      _path_2=_root_2.getPath();
    }
    it.setProjectNameUi(this.getLastSegment(_path_2));
    it.setIdeBasePackage(this._xtextGeneratorNaming.getGenericIdeBasePackage(config2.getGrammar()));
    it.setUiBasePackage(this._xtextGeneratorNaming.getEclipsePluginBasePackage(config2.getGrammar()));
    TypeReference _eclipsePluginActivator = this._xtextGeneratorNaming.getEclipsePluginActivator();
    String _name = null;
    if (_eclipsePluginActivator!=null) {
      _name=_eclipsePluginActivator.getName();
    }
    it.setActivatorName(_name);
    IXtextGeneratorFileSystemAccess _root_3 = this.getProjectConfig().getRuntimeTest().getRoot();
    String _path_3 = null;
    if (_root_3!=null) {
      _path_3=_root_3.getPath();
    }
    it.setPathTestProject(_path_3);
    it.setLineDelimiter(this.codeConfig.getLineDelimiter());
    it.setFileHeader(this.codeConfig.getFileHeader());
    it.setClassAnnotations(this.codeConfig.getClassAnnotationsAsString());
    it.setAnnotationImports(this.codeConfig.getAnnotationImportsAsString());
    String _projectNameUi = it.getProjectNameUi();
    boolean _tripleNotEquals = (_projectNameUi != null);
    it.setHasUI(_tripleNotEquals);
    String _projectNameIde = it.getProjectNameIde();
    boolean _tripleNotEquals_1 = (_projectNameIde != null);
    it.setHasIde(_tripleNotEquals_1);
    it.setGrammarId(config2.getGrammar().getName());
  };
  final Naming result = ObjectExtensions.<Naming>operator_doubleArrow(_naming, _function);
  if ((this.fragment instanceof NamingAware)) {
    ((NamingAware)this.fragment).registerNaming(result);
  }
  return result;
}
 
Example #30
Source File: ExternalAntlrLexerFragment.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void splitParserClassFile(IXtextGeneratorFileSystemAccess fsa, TypeReference parser) {
	// no-op
}