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

The following examples show how to use org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess. 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: FragmentAdapter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private void generateGuiceModuleUi(final LanguageConfig config1, final XpandExecutionContext ctx) {
  final IXtextGeneratorLanguage config2 = this.getLanguage();
  final Set<Binding> bindings = this.fragment.getGuiceBindingsUi(config1.getGrammar());
  if ((bindings != null)) {
    final Function1<Binding, GuiceModuleAccess.Binding> _function = (Binding it) -> {
      return this.translateBinding(it);
    };
    config2.getEclipsePluginGenModule().addAll(IterableExtensions.<Binding, GuiceModuleAccess.Binding>map(bindings, _function));
  }
  if ((this.fragment instanceof IGeneratorFragmentExtension4)) {
    final String superClass = ((IGeneratorFragmentExtension4)this.fragment).getDefaultUiModuleClassName(config1.getGrammar());
    if ((superClass != null)) {
      GuiceModuleAccess _eclipsePluginGenModule = config2.getEclipsePluginGenModule();
      TypeReference _typeReference = new TypeReference(superClass);
      _eclipsePluginGenModule.setSuperClass(_typeReference);
    }
  }
}
 
Example #2
Source File: FragmentAdapter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private void generateGuiceModuleRt(final LanguageConfig config1, final XpandExecutionContext ctx) {
  final IXtextGeneratorLanguage config2 = this.getLanguage();
  final Set<Binding> bindings = this.fragment.getGuiceBindingsRt(config1.getGrammar());
  if ((bindings != null)) {
    final Function1<Binding, GuiceModuleAccess.Binding> _function = (Binding it) -> {
      return this.translateBinding(it);
    };
    config2.getRuntimeGenModule().addAll(IterableExtensions.<Binding, GuiceModuleAccess.Binding>map(bindings, _function));
  }
  if ((this.fragment instanceof IGeneratorFragmentExtension4)) {
    final String superClass = ((IGeneratorFragmentExtension4)this.fragment).getDefaultRuntimeModuleClassName(config1.getGrammar());
    if ((superClass != null)) {
      GuiceModuleAccess _runtimeGenModule = config2.getRuntimeGenModule();
      TypeReference _typeReference = new TypeReference(superClass);
      _runtimeGenModule.setSuperClass(_typeReference);
    }
  }
}
 
Example #3
Source File: BindingFactory.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Put the bindings to the associated module.
 */
public void contributeToModule() {
	final GuiceModuleAccess module = this.module.get();
	if (!this.removableBindings.isEmpty()) {
		// Ok, we are broking the Java secutiry manager.
		// But it's for having something working!
		try {
			final Field field = module.getClass().getDeclaredField("bindings"); //$NON-NLS-1$
			final boolean accessible = field.isAccessible();
			try {
				field.setAccessible(true);
				final Collection<?> hiddenBindings = (Collection<?>) field.get(module);
				hiddenBindings.removeAll(this.removableBindings);
			} finally {
				field.setAccessible(accessible);
			}
		} catch (Exception exception) {
			throw new IllegalStateException(exception);
		}
	}
	module.addAll(this.bindings);
}
 
Example #4
Source File: QualifiedNamesFragment2.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void generate() {
	new GuiceModuleAccess.BindingFactory()
			.addTypeToType(TypeReference.typeRef(IQualifiedNameProvider.class),
					TypeReference.typeRef(DefaultDeclarativeQualifiedNameProvider.class))
			.contributeTo(getLanguage().getRuntimeGenModule());
	new GuiceModuleAccess.BindingFactory()
			.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher"),
					TypeReference.typeRef("org.eclipse.xtext.ui.editor.contentassist.FQNPrefixMatcher"))
			.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ui.refactoring.IDependentElementsCalculator"),
					TypeReference
							.typeRef("org.eclipse.xtext.ui.refactoring.impl.DefaultDependentElementsCalculator"))
			.contributeTo(getLanguage().getEclipsePluginGenModule());
	new GuiceModuleAccess.BindingFactory()
			.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.IPrefixMatcher"),
					TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.FQNPrefixMatcher"))
			.contributeTo(getLanguage().getIdeGenModule());
}
 
Example #5
Source File: BindingFactory.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Bind an annotated element.
 *
 * @param bind the type to bind.
 * @param annotatedWith the annotation to consider.
 * @param to the instance.
 * @param functionName the optional function name.
 * @return the binding element.
 */
protected Binding bindAnnotatedWithToInstance(TypeReference bind, TypeReference annotatedWith, String to,
		String functionName) {
	final StringConcatenationClient client = new StringConcatenationClient() {
		@Override
		protected void appendTo(TargetStringConcatenation builder) {
			builder.append("binder.bind("); //$NON-NLS-1$
			builder.append(bind);
			builder.append(".class).annotatedWith("); //$NON-NLS-1$
			builder.append(annotatedWith);
			builder.append(".class).toInstance("); //$NON-NLS-1$
			builder.append(to);
			builder.append(".class);"); //$NON-NLS-1$
		}
	};
	String fctname = functionName;
	if (Strings.isEmpty(fctname)) {
		fctname = bind.getSimpleName();
	}
	final BindKey key = new GuiceModuleAccess.BindKey(formatFunctionName(fctname), null, false, false);
	final  BindValue statements = new BindValue(null, null, false, Collections.singletonList(client));
    return new Binding(key, statements, true, this.name);
}
 
Example #6
Source File: BindingFactory.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Bind an annotated element.
 *
 * @param bind the type to bind.
 * @param annotatedWith the annotation to consider.
 * @param to the target type.
 * @param functionName the optional function name.
 * @return the binding element.
 */
protected Binding bindAnnotatedWith(TypeReference bind, TypeReference annotatedWith, TypeReference to,
		String functionName) {
	final StringConcatenationClient client = new StringConcatenationClient() {
		@Override
		protected void appendTo(TargetStringConcatenation builder) {
			builder.append("binder.bind("); //$NON-NLS-1$
			builder.append(bind);
			builder.append(".class).annotatedWith("); //$NON-NLS-1$
			builder.append(annotatedWith);
			builder.append(".class).to("); //$NON-NLS-1$
			builder.append(to);
			builder.append(".class);"); //$NON-NLS-1$
		}
	};
	String fctname = functionName;
	if (Strings.isEmpty(fctname)) {
		fctname = bind.getSimpleName();
	}
	final BindKey key = new GuiceModuleAccess.BindKey(formatFunctionName(fctname), null, false, false);
	final  BindValue statements = new BindValue(null, null, false, Collections.singletonList(client));
    return new Binding(key, statements, true, this.name);
}
 
Example #7
Source File: InjectionRecommender2.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Provide the recommendations for the given module.
 *
 * @param superModule the super module to extract definitions from.
 * @param currentModuleAccess the accessor to the the current module's definition.
 */
protected void recommend(Class<?> superModule, GuiceModuleAccess currentModuleAccess) {
	LOG.info(MessageFormat.format("Building injection configuration from {0}", //$NON-NLS-1$
			superModule.getName()));
	final Set<BindingElement> superBindings = new LinkedHashSet<>();
	fillFrom(superBindings, superModule.getSuperclass());
	fillFrom(superBindings, superModule);

	final Set<Binding> currentBindings = currentModuleAccess.getBindings();

	recommendFrom(superModule.getName(), superBindings, currentBindings);
}
 
Example #8
Source File: BindingFactory.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Bind a type annotated with a name of the given value.
 *
 * @param bind the type to bind.
 * @param name the name to consider.
 * @param to the instance.
 * @param functionName the optional function name.
 * @return the binding element.
 */
protected Binding bindAnnotatedWithNameToInstance(TypeReference bind, String name, String to,
		String functionName) {
	String tmpName = Strings.emptyIfNull(name);
	if (tmpName.startsWith(REFERENCE_PREFIX)) {
		tmpName = tmpName.substring(REFERENCE_PREFIX.length()).trim();
	} else {
		tmpName = "\"" + tmpName + "\""; //$NON-NLS-1$//$NON-NLS-2$
	}
	final String unferencedName = tmpName;
	final StringConcatenationClient client = new StringConcatenationClient() {
		@Override
		protected void appendTo(TargetStringConcatenation builder) {
			builder.append("binder.bind("); //$NON-NLS-1$
			builder.append(bind);
			builder.append(".class).annotatedWith(Names.named("); //$NON-NLS-1$
			builder.append(unferencedName);
			builder.append(")).toInstance("); //$NON-NLS-1$
			builder.append(to);
			builder.append(".class);"); //$NON-NLS-1$
		}
	};
	String fctname = functionName;
	if (Strings.isEmpty(fctname)) {
		fctname = name;
	}
	final BindKey key = new GuiceModuleAccess.BindKey(formatFunctionName(fctname), null, false, false);
	final BindValue statements = new BindValue(null, null, false, Collections.singletonList(client));
    return new Binding(key, statements, true, this.name);
}
 
Example #9
Source File: BindingFactory.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Bind a type annotated with a name of the given value.
 *
 * @param bind the type to bind.
 * @param name the name to consider.
 * @param to the target type.
 * @param functionName the optional function name.
 * @return the binding element.
 */
protected Binding bindAnnotatedWithName(TypeReference bind, String name, TypeReference to,
		String functionName) {
	String tmpName = Strings.emptyIfNull(name);
	if (tmpName.startsWith(REFERENCE_PREFIX)) {
		tmpName = tmpName.substring(REFERENCE_PREFIX.length()).trim();
	} else {
		tmpName = "\"" + tmpName + "\""; //$NON-NLS-1$//$NON-NLS-2$
	}
	final String unferencedName = tmpName;
	final StringConcatenationClient client = new StringConcatenationClient() {
		@Override
		protected void appendTo(TargetStringConcatenation builder) {
			builder.append("binder.bind("); //$NON-NLS-1$
			builder.append(bind);
			builder.append(".class).annotatedWith(Names.named("); //$NON-NLS-1$
			builder.append(unferencedName);
			builder.append(")).to("); //$NON-NLS-1$
			builder.append(to);
			builder.append(".class);"); //$NON-NLS-1$
		}
	};
	String fctname = functionName;
	if (Strings.isEmpty(fctname)) {
		fctname = name;
	}
	final BindKey key = new GuiceModuleAccess.BindKey(formatFunctionName(fctname), null, false, false);
	final BindValue statements = new BindValue(null, null, false, Collections.singletonList(client));
    return new Binding(key, statements, true, this.name);
}
 
Example #10
Source File: InjectionFragment2.java    From sarl with Apache License 2.0 5 votes vote down vote up
private void bind(GuiceModuleAccess module, List<BindingElement> bindings) {
	final BindingFactory bindingFactory = this.injector.getInstance(BindingFactory.class);
	bindingFactory.setName(this.name);
	bindingFactory.setGuiceModule(module);
	for (final BindingElement element : bindings) {
		final Binding guiceBinding = bindingFactory.toBinding(element);
		bindingFactory.add(guiceBinding, isOverrideAll() || element.isOverride());
	}
	bindingFactory.contributeToModule();
}
 
Example #11
Source File: Formatter2Fragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate() {
  boolean _isGenerateStub = this.isGenerateStub();
  boolean _not = (!_isGenerateStub);
  if (_not) {
    return;
  }
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("binder.bind(");
      _builder.append(IPreferenceValuesProvider.class);
      _builder.append(".class).annotatedWith(");
      _builder.append(FormatterPreferences.class);
      _builder.append(".class).to(");
      _builder.append(FormatterPreferenceValuesProvider.class);
      _builder.append(".class);");
    }
  };
  final StringConcatenationClient statement = _client;
  new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef(IFormatter2.class), this.getFormatter2Stub(this.getLanguage().getGrammar())).addConfiguredBinding(FormatterPreferences.class.getSimpleName(), statement).contributeTo(this.getLanguage().getRuntimeGenModule());
  new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ui.editor.formatting.IContentFormatterFactory"), 
    TypeReference.typeRef("org.eclipse.xtext.ui.editor.formatting2.ContentFormatterFactory")).contributeTo(this.getLanguage().getEclipsePluginGenModule());
  ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
  boolean _tripleNotEquals = (_manifest != null);
  if (_tripleNotEquals) {
    Set<String> _exportedPackages = this.getProjectConfig().getRuntime().getManifest().getExportedPackages();
    String _runtimeBasePackage = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
    String _plus = (_runtimeBasePackage + ".formatting2");
    _exportedPackages.add(_plus);
  }
  this.doGenerateStubFile();
}
 
Example #12
Source File: XtextGeneratorTemplates.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private CharSequence getBindMethodName(final GuiceModuleAccess.Binding it) {
  StringConcatenation _builder = new StringConcatenation();
  {
    if (((!it.getValue().isProvider()) && it.getValue().getStatements().isEmpty())) {
      _builder.append("bind");
    } else {
      boolean _isEmpty = it.getValue().getStatements().isEmpty();
      if (_isEmpty) {
        _builder.append("provide");
      } else {
        _builder.append("configure");
      }
    }
  }
  String _elvis = null;
  String _name = it.getKey().getName();
  String _replace = null;
  if (_name!=null) {
    _replace=_name.replace(".", "$");
  }
  if (_replace != null) {
    _elvis = _replace;
  } else {
    String _simpleMethodName = this.getSimpleMethodName(it.getKey().getType());
    _elvis = _simpleMethodName;
  }
  _builder.append(_elvis);
  {
    if (((it.getValue().getExpression() != null) && (!it.getValue().isProvider()))) {
      _builder.append("ToInstance");
    }
  }
  return _builder;
}
 
Example #13
Source File: SerializerFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate() {
  new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef(ISemanticSequencer.class), this.getSemanticSequencerClass(this.getGrammar())).addTypeToType(TypeReference.typeRef(ISyntacticSequencer.class), this.getSyntacticSequencerClass(this.getGrammar())).addTypeToType(TypeReference.typeRef(ISerializer.class), TypeReference.typeRef(Serializer.class)).contributeTo(this.getLanguage().getRuntimeGenModule());
  ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
  boolean _tripleNotEquals = (_manifest != null);
  if (_tripleNotEquals) {
    Set<String> _exportedPackages = this.getProjectConfig().getRuntime().getManifest().getExportedPackages();
    String _serializerBasePackage = this.getSerializerBasePackage(this.getGrammar());
    _exportedPackages.add(_serializerBasePackage);
    Set<String> _requiredBundles = this.getProjectConfig().getRuntime().getManifest().getRequiredBundles();
    String _xbaseLibVersionLowerBound = this.getProjectConfig().getRuntime().getXbaseLibVersionLowerBound();
    String _plus = ("org.eclipse.xtext.xbase.lib;bundle-version=\"" + _xbaseLibVersionLowerBound);
    String _plus_1 = (_plus + "\"");
    _requiredBundles.add(_plus_1);
  }
  this.generateAbstractSemanticSequencer();
  this.generateAbstractSyntacticSequencer();
  boolean _isGenerateStub = this.isGenerateStub();
  if (_isGenerateStub) {
    this.generateSemanticSequencer();
    this.generateSyntacticSequencer();
  }
  if (this.generateDebugData) {
    this.generateGrammarConstraints();
    Iterable<Pair<String, String>> _generateDebugGraphs = this.debugGraphGenerator.generateDebugGraphs();
    for (final Pair<String, String> fileToContent : _generateDebugGraphs) {
      this.getProjectConfig().getRuntime().getSrcGen().generateFile(fileToContent.getKey(), fileToContent.getValue());
    }
  }
}
 
Example #14
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 #15
Source File: ResourceDescriptionStrategyFragment.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void contributeRuntimeGuiceBindings() {
  final GuiceModuleAccess.BindingFactory bindingFactory = new GuiceModuleAccess.BindingFactory();
  if ((this.isGenerateStub() || this.isGenerateXtendStub())) {
    bindingFactory.addTypeToType(TypeReference.typeRef(IDefaultResourceDescriptionStrategy.class), this.getStubResourceDescriptionStrategyClass());
  } else {
    bindingFactory.addTypeToType(TypeReference.typeRef(IDefaultResourceDescriptionStrategy.class), this.getDefaultResourceDescriptionStrategyClass());
  }
  bindingFactory.contributeTo(this.getLanguage().getRuntimeGenModule());
}
 
Example #16
Source File: GrammarAccessFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate() {
  final GuiceModuleAccess.BindingFactory bindingFactory = new GuiceModuleAccess.BindingFactory();
  String _name = this.getLanguage().getGrammar().getName();
  boolean _notEquals = (!Objects.equal(_name, "org.eclipse.xtext.common.Terminals"));
  if (_notEquals) {
    TypeReference _typeRef = TypeReference.typeRef(ClassLoader.class);
    StringConcatenationClient _client = new StringConcatenationClient() {
      @Override
      protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
        _builder.append("getClass().getClassLoader()");
      }
    };
    bindingFactory.addTypeToInstance(_typeRef, _client);
  }
  bindingFactory.addTypeToType(TypeReference.typeRef(IGrammarAccess.class), this._grammarAccessExtensions.getGrammarAccess(this.getLanguage().getGrammar())).contributeTo(this.getLanguage().getRuntimeGenModule());
  ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
  boolean _tripleNotEquals = (_manifest != null);
  if (_tripleNotEquals) {
    String _runtimeBasePackage = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
    String _runtimeBasePackage_1 = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
    String _plus = (_runtimeBasePackage_1 + ".services");
    this.getProjectConfig().getRuntime().getManifest().getExportedPackages().addAll(
      Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(_runtimeBasePackage, _plus)));
  }
  this.doGenerateGrammarAccess();
  this.writeGrammar();
}
 
Example #17
Source File: SimpleNamesFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate() {
	new GuiceModuleAccess.BindingFactory()
			.addfinalTypeToType(TypeReference.typeRef(IQualifiedNameProvider.class),
					TypeReference.typeRef(SimpleNameProvider.class))
			.contributeTo(getLanguage().getRuntimeGenModule());
	new GuiceModuleAccess.BindingFactory()
			.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ui.refactoring.IDependentElementsCalculator"),
					TypeReference
							.typeRef("org.eclipse.xtext.ui.refactoring.impl.DefaultDependentElementsCalculator"))
			.contributeTo(getLanguage().getEclipsePluginGenModule());
}
 
Example #18
Source File: Ecore2XtextValueConverterServiceFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void generate() {
	new GuiceModuleAccess.BindingFactory()
			.addTypeToType(TypeReference.typeRef(IValueConverterService.class),
					TypeReference.typeRef(Ecore2XtextTerminalConverters.class))
			.contributeTo(getLanguage().getRuntimeGenModule());
}
 
Example #19
Source File: ValidatorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.14
 */
protected void contributePluginGuiceBindings() {
  if ((this.generateDeprecationValidation || this.generatePropertyPage)) {
    final GuiceModuleAccess.BindingFactory bindingFactory = new GuiceModuleAccess.BindingFactory();
    bindingFactory.addTypeToType(this.getAbstractValidatorConfigurationBlockClass(), this.getValidatorConfigurationBlockClass());
    bindingFactory.contributeTo(this.getLanguage().getEclipsePluginGenModule());
  }
}
 
Example #20
Source File: ValidatorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.14
 */
protected void contributeRuntimeGuiceBindings() {
  final GuiceModuleAccess.BindingFactory bindingFactory = new GuiceModuleAccess.BindingFactory();
  bindingFactory.addTypeToTypeEagerSingleton(this._validatorNaming.getValidatorClass(this.getGrammar()), this._validatorNaming.getValidatorClass(this.getGrammar()));
  if ((this.generateDeprecationValidation || this.generatePropertyPage)) {
    bindingFactory.addTypeToType(this.getSuperConfigurableIssueCodesProviderClass(), this.getConfigurableIssueCodesProviderClass());
  }
  bindingFactory.contributeTo(this.getLanguage().getRuntimeGenModule());
}
 
Example #21
Source File: XtextGeneratorLanguage.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Pure
@Override
public GuiceModuleAccess getIdeGenModule() {
  return this.ideGenModule;
}
 
Example #22
Source File: FragmentAdapter.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
private GuiceModuleAccess.Binding translateBinding(final Binding it) {
  GuiceModuleAccess.Binding _xblockexpression = null;
  {
    GuiceModuleAccess.BindKey _xifexpression = null;
    if (((it.getValue().getStatements() == null) || ((List<String>)Conversions.doWrapArray(it.getValue().getStatements())).isEmpty())) {
      String _type = it.getKey().getType();
      TypeReference _guessTypeRef = null;
      if (_type!=null) {
        _guessTypeRef=TypeReference.guessTypeRef(_type);
      }
      boolean _isSingleton = it.getKey().isSingleton();
      boolean _isEagerSingleton = it.getKey().isEagerSingleton();
      _xifexpression = new GuiceModuleAccess.BindKey(null, _guessTypeRef, _isSingleton, _isEagerSingleton);
    } else {
      String _className = this.getClassName(it.getKey().getType());
      boolean _isSingleton_1 = it.getKey().isSingleton();
      boolean _isEagerSingleton_1 = it.getKey().isEagerSingleton();
      _xifexpression = new GuiceModuleAccess.BindKey(_className, null, _isSingleton_1, _isEagerSingleton_1);
    }
    final GuiceModuleAccess.BindKey newKey = _xifexpression;
    String _expression = it.getValue().getExpression();
    String _typeName = it.getValue().getTypeName();
    TypeReference _guessTypeRef_1 = null;
    if (_typeName!=null) {
      _guessTypeRef_1=TypeReference.guessTypeRef(_typeName);
    }
    boolean _isProvider = it.getValue().isProvider();
    final Function1<String, Object> _function = (String s) -> {
      String _xifexpression_1 = null;
      boolean _endsWith = s.endsWith(";");
      if (_endsWith) {
        _xifexpression_1 = s;
      } else {
        _xifexpression_1 = (s + ";");
      }
      return _xifexpression_1;
    };
    List<Object> _map = ListExtensions.<String, Object>map(((List<String>)Conversions.doWrapArray(it.getValue().getStatements())), _function);
    final GuiceModuleAccess.BindValue newValue = new GuiceModuleAccess.BindValue(_expression, _guessTypeRef_1, _isProvider, _map);
    boolean _isFinal = it.isFinal();
    String _contributedBy = it.getContributedBy();
    _xblockexpression = new GuiceModuleAccess.Binding(newKey, newValue, _isFinal, _contributedBy);
  }
  return _xblockexpression;
}
 
Example #23
Source File: XtextGeneratorLanguage.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Pure
@Override
public GuiceModuleAccess getWebGenModule() {
  return this.webGenModule;
}
 
Example #24
Source File: XtextGeneratorLanguage.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Pure
@Override
public GuiceModuleAccess getEclipsePluginGenModule() {
  return this.eclipsePluginGenModule;
}
 
Example #25
Source File: XtextAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void addIdeBindingsAndImports() {
  @Extension
  final ContentAssistGrammarNaming naming = this.contentAssistNaming;
  ManifestAccess _manifest = this.getProjectConfig().getGenericIde().getManifest();
  boolean _tripleNotEquals = (_manifest != null);
  if (_tripleNotEquals) {
    ManifestAccess _manifest_1 = this.getProjectConfig().getGenericIde().getManifest();
    final Procedure1<ManifestAccess> _function = (ManifestAccess it) -> {
      Set<String> _exportedPackages = it.getExportedPackages();
      String _packageName = naming.getLexerClass(this.getGrammar()).getPackageName();
      String _packageName_1 = naming.getParserClass(this.getGrammar()).getPackageName();
      String _packageName_2 = naming.getInternalParserClass(this.getGrammar()).getPackageName();
      Iterables.<String>addAll(_exportedPackages, Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(_packageName, _packageName_1, _packageName_2)));
      Set<String> _requiredBundles = it.getRequiredBundles();
      _requiredBundles.add("org.antlr.runtime;bundle-version=\"[3.2.0,3.2.1)\"");
    };
    ObjectExtensions.<ManifestAccess>operator_doubleArrow(_manifest_1, _function);
  }
  GuiceModuleAccess.BindingFactory _bindingFactory = new GuiceModuleAccess.BindingFactory();
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("binder.bind(");
      TypeReference _lexerSuperClass = naming.getLexerSuperClass(XtextAntlrGeneratorFragment2.this.getGrammar());
      _builder.append(_lexerSuperClass);
      _builder.append(".class)");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append(".annotatedWith(");
      _builder.append(Names.class, "\t");
      _builder.append(".named(");
      TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ide.LexerIdeBindings");
      _builder.append(_typeRef, "\t");
      _builder.append(".CONTENT_ASSIST))");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append(".to(");
      TypeReference _lexerClass = naming.getLexerClass(XtextAntlrGeneratorFragment2.this.getGrammar());
      _builder.append(_lexerClass, "\t");
      _builder.append(".class);");
      _builder.newLineIfNotEmpty();
    }
  };
  final GuiceModuleAccess.BindingFactory ideBindings = _bindingFactory.addConfiguredBinding("ContentAssistLexer", _client).addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.antlr.IContentAssistParser"), naming.getParserClass(this.getGrammar())).addTypeToType(
    TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.IProposalConflictHelper"), 
    TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.antlr.AntlrProposalConflictHelper"));
  if (this.partialParsing) {
    ideBindings.addTypeToType(
      TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory"), 
      TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.antlr.PartialContentAssistContextFactory"));
  }
  boolean _hasSyntheticTerminalRule = this.hasSyntheticTerminalRule();
  if (_hasSyntheticTerminalRule) {
    ideBindings.addTypeToType(
      TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.CompletionPrefixProvider"), 
      TypeReference.typeRef("org.eclipse.xtext.ide.editor.contentassist.IndentationAwareCompletionPrefixProvider"));
  }
  ideBindings.contributeTo(this.getLanguage().getIdeGenModule());
}
 
Example #26
Source File: XtextGeneratorLanguage.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Pure
@Override
public GuiceModuleAccess getRuntimeGenModule() {
  return this.runtimeGenModule;
}
 
Example #27
Source File: GeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void generate() {
  boolean _isGenerateStub = this.isGenerateStub();
  if (_isGenerateStub) {
    new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef(IGenerator2.class), this.getGeneratorStub(this.getLanguage().getGrammar())).contributeTo(this.getLanguage().getRuntimeGenModule());
    ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
    boolean _tripleNotEquals = (_manifest != null);
    if (_tripleNotEquals) {
      Set<String> _requiredBundles = this.getProjectConfig().getRuntime().getManifest().getRequiredBundles();
      String _xbaseLibVersionLowerBound = this.getProjectConfig().getRuntime().getXbaseLibVersionLowerBound();
      String _plus = ("org.eclipse.xtext.xbase.lib;bundle-version=\"" + _xbaseLibVersionLowerBound);
      String _plus_1 = (_plus + "\"");
      _requiredBundles.add(_plus_1);
    }
    boolean _isGenerateXtendStub = this.isGenerateXtendStub();
    if (_isGenerateXtendStub) {
      this.doGenerateXtendStubFile();
    } else {
      this.doGenerateJavaStubFile();
    }
  }
  if ((this.isGenerateStub() || this.isGenerateJavaMain())) {
    ManifestAccess _manifest_1 = this.getProjectConfig().getRuntime().getManifest();
    boolean _tripleNotEquals_1 = (_manifest_1 != null);
    if (_tripleNotEquals_1) {
      Set<String> _exportedPackages = this.getProjectConfig().getRuntime().getManifest().getExportedPackages();
      String _packageName = this.getGeneratorStub(this.getLanguage().getGrammar()).getPackageName();
      _exportedPackages.add(_packageName);
    }
  }
  boolean _isGenerateJavaMain = this.isGenerateJavaMain();
  if (_isGenerateJavaMain) {
    this.doGenerateJavaMain();
  }
  boolean _isGenerateXtendMain = this.isGenerateXtendMain();
  if (_isGenerateXtendMain) {
    this.doGenerateXtendMain();
  }
  boolean _isGenerateMwe = this.isGenerateMwe();
  if (_isGenerateMwe) {
    this.doGenerateMweFile();
  }
  this.contributeEclipsePluginGuiceBindings();
  ManifestAccess _manifest_2 = this.getProjectConfig().getEclipsePlugin().getManifest();
  boolean _tripleNotEquals_2 = (_manifest_2 != null);
  if (_tripleNotEquals_2) {
    Set<String> _requiredBundles_1 = this.getProjectConfig().getEclipsePlugin().getManifest().getRequiredBundles();
    _requiredBundles_1.add("org.eclipse.xtext.builder");
  }
  PluginXmlAccess _pluginXml = this.getProjectConfig().getEclipsePlugin().getPluginXml();
  boolean _tripleNotEquals_3 = (_pluginXml != null);
  if (_tripleNotEquals_3) {
    this.contributeEclipsePluginExtensions();
  }
}
 
Example #28
Source File: ImplicitFragment.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void generate() {
  ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
  boolean _tripleNotEquals = (_manifest != null);
  if (_tripleNotEquals) {
    this.getProjectConfig().getRuntime().getManifest().getRequiredBundles().addAll(
      Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("org.eclipse.xtext", "org.eclipse.xtext.util")));
    boolean _isGenerateXtendStub = this.isGenerateXtendStub();
    if (_isGenerateXtendStub) {
      Set<String> _requiredBundles = this.getProjectConfig().getRuntime().getManifest().getRequiredBundles();
      String _xtendLibVersionLowerBound = this.getProjectConfig().getRuntime().getXtendLibVersionLowerBound();
      String _plus = ("org.eclipse.xtend.lib;bundle-version=\"" + _xtendLibVersionLowerBound);
      String _plus_1 = (_plus + "\"");
      _requiredBundles.add(_plus_1);
    }
    this.getProjectConfig().getRuntime().getManifest().getImportedPackages().add("org.apache.log4j");
  }
  ManifestAccess _manifest_1 = this.getProjectConfig().getEclipsePlugin().getManifest();
  boolean _tripleNotEquals_1 = (_manifest_1 != null);
  if (_tripleNotEquals_1) {
    this.getProjectConfig().getEclipsePlugin().getManifest().getRequiredBundles().addAll(
      Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("org.eclipse.xtext.ui", "org.eclipse.xtext.ui.shared", "org.eclipse.ui.editors", "org.eclipse.ui")));
    boolean _isGenerateXtendStub_1 = this.isGenerateXtendStub();
    if (_isGenerateXtendStub_1) {
      Set<String> _requiredBundles_1 = this.getProjectConfig().getEclipsePlugin().getManifest().getRequiredBundles();
      String _xtendLibVersionLowerBound_1 = this.getProjectConfig().getRuntime().getXtendLibVersionLowerBound();
      String _plus_2 = ("org.eclipse.xtend.lib;bundle-version=\"" + _xtendLibVersionLowerBound_1);
      String _plus_3 = (_plus_2 + "\"");
      _requiredBundles_1.add(_plus_3);
    }
    this.getProjectConfig().getEclipsePlugin().getManifest().getImportedPackages().add("org.apache.log4j");
  }
  PluginXmlAccess _pluginXml = this.getProjectConfig().getEclipsePlugin().getPluginXml();
  boolean _tripleNotEquals_2 = (_pluginXml != null);
  if (_tripleNotEquals_2) {
    List<CharSequence> _entries = this.getProjectConfig().getEclipsePlugin().getPluginXml().getEntries();
    CharSequence _implicitPluginXmlEnties = this.getImplicitPluginXmlEnties(this.getGrammar());
    _entries.add(_implicitPluginXmlEnties);
  }
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ui.shared.Access");
      _builder.append(_typeRef);
      _builder.append(".getJavaProjectsState()");
    }
  };
  final StringConcatenationClient expression = _client;
  final GuiceModuleAccess.BindingFactory bindingFactory = new GuiceModuleAccess.BindingFactory().addTypeToProviderInstance(TypeReference.typeRef(IAllContainersState.class), expression);
  boolean _inheritsXbase = this._xbaseUsageDetector.inheritsXbase(this.getGrammar());
  if (_inheritsXbase) {
    bindingFactory.addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ui.editor.model.XtextDocumentProvider"), 
      TypeReference.typeRef("org.eclipse.xtext.xbase.ui.editor.XbaseDocumentProvider")).addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ui.generator.trace.OpenGeneratedFileHandler"), 
      TypeReference.typeRef("org.eclipse.xtext.xbase.ui.generator.trace.XbaseOpenGeneratedFileHandler"));
  }
  bindingFactory.contributeTo(this.getLanguage().getEclipsePluginGenModule());
}
 
Example #29
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 #30
Source File: SimpleProjectWizardFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void generate() {
  if ((!this.generate)) {
    return;
  }
  IBundleProjectConfig _eclipsePlugin = this.getProjectConfig().getEclipsePlugin();
  ManifestAccess _manifest = null;
  if (_eclipsePlugin!=null) {
    _manifest=_eclipsePlugin.getManifest();
  }
  boolean _tripleNotEquals = (_manifest != null);
  if (_tripleNotEquals) {
    Set<String> _requiredBundles = this.getProjectConfig().getEclipsePlugin().getManifest().getRequiredBundles();
    Iterables.<String>addAll(_requiredBundles, Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("org.eclipse.ui", "org.eclipse.core.runtime", "org.eclipse.core.resources", "org.eclipse.ui.ide")));
  }
  GuiceModuleAccess.BindingFactory _bindingFactory = new GuiceModuleAccess.BindingFactory();
  TypeReference _typeReference = new TypeReference("org.eclipse.xtext.ui.wizard.IProjectCreator");
  String _projectCreatorClassName = this.getProjectCreatorClassName();
  TypeReference _typeReference_1 = new TypeReference(_projectCreatorClassName);
  _bindingFactory.addTypeToType(_typeReference, _typeReference_1).contributeTo(this.getLanguage().getEclipsePluginGenModule());
  IBundleProjectConfig _eclipsePlugin_1 = this.getProjectConfig().getEclipsePlugin();
  PluginXmlAccess _pluginXml = null;
  if (_eclipsePlugin_1!=null) {
    _pluginXml=_eclipsePlugin_1.getPluginXml();
  }
  boolean _tripleNotEquals_1 = (_pluginXml != null);
  if (_tripleNotEquals_1) {
    List<CharSequence> _entries = this.getProjectConfig().getEclipsePlugin().getPluginXml().getEntries();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("<extension");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("point=\"org.eclipse.ui.newWizards\">");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("<wizard");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("category=\"org.eclipse.xtext.projectwiz\"");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("class=\"");
    TypeReference _eclipsePluginExecutableExtensionFactory = this._xtextGeneratorNaming.getEclipsePluginExecutableExtensionFactory(this.getGrammar());
    _builder.append(_eclipsePluginExecutableExtensionFactory, "\t\t");
    _builder.append(":");
    String _projectWizardClassName = this.getProjectWizardClassName();
    _builder.append(_projectWizardClassName, "\t\t");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("id=\"");
    String _projectWizardClassName_1 = this.getProjectWizardClassName();
    _builder.append(_projectWizardClassName_1, "\t\t");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("name=\"");
    String _simpleName = GrammarUtil.getSimpleName(this.getGrammar());
    _builder.append(_simpleName, "\t\t");
    _builder.append(" Project\"");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("project=\"true\">");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("</wizard>");
    _builder.newLine();
    _builder.append("</extension>");
    _builder.newLine();
    _entries.add(_builder.toString());
  }
  this.generateProjectInfo();
  this.generateWizardNewProjectCreationPage();
  this.generateNewProjectWizardInitialContents();
  this.generateProjectCreator();
  this.generateNewProjectWizard();
}