Java Code Examples for org.eclipse.xtext.xtext.generator.model.TypeReference#getSimpleName()

The following examples show how to use org.eclipse.xtext.xtext.generator.model.TypeReference#getSimpleName() . 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: SimpleProjectWizardFragment2.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void generateProjectInfo() {
  final TypeReference projectInfoClass = TypeReference.typeRef(this.getProjectInfoClassName());
  final JavaFileAccess file = this.fileAccessFactory.createJavaFile(projectInfoClass);
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("public class ");
      String _simpleName = projectInfoClass.getSimpleName();
      _builder.append(_simpleName);
      _builder.append(" extends ");
      TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ui.wizard.DefaultProjectInfo");
      _builder.append(_typeRef);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
    }
  };
  file.setContent(_client);
  file.writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}
 
Example 2
Source File: QuickfixProviderFragment2.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void generateGenQuickfixProvider() {
  final TypeReference genClass = this.getQuickfixProviderClass(this.getGrammar());
  final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(genClass);
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("public class ");
      String _simpleName = genClass.getSimpleName();
      _builder.append(_simpleName);
      _builder.append(" extends ");
      TypeReference _quickfixProviderSuperClass = QuickfixProviderFragment2.this.getQuickfixProviderSuperClass(QuickfixProviderFragment2.this.getGrammar());
      _builder.append(_quickfixProviderSuperClass);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.append("}");
      _builder.newLine();
    }
  };
  file.setContent(_client);
  file.writeTo(this.getProjectConfig().getEclipsePlugin().getSrcGen());
}
 
Example 3
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 4
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 5
Source File: ValidatorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected StringConcatenationClient generateValidationToDeprecateRules() {
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      {
        if (ValidatorFragment2.this.generateDeprecationValidation) {
          {
            List<AbstractRule> _deprecatedRulesFromGrammar = ValidatorFragment2.this.getDeprecatedRulesFromGrammar();
            for(final AbstractRule deprecatedRule : _deprecatedRulesFromGrammar) {
              EClassifier _classifier = deprecatedRule.getType().getClassifier();
              ResourceSet _resourceSet = ValidatorFragment2.this.getGrammar().eResource().getResourceSet();
              final TypeReference elementType = new TypeReference(((EClass) _classifier), _resourceSet);
              _builder.newLineIfNotEmpty();
              _builder.newLine();
              _builder.append("@");
              _builder.append(Check.class);
              _builder.newLineIfNotEmpty();
              _builder.append("public void checkDeprecated");
              String _simpleName = elementType.getSimpleName();
              _builder.append(_simpleName);
              _builder.append("(");
              _builder.append(elementType);
              _builder.append(" element) {");
              _builder.newLineIfNotEmpty();
              _builder.append("\t");
              _builder.append("addIssue(\"This part of the language is marked as deprecated and might get removed in the future!\", element, ");
              TypeReference _configurableIssueCodesProviderClass = ValidatorFragment2.this.getConfigurableIssueCodesProviderClass();
              _builder.append(_configurableIssueCodesProviderClass, "\t");
              _builder.append(".DEPRECATED_MODEL_PART);");
              _builder.newLineIfNotEmpty();
              _builder.append("}");
              _builder.newLine();
            }
          }
        }
      }
    }
  };
  return _client;
}
 
Example 6
Source File: SimpleProjectWizardFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void generateWizardNewProjectCreationPage() {
  final TypeReference mainPageClass = TypeReference.typeRef(this.getProjectWizardCreationPageClassName());
  final JavaFileAccess file = this.fileAccessFactory.createJavaFile(mainPageClass);
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("public class ");
      String _simpleName = mainPageClass.getSimpleName();
      _builder.append(_simpleName);
      _builder.append(" extends ");
      TypeReference _typeRef = TypeReference.typeRef("org.eclipse.ui.dialogs.WizardNewProjectCreationPage");
      _builder.append(_typeRef);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("public ");
      String _simpleName_1 = mainPageClass.getSimpleName();
      _builder.append(_simpleName_1, "\t");
      _builder.append("(String pageName) {");
      _builder.newLineIfNotEmpty();
      _builder.append("\t\t");
      _builder.append("super(pageName);");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
    }
  };
  file.setContent(_client);
  file.writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}
 
Example 7
Source File: SimpleProjectWizardFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void generateNewProjectWizardInitialContents() {
  final TypeReference initialContentsClass = TypeReference.typeRef(this.getProjectWizardInitialContentsClassName());
  final XtendFileAccess file = this.fileAccessFactory.createXtendFile(initialContentsClass);
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      _builder.append("import com.google.inject.Inject");
      _builder.newLine();
      _builder.append("import org.eclipse.xtext.generator.IFileSystemAccess2");
      _builder.newLine();
      _builder.append("import org.eclipse.xtext.resource.FileExtensionProvider");
      _builder.newLine();
      _builder.newLine();
      _builder.append("class ");
      String _simpleName = initialContentsClass.getSimpleName();
      _builder.append(_simpleName);
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("@Inject");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("FileExtensionProvider fileExtensionProvider");
      _builder.newLine();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("def generateInitialContents(IFileSystemAccess2 fsa) {");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("fsa.generateFile(");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("\"src/model/Model.\" + fileExtensionProvider.primaryFileExtension,");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("\'\'");
      _builder.append("\'");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("/*");
      _builder.newLine();
      _builder.append("\t\t\t ");
      _builder.append("* This is an example model");
      _builder.newLine();
      _builder.append("\t\t\t ");
      _builder.append("*/");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("Hello Xtext!");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("\'\'");
      _builder.append("\'");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append(")");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("}");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
    }
  };
  file.setContent(_client);
  file.writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}