Java Code Examples for org.eclipse.xtend2.lib.StringConcatenationClient#TargetStringConcatenation
The following examples show how to use
org.eclipse.xtend2.lib.StringConcatenationClient#TargetStringConcatenation .
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: TemplateNodeTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testIndentedIf() { final boolean condition = true; final String string = "foo"; StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("Very wise:"); _builder.newLine(); { if (condition) { _builder.append("\t"); _builder.append("who "); _builder.append(string, "\t"); _builder.append(" do"); _builder.newLineIfNotEmpty(); } } } }; this.assertEquals(_client); }
Example 2
Source File: AddInterfaceWithDefaultProcessor.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) { super.doTransform(annotatedClass, context); Type _findTypeGlobally = context.findTypeGlobally("de.test.Test"); final MutableInterfaceDeclaration ifType = ((MutableInterfaceDeclaration) _findTypeGlobally); final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> { StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("System.out.println(\"Hello World\");"); } }; it.setBody(_client); it.setDefault(true); }; ifType.addMethod("sayHello", _function); }
Example 3
Source File: GrammarAccessFragment2.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected StringConcatenationClient _initializer(final EnumRule it) { StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("this."); String _gaRuleAccessorLocalVarName = GrammarAccessFragment2.this.gaRuleAccessorLocalVarName(it); _builder.append(_gaRuleAccessorLocalVarName); _builder.append(" = new "); String _gaRuleAccessorClassName = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessorClassName(it); _builder.append(_gaRuleAccessorClassName); _builder.append("();"); _builder.newLineIfNotEmpty(); } }; return _client; }
Example 4
Source File: TracingSugarTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public StringConcatenationClient __generateType(final Type it) { StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("Class "); IGeneratorNode __name = TracingSugarTest.this._myExtensions._name(it); _builder.append(__name); _builder.append(" {"); _builder.newLineIfNotEmpty(); { EList<Property> _properties = it.getProperties(); for(final Property p : _properties) { _builder.append("\t"); IGeneratorNode __generateProperty = TracingSugarTest.this._generateProperty(p); _builder.append(__generateProperty, "\t"); _builder.newLineIfNotEmpty(); } } _builder.append("}"); _builder.newLine(); } }; return _client; }
Example 5
Source File: TemplateNodeTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testSimpleString() { StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("fooo bar"); _builder.newLine(); } }; this.assertEquals(_client); }
Example 6
Source File: Formatter2Fragment2.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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 7
Source File: SerializerFragment2.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private StringConcatenationClient genMethodCreateSequenceCall(final Map<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint> superConstraints, final EClass type, final IGrammarConstraintProvider.IConstraint key) { StringConcatenationClient _xblockexpression = null; { final IGrammarConstraintProvider.IConstraint superConstraint = superConstraints.get(key); IGrammarConstraintProvider.IConstraint _elvis = null; if (superConstraint != null) { _elvis = superConstraint; } else { _elvis = key; } final IGrammarConstraintProvider.IConstraint constraint = _elvis; StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("sequence_"); String _simpleName = constraint.getSimpleName(); _builder.append(_simpleName); _builder.append("(context, ("); _builder.append(type); _builder.append(") semanticObject); "); _builder.newLineIfNotEmpty(); _builder.append("return; "); _builder.newLine(); } }; _xblockexpression = _client; } return _xblockexpression; }
Example 8
Source File: MutableJvmFieldDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public void setConstantValueAsFloat(final float value) { this.internalGenericSetConstantValue(Float.valueOf(value)); StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append(value); _builder.append("f"); } }; this.getCompilationUnit().setCompilationTemplate(this.getDelegate(), _client); }
Example 9
Source File: MutableJvmFieldDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public void setConstantValueAsLong(final long value) { this.internalGenericSetConstantValue(Long.valueOf(value)); StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append(value); _builder.append("L"); } }; this.getCompilationUnit().setCompilationTemplate(this.getDelegate(), _client); }
Example 10
Source File: GeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void doGenerateJavaStubFile() { TypeReference _generatorStub = this.getGeneratorStub(this.getGrammar()); StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("/**"); _builder.newLine(); _builder.append(" "); _builder.append("* Generates code from your model files on save."); _builder.newLine(); _builder.append(" "); _builder.append("* "); _builder.newLine(); _builder.append(" "); _builder.append("* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation"); _builder.newLine(); _builder.append(" "); _builder.append("*/"); _builder.newLine(); _builder.append("public class "); String _simpleName = GeneratorFragment2.this.getGeneratorStub(GeneratorFragment2.this.getLanguage().getGrammar()).getSimpleName(); _builder.append(_simpleName); _builder.append(" extends "); _builder.append(AbstractGenerator.class); _builder.append(" {"); _builder.newLineIfNotEmpty(); _builder.newLine(); _builder.append("\t"); _builder.append("@"); _builder.append(Override.class, "\t"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("public void doGenerate("); _builder.append(Resource.class, "\t"); _builder.append(" resource, "); _builder.append(IFileSystemAccess2.class, "\t"); _builder.append(" fsa, "); _builder.append(IGeneratorContext.class, "\t"); _builder.append(" context) {"); _builder.newLineIfNotEmpty(); _builder.append("//\t\tIterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class);"); _builder.newLine(); _builder.append("//\t\tIterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() {"); _builder.newLine(); _builder.append("//"); _builder.newLine(); _builder.append("//\t\t\t@"); _builder.append(Override.class); _builder.newLineIfNotEmpty(); _builder.append("//\t\t\tpublic String apply(Greeting greeting) {"); _builder.newLine(); _builder.append("//\t\t\t\treturn greeting.getName();"); _builder.newLine(); _builder.append("//\t\t\t}"); _builder.newLine(); _builder.append("//\t\t});"); _builder.newLine(); _builder.append("//\t\tfsa.generateFile(\"greetings.txt\", \"People to greet: \" + IteratorExtensions.join(names, \", \"));"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); } }; this.fileAccessFactory.createJavaFile(_generatorStub, _client).writeTo(this.getProjectConfig().getRuntime().getSrc()); }
Example 11
Source File: QuickfixProviderFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void generateXtendQuickfixProvider() { TypeReference _quickfixProviderClass = this.getQuickfixProviderClass(this.getGrammar()); StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("/**"); _builder.newLine(); _builder.append(" "); _builder.append("* Custom quickfixes."); _builder.newLine(); _builder.append(" "); _builder.append("*"); _builder.newLine(); _builder.append(" "); _builder.append("* See https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#quick-fixes"); _builder.newLine(); _builder.append(" "); _builder.append("*/"); _builder.newLine(); _builder.append("class "); String _simpleName = QuickfixProviderFragment2.this.getQuickfixProviderClass(QuickfixProviderFragment2.this.getGrammar()).getSimpleName(); _builder.append(_simpleName); _builder.append(" extends "); TypeReference _quickfixProviderSuperClass = QuickfixProviderFragment2.this.getQuickfixProviderSuperClass(QuickfixProviderFragment2.this.getGrammar()); _builder.append(_quickfixProviderSuperClass); _builder.append(" {"); _builder.newLineIfNotEmpty(); _builder.newLine(); _builder.append("//\t@Fix("); String _simpleName_1 = QuickfixProviderFragment2.this._validatorNaming.getValidatorClass(QuickfixProviderFragment2.this.getGrammar()).getSimpleName(); _builder.append(_simpleName_1); _builder.append(".INVALID_NAME)"); _builder.newLineIfNotEmpty(); _builder.append("//\tdef capitalizeName(Issue issue, IssueResolutionAcceptor acceptor) {"); _builder.newLine(); _builder.append("//\t\tacceptor.accept(issue, \'Capitalize name\', \'Capitalize the name.\', \'upcase.png\') ["); _builder.newLine(); _builder.append("//\t\t\tcontext |"); _builder.newLine(); _builder.append("//\t\t\tval xtextDocument = context.xtextDocument"); _builder.newLine(); _builder.append("//\t\t\tval firstLetter = xtextDocument.get(issue.offset, 1)"); _builder.newLine(); _builder.append("//\t\t\txtextDocument.replace(issue.offset, 1, firstLetter.toUpperCase)"); _builder.newLine(); _builder.append("//\t\t]"); _builder.newLine(); _builder.append("//\t}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); } }; this.fileAccessFactory.createXtendFile(_quickfixProviderClass, _client).writeTo(this.getProjectConfig().getEclipsePlugin().getSrc()); }
Example 12
Source File: GrammarAccessFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected StringConcatenationClient _getter(final EnumRule it, final Grammar original) { StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { String _grammarFragmentToString = GrammarAccessFragment2.this._grammarAccessExtensions.grammarFragmentToString(it, "//"); _builder.append(_grammarFragmentToString); _builder.newLineIfNotEmpty(); { Grammar _grammar = GrammarUtil.getGrammar(it); boolean _tripleEquals = (_grammar == original); if (_tripleEquals) { _builder.append("public "); String _gaRuleAccessorClassName = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessorClassName(it); _builder.append(_gaRuleAccessorClassName); _builder.append(" "); String _gaElementsAccessor = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementsAccessor(it); _builder.append(_gaElementsAccessor); _builder.append(" {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("return "); String _gaRuleAccessorLocalVarName = GrammarAccessFragment2.this.gaRuleAccessorLocalVarName(it); _builder.append(_gaRuleAccessorLocalVarName, "\t"); _builder.append(";"); _builder.newLineIfNotEmpty(); _builder.append("}"); _builder.newLine(); } else { _builder.append("public "); TypeReference _grammarAccess = GrammarAccessFragment2.this._grammarAccessExtensions.getGrammarAccess(GrammarUtil.getGrammar(it)); _builder.append(_grammarAccess); _builder.append("."); String _gaRuleAccessorClassName_1 = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessorClassName(it); _builder.append(_gaRuleAccessorClassName_1); _builder.append(" "); String _gaElementsAccessor_1 = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementsAccessor(it); _builder.append(_gaElementsAccessor_1); _builder.append(" {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("return "); String _gaGrammarAccessLocalVarName = GrammarAccessFragment2.this.gaGrammarAccessLocalVarName(GrammarUtil.getGrammar(it)); _builder.append(_gaGrammarAccessLocalVarName, "\t"); _builder.append("."); String _gaElementsAccessor_2 = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementsAccessor(it); _builder.append(_gaElementsAccessor_2, "\t"); _builder.append(";"); _builder.newLineIfNotEmpty(); _builder.append("}"); _builder.newLine(); } } _builder.newLine(); _builder.append("public "); _builder.append(EnumRule.class); _builder.append(" "); String _gaRuleAccessor = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessor(it); _builder.append(_gaRuleAccessor); _builder.append(" {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("return "); String _gaElementsAccessor_3 = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementsAccessor(it); _builder.append(_gaElementsAccessor_3, "\t"); _builder.append(".getRule();"); _builder.newLineIfNotEmpty(); _builder.append("}"); _builder.newLine(); } }; return _client; }
Example 13
Source File: GrammarAccessFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected StringConcatenationClient parserRuleClasses(final EnumRule it) { StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("public class "); String _gaRuleAccessorClassName = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessorClassName(it); _builder.append(_gaRuleAccessorClassName); _builder.append(" extends "); _builder.append(AbstractElementFinder.AbstractEnumRuleElementFinder.class); _builder.append(" {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("private final "); _builder.append(EnumRule.class, "\t"); _builder.append(" rule = ("); _builder.append(EnumRule.class, "\t"); _builder.append(") "); _builder.append(GrammarUtil.class, "\t"); _builder.append(".findRuleForName(getGrammar(), \""); String _qualifiedName = GrammarAccessFragment2.this.getQualifiedName(it); _builder.append(_qualifiedName, "\t"); _builder.append("\");"); _builder.newLineIfNotEmpty(); { List<AbstractElement> _containedAbstractElements = GrammarUtil.containedAbstractElements(it); for(final AbstractElement e : _containedAbstractElements) { _builder.append("\t"); _builder.append("private final "); TypeReference _typeRef = TypeReference.typeRef(e.eClass(), GrammarAccessFragment2.this.getLanguage()); _builder.append(_typeRef, "\t"); _builder.append(" "); String _gaElementAccessorLocalVarName = GrammarAccessFragment2.this.gaElementAccessorLocalVarName(e); _builder.append(_gaElementAccessorLocalVarName, "\t"); _builder.append(" = "); StringConcatenationClient _loadElementStatement = GrammarAccessFragment2.this.loadElementStatement(e); _builder.append(_loadElementStatement, "\t"); _builder.append(";"); _builder.newLineIfNotEmpty(); } } _builder.append("\t"); _builder.newLine(); _builder.append("\t"); String _grammarFragmentToString = GrammarAccessFragment2.this._grammarAccessExtensions.grammarFragmentToString(it, "//"); _builder.append(_grammarFragmentToString, "\t"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("public EnumRule getRule() { return rule; }"); _builder.newLine(); { List<AbstractElement> _containedAbstractElements_1 = GrammarUtil.containedAbstractElements(it); for(final AbstractElement e_1 : _containedAbstractElements_1) { _builder.append("\t"); _builder.newLine(); _builder.append("\t"); String _grammarFragmentToString_1 = GrammarAccessFragment2.this._grammarAccessExtensions.grammarFragmentToString(e_1, "//"); _builder.append(_grammarFragmentToString_1, "\t"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("public "); TypeReference _typeRef_1 = TypeReference.typeRef(e_1.eClass(), GrammarAccessFragment2.this.getLanguage()); _builder.append(_typeRef_1, "\t"); _builder.append(" "); String _gaElementAccessMethodName = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementAccessMethodName(e_1); _builder.append(_gaElementAccessMethodName, "\t"); _builder.append("() { return "); String _gaElementAccessorLocalVarName_1 = GrammarAccessFragment2.this.gaElementAccessorLocalVarName(e_1); _builder.append(_gaElementAccessorLocalVarName_1, "\t"); _builder.append("; }"); _builder.newLineIfNotEmpty(); } } _builder.append("}"); _builder.newLine(); } }; return _client; }
Example 14
Source File: LabelProviderFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void generateXtendDescriptionLabelProvider() { TypeReference _descriptionLabelProviderClass = this.getDescriptionLabelProviderClass(this.getGrammar()); StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("/**"); _builder.newLine(); _builder.append(" "); _builder.append("* Provides labels for IEObjectDescriptions and IResourceDescriptions."); _builder.newLine(); _builder.append(" "); _builder.append("* "); _builder.newLine(); _builder.append(" "); _builder.append("* See https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#label-provider"); _builder.newLine(); _builder.append(" "); _builder.append("*/"); _builder.newLine(); _builder.append("class "); String _simpleName = LabelProviderFragment2.this.getDescriptionLabelProviderClass(LabelProviderFragment2.this.getGrammar()).getSimpleName(); _builder.append(_simpleName); _builder.append(" extends "); TypeReference _descriptionLabelProviderSuperClass = LabelProviderFragment2.this.getDescriptionLabelProviderSuperClass(LabelProviderFragment2.this.getGrammar()); _builder.append(_descriptionLabelProviderSuperClass); _builder.append(" {"); _builder.newLineIfNotEmpty(); _builder.newLine(); _builder.append("\t"); _builder.append("// Labels and icons can be computed like this:"); _builder.newLine(); _builder.append("\t"); _builder.newLine(); _builder.append("//\toverride text(IEObjectDescription ele) {"); _builder.newLine(); _builder.append("//\t\tele.name.toString"); _builder.newLine(); _builder.append("//\t}"); _builder.newLine(); _builder.append("//\t "); _builder.newLine(); _builder.append("//\toverride image(IEObjectDescription ele) {"); _builder.newLine(); _builder.append("//\t\tele.EClass.name + \'.gif\'"); _builder.newLine(); _builder.append("//\t}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); } }; this.fileAccessFactory.createXtendFile(_descriptionLabelProviderClass, _client).writeTo(this.getProjectConfig().getEclipsePlugin().getSrc()); }
Example 15
Source File: SerializerFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
private StringConcatenationClient genEmitUnassignedTokens() { StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("@Override"); _builder.newLine(); _builder.append("protected void emitUnassignedTokens("); _builder.append(EObject.class); _builder.append(" semanticObject, "); _builder.append(ISyntacticSequencerPDAProvider.ISynTransition.class); _builder.append(" transition, "); _builder.append(INode.class); _builder.append(" fromNode, "); _builder.append(INode.class); _builder.append(" toNode) {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("if (transition.getAmbiguousSyntaxes().isEmpty()) return;"); _builder.newLine(); _builder.append("\t"); _builder.append(List.class, "\t"); _builder.append("<"); _builder.append(INode.class, "\t"); _builder.append("> transitionNodes = collectNodes(fromNode, toNode);"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("for ("); _builder.append(GrammarAlias.AbstractElementAlias.class, "\t"); _builder.append(" syntax : transition.getAmbiguousSyntaxes()) {"); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.append(List.class, "\t\t"); _builder.append("<"); _builder.append(INode.class, "\t\t"); _builder.append("> syntaxNodes = getNodesFor(transitionNodes, syntax);"); _builder.newLineIfNotEmpty(); { Iterable<Pair<Integer, EqualAmbiguousTransitions>> _indexed = IterableExtensions.<EqualAmbiguousTransitions>indexed(SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax()); for(final Pair<Integer, EqualAmbiguousTransitions> group : _indexed) { _builder.append("\t\t"); { Integer _key = group.getKey(); boolean _greaterThan = ((_key).intValue() > 0); if (_greaterThan) { _builder.append("else "); } } _builder.append("if (match_"); String _identifier = group.getValue().getIdentifier(); _builder.append(_identifier, "\t\t"); _builder.append(".equals(syntax))"); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.append("\t"); _builder.append("emit_"); String _identifier_1 = group.getValue().getIdentifier(); _builder.append(_identifier_1, "\t\t\t"); _builder.append("(semanticObject, getLastNavigableState(), syntaxNodes);"); _builder.newLineIfNotEmpty(); } } _builder.append("\t\t"); { boolean _isEmpty = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax().isEmpty(); boolean _not = (!_isEmpty); if (_not) { _builder.append("else "); } } _builder.append("acceptNodes(getLastNavigableState(), syntaxNodes);"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); } }; return _client; }
Example 16
Source File: ResourceDescriptionStrategyFragment.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected JavaFileAccess generateResourceDescriptionStrategy(final Iterable<AbstractRule> exportedRules) { TypeReference _abstractResourceDescriptionStrategyClass = this.getAbstractResourceDescriptionStrategyClass(); StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("public class "); String _simpleName = ResourceDescriptionStrategyFragment.this.getSuperTypeRef().getSimpleName(); _builder.append(_simpleName); _builder.append(" extends "); TypeReference _resourceDescriptionSuperClass = ResourceDescriptionStrategyFragment.this.getResourceDescriptionSuperClass(); _builder.append(_resourceDescriptionSuperClass); _builder.append(" {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("public boolean createEObjectDescriptions("); _builder.append(EObject.class, "\t"); _builder.append(" eObject, "); _builder.append(IAcceptor.class, "\t"); _builder.append("<"); _builder.append(IEObjectDescription.class, "\t"); _builder.append("> acceptor) {"); _builder.newLineIfNotEmpty(); { for(final AbstractRule exportedRule : exportedRules) { _builder.append("\t\t"); _builder.append("if(eObject instanceof "); EClassifier _classifier = exportedRule.getType().getClassifier(); ResourceSet _resourceSet = ResourceDescriptionStrategyFragment.this.getGrammar().eResource().getResourceSet(); TypeReference _typeReference = new TypeReference(((EClass) _classifier), _resourceSet); _builder.append(_typeReference, "\t\t"); _builder.append(") {"); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.append("\t"); _builder.append("return createEObjectDescriptionsFor"); String _name = exportedRule.getType().getClassifier().getName(); _builder.append(_name, "\t\t\t"); _builder.append("(eObject, acceptor);"); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.append("}"); _builder.newLine(); } } { boolean _needsToInvokeSuperResourceDescriptionStrategy = ResourceDescriptionStrategyFragment.this.needsToInvokeSuperResourceDescriptionStrategy(); if (_needsToInvokeSuperResourceDescriptionStrategy) { _builder.append("\t\t"); _builder.append("return super.createEObjectDescriptions(eObject, acceptor);"); _builder.newLine(); } else { _builder.append("\t\t"); _builder.append("return true;"); _builder.newLine(); } } _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.newLine(); { for(final AbstractRule exportedRule_1 : exportedRules) { _builder.append("\t"); _builder.append("protected boolean createEObjectDescriptionsFor"); String _name_1 = exportedRule_1.getType().getClassifier().getName(); _builder.append(_name_1, "\t"); _builder.append("("); _builder.append(EObject.class, "\t"); _builder.append(" eObject, "); _builder.append(IAcceptor.class, "\t"); _builder.append("<"); _builder.append(IEObjectDescription.class, "\t"); _builder.append("> acceptor) {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("\t"); _builder.append("return super.createEObjectDescriptions(eObject, acceptor);"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); } } _builder.append("}"); _builder.newLine(); } }; return this.fileAccessFactory.createJavaFile(_abstractResourceDescriptionStrategyClass, _client); }
Example 17
Source File: CodeMiningFragment.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void generateXtendCodeMiningProvider() { TypeReference _typeRef = TypeReference.typeRef(this.getCodeMiningProviderClass().toString()); StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("class "); String _simpleName = CodeMiningFragment.this.getCodeMiningProviderClass().getSimpleName(); _builder.append(_simpleName); _builder.append(" extends "); TypeReference _codeMiningProviderSuperClass = CodeMiningFragment.this.getCodeMiningProviderSuperClass(); _builder.append(_codeMiningProviderSuperClass); _builder.append(" {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("override void createCodeMinings("); TypeReference _iDocument = CodeMiningFragment.this.getIDocument(); _builder.append(_iDocument, "\t"); _builder.append(" document, "); TypeReference _xtextResource = CodeMiningFragment.this.getXtextResource(); _builder.append(_xtextResource, "\t"); _builder.append(" resource, "); TypeReference _cancelIndicator = CodeMiningFragment.this.getCancelIndicator(); _builder.append(_cancelIndicator, "\t"); _builder.append(" indicator,"); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); TypeReference _iAcceptor = CodeMiningFragment.this.getIAcceptor(); _builder.append(_iAcceptor, "\t\t"); _builder.append("<? super "); TypeReference _iCodeMining = CodeMiningFragment.this.getICodeMining(); _builder.append(_iCodeMining, "\t\t"); _builder.append("> acceptor) throws "); TypeReference _badLocationException = CodeMiningFragment.this.getBadLocationException(); _builder.append(_badLocationException, "\t\t"); _builder.append(" {"); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.newLine(); _builder.append("\t\t"); _builder.append("// TODO: implement me"); _builder.newLine(); _builder.append("\t\t"); _builder.append("// use acceptor.accept(super.createNewLineHeaderCodeMining(...)) to add a new code mining to the final list"); _builder.newLine(); _builder.append("\t\t"); _builder.newLine(); _builder.append("\t\t"); _builder.append("// example:"); _builder.newLine(); _builder.append("\t\t"); _builder.append("// acceptor.accept(createNewLineHeaderCodeMining(1, document, \"Header annotation\"))"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); } }; this.fileAccessFactory.createXtendFile(_typeRef, _client).writeTo(this.getProjectConfig().getEclipsePlugin().getSrc()); }
Example 18
Source File: ToStringProcessor.java From xtext-lib with Eclipse Public License 2.0 | 4 votes |
public void addToString(final MutableClassDeclaration cls, final Iterable<? extends FieldDeclaration> fields, final ToStringConfiguration config) { final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> { this.context.setPrimarySourceElement(it, this.context.getPrimarySourceElement(cls)); it.setReturnType(this.context.getString()); it.addAnnotation(this.context.newAnnotationReference(Override.class)); it.addAnnotation(this.context.newAnnotationReference(Pure.class)); StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append(ToStringBuilder.class); _builder.append(" b = new "); _builder.append(ToStringBuilder.class); _builder.append("(this);"); _builder.newLineIfNotEmpty(); { boolean _isSkipNulls = config.isSkipNulls(); if (_isSkipNulls) { _builder.append("b.skipNulls();"); } } _builder.newLineIfNotEmpty(); { boolean _isSingleLine = config.isSingleLine(); if (_isSingleLine) { _builder.append("b.singleLine();"); } } _builder.newLineIfNotEmpty(); { boolean _isHideFieldNames = config.isHideFieldNames(); if (_isHideFieldNames) { _builder.append("b.hideFieldNames();"); } } _builder.newLineIfNotEmpty(); { boolean _isVerbatimValues = config.isVerbatimValues(); if (_isVerbatimValues) { _builder.append("b.verbatimValues();"); } } _builder.newLineIfNotEmpty(); { for(final FieldDeclaration field : fields) { _builder.append("b.add(\""); String _simpleName = field.getSimpleName(); _builder.append(_simpleName); _builder.append("\", this."); String _simpleName_1 = field.getSimpleName(); _builder.append(_simpleName_1); _builder.append(");"); _builder.newLineIfNotEmpty(); } } _builder.append("return b.toString();"); _builder.newLine(); } }; it.setBody(_client); }; cls.addMethod("toString", _function); }
Example 19
Source File: EqualsHashCodeProcessor.java From xtext-lib with Eclipse Public License 2.0 | 4 votes |
public void addHashCode(final MutableClassDeclaration cls, final Iterable<? extends FieldDeclaration> includedFields, final boolean includeSuper) { String _xifexpression = null; if (includeSuper) { _xifexpression = "super.hashCode()"; } else { _xifexpression = "1"; } final String defaultBase = _xifexpression; final int fields = IterableExtensions.size(includedFields); final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> { this.context.setPrimarySourceElement(it, this.context.getPrimarySourceElement(cls)); it.setReturnType(this.context.getPrimitiveInt()); it.addAnnotation(this.context.newAnnotationReference(Override.class)); it.addAnnotation(this.context.newAnnotationReference(Pure.class)); StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { { if ((fields >= 2)) { _builder.append("final int prime = "); _builder.append(EqualsHashCodeProcessor.Util.PRIME_VALUE); _builder.append(";"); _builder.newLineIfNotEmpty(); _builder.append("int result = "); _builder.append(defaultBase); _builder.append(";"); _builder.newLineIfNotEmpty(); { ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, fields, true); for(final Integer i : _doubleDotLessThan) { { if (((i).intValue() == (fields - 1))) { _builder.append("return"); } else { _builder.append("result ="); } } _builder.append(" prime * result + "); StringConcatenationClient _contributeToHashCode = Util.this.contributeToHashCode(((FieldDeclaration[])Conversions.unwrapArray(includedFields, FieldDeclaration.class))[(i).intValue()]); _builder.append(_contributeToHashCode); _builder.append(";"); _builder.newLineIfNotEmpty(); } } } else { if ((fields == 1)) { _builder.append("return "); _builder.append(EqualsHashCodeProcessor.Util.PRIME_VALUE); _builder.append(" * "); _builder.append(defaultBase); _builder.append(" + "); StringConcatenationClient _contributeToHashCode_1 = Util.this.contributeToHashCode(IterableExtensions.head(includedFields)); _builder.append(_contributeToHashCode_1); _builder.append(";"); _builder.newLineIfNotEmpty(); } else { _builder.append("return "); _builder.append(defaultBase); _builder.append(";"); _builder.newLineIfNotEmpty(); } } } } }; it.setBody(_client); }; cls.addMethod("hashCode", _function); }
Example 20
Source File: GrammarAccessFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected StringConcatenationClient _getter(final TerminalRule it, final Grammar original) { StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { String _grammarFragmentToString = GrammarAccessFragment2.this._grammarAccessExtensions.grammarFragmentToString(it, "//"); _builder.append(_grammarFragmentToString); _builder.newLineIfNotEmpty(); _builder.append("public "); _builder.append(TerminalRule.class); _builder.append(" "); String _gaRuleAccessor = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessor(it); _builder.append(_gaRuleAccessor); _builder.append(" {"); _builder.newLineIfNotEmpty(); { Grammar _grammar = GrammarUtil.getGrammar(it); boolean _tripleEquals = (_grammar == original); if (_tripleEquals) { _builder.append("\t"); _builder.append("return "); String _gaRuleAccessorLocalVarName = GrammarAccessFragment2.this.gaRuleAccessorLocalVarName(it); _builder.append(_gaRuleAccessorLocalVarName, "\t"); _builder.append(";"); _builder.newLineIfNotEmpty(); } else { _builder.append("\t"); _builder.append("return "); String _gaGrammarAccessLocalVarName = GrammarAccessFragment2.this.gaGrammarAccessLocalVarName(GrammarUtil.getGrammar(it)); _builder.append(_gaGrammarAccessLocalVarName, "\t"); _builder.append("."); String _gaBaseRuleAccessor = GrammarAccessFragment2.this._grammarAccessExtensions.gaBaseRuleAccessor(it); _builder.append(_gaBaseRuleAccessor, "\t"); _builder.append(";"); _builder.newLineIfNotEmpty(); } } _builder.append("}"); _builder.newLine(); } }; return _client; }