/** * Parses, validates and compiles the given source. Calls the given acceptor for each * resource which is generated from the source. * * @param resourceSet - the {@link ResourceSet} to use * @param acceptor gets called once for each file generated in {@link IGenerator} */ public void compile(final ResourceSet resourceSet, IAcceptor<Result> acceptor) { try { List<Resource> resourcesToCheck = newArrayList(resourceSet.getResources()); if (generatorConfigProvider instanceof GeneratorConfigProvider) { GeneratorConfigProvider configProvider = (GeneratorConfigProvider) generatorConfigProvider; GeneratorConfig config = generatorConfigProvider.get(null); config.setJavaSourceVersion(javaCompiler.getJavaVersion()); GeneratorConfig existent = configProvider.install(resourceSet, config); if (existent != null) { existent.setJavaSourceVersion(javaCompiler.getJavaVersion()); configProvider.install(resourceSet, existent); } } Result result = resultProvider.get(); result.setJavaCompiler(javaCompiler); result.setCheckMode(getCheckMode()); result.setResources(resourcesToCheck); result.setResourceSet(resourceSet); result.setOutputConfigurations(getOutputConfigurations()); result.doGenerate(); acceptor.accept(result); } catch (Exception e) { Exceptions.throwUncheckedException(e); } }
public GeneratorConfig install(final ResourceSet resourceSet, final GeneratorConfig config) { GeneratorConfigProvider.GeneratorConfigAdapter _elvis = null; GeneratorConfigProvider.GeneratorConfigAdapter _findInEmfObject = GeneratorConfigProvider.GeneratorConfigAdapter.findInEmfObject(resourceSet); if (_findInEmfObject != null) { _elvis = _findInEmfObject; } else { GeneratorConfigProvider.GeneratorConfigAdapter _generatorConfigAdapter = new GeneratorConfigProvider.GeneratorConfigAdapter(); final Procedure1<GeneratorConfigProvider.GeneratorConfigAdapter> _function = (GeneratorConfigProvider.GeneratorConfigAdapter it) -> { it.attachToEmfObject(resourceSet); }; GeneratorConfigProvider.GeneratorConfigAdapter _doubleArrow = ObjectExtensions.<GeneratorConfigProvider.GeneratorConfigAdapter>operator_doubleArrow(_generatorConfigAdapter, _function); _elvis = _doubleArrow; } final GeneratorConfigProvider.GeneratorConfigAdapter adapter = _elvis; return adapter.language2GeneratorConfig.put(this.languageId, config); }
@Override public GeneratorConfig get(final EObject context) { Resource _eResource = null; if (context!=null) { _eResource=context.eResource(); } ResourceSet _resourceSet = null; if (_eResource!=null) { _resourceSet=_eResource.getResourceSet(); } final ResourceSet resourceSet = _resourceSet; if ((resourceSet != null)) { final GeneratorConfigProvider.GeneratorConfigAdapter adapter = GeneratorConfigProvider.GeneratorConfigAdapter.findInEmfObject(resourceSet); if (((adapter != null) && adapter.language2GeneratorConfig.containsKey(this.languageId))) { return adapter.language2GeneratorConfig.get(this.languageId); } } return new GeneratorConfig(); }
public void generateAnnotationMethod(final JvmOperation it, final ITreeAppendable appendable, final GeneratorConfig config) { appendable.increaseIndentation().newLine(); appendable.openScope(); this.generateJavaDoc(it, appendable, config); final ITreeAppendable tracedAppendable = appendable.trace(it); this.generateAnnotations(it.getAnnotations(), tracedAppendable, true, config); this.generateModifier(it, tracedAppendable, config); this._errorSafeExtensions.serializeSafely(it.getReturnType(), "Object", tracedAppendable); tracedAppendable.append(" "); this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName())); tracedAppendable.append("()"); this.generateDefaultExpression(it, tracedAppendable, config); tracedAppendable.append(";"); appendable.decreaseIndentation(); appendable.closeScope(); }
protected ITreeAppendable _generateModifier(final JvmField it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { this.generateVisibilityModifier(it, appendable); boolean _isFinal = it.isFinal(); if (_isFinal) { appendable.append("final "); } boolean _isStatic = it.isStatic(); if (_isStatic) { appendable.append("static "); } boolean _isTransient = it.isTransient(); if (_isTransient) { appendable.append("transient "); } ITreeAppendable _xifexpression = null; boolean _isVolatile = it.isVolatile(); if (_isVolatile) { _xifexpression = appendable.append("volatile "); } _xblockexpression = _xifexpression; } return _xblockexpression; }
protected ITreeAppendable _generateMember(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { appendable.newLine(); appendable.openScope(); this.assignThisAndSuper(appendable, it, config); ITreeAppendable _xtrycatchfinallyexpression = null; try { _xtrycatchfinallyexpression = this.generateBody(it, appendable, config); } finally { appendable.closeScope(); } _xblockexpression = _xtrycatchfinallyexpression; } return _xblockexpression; }
protected ITreeAppendable _generateMember(final JvmField it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { appendable.newLine(); this.generateJavaDoc(it, appendable, config); final ITreeAppendable tracedAppendable = appendable.trace(it); this.generateAnnotations(it.getAnnotations(), tracedAppendable, true, config); this.generateModifier(it, tracedAppendable, config); this._errorSafeExtensions.serializeSafely(it.getType(), "Object", tracedAppendable); tracedAppendable.append(" "); final String name = tracedAppendable.declareVariable(it, this.makeJavaIdentifier(it.getSimpleName())); this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(name); this.generateInitialization(it, tracedAppendable, config); _xblockexpression = tracedAppendable.append(";"); } return _xblockexpression; }
protected ITreeAppendable _generateMember(final JvmConstructor it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { appendable.newLine(); appendable.openScope(); this.generateJavaDoc(it, appendable, config); final ITreeAppendable tracedAppendable = appendable.trace(it); this.generateAnnotations(it.getAnnotations(), tracedAppendable, true, config); this.generateModifier(it, tracedAppendable, config); this.generateTypeParameterDeclaration(it, tracedAppendable, config); this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName())); tracedAppendable.append("("); this.generateParameters(it, tracedAppendable, config); tracedAppendable.append(")"); this.generateThrowsClause(it, tracedAppendable, config); tracedAppendable.append(" "); this.generateExecutableBody(it, tracedAppendable, config); appendable.closeScope(); _xblockexpression = appendable; } return _xblockexpression; }
public void generateParameters(final JvmExecutable it, final ITreeAppendable appendable, final GeneratorConfig config) { boolean _isEmpty = it.getParameters().isEmpty(); boolean _not = (!_isEmpty); if (_not) { int _size = it.getParameters().size(); int _minus = (_size - 1); IntegerRange _upTo = new IntegerRange(0, _minus); for (final Integer i : _upTo) { { int _size_1 = it.getParameters().size(); final boolean last = (((i).intValue() + 1) == _size_1); final JvmFormalParameter p = it.getParameters().get((i).intValue()); this.generateParameter(p, appendable, (last && it.isVarArgs()), config); if ((!last)) { appendable.append(", "); } } } } }
public void generateParameter(final JvmFormalParameter it, final ITreeAppendable appendable, final boolean vararg, final GeneratorConfig config) { final ITreeAppendable tracedAppendable = appendable.trace(it); this.generateAnnotations(it.getAnnotations(), tracedAppendable, false, config); tracedAppendable.append("final "); if (vararg) { JvmTypeReference _parameterType = it.getParameterType(); boolean _not = (!(_parameterType instanceof JvmGenericArrayTypeReference)); if (_not) { tracedAppendable.append("/* Internal Error: Parameter was vararg but not an array type. */"); } else { JvmTypeReference _parameterType_1 = it.getParameterType(); this._errorSafeExtensions.serializeSafely(((JvmGenericArrayTypeReference) _parameterType_1).getComponentType(), "Object", tracedAppendable); } tracedAppendable.append("..."); } else { this._errorSafeExtensions.serializeSafely(it.getParameterType(), "Object", tracedAppendable); } tracedAppendable.append(" "); final String name = tracedAppendable.declareVariable(it, this.makeJavaIdentifier(it.getSimpleName())); this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(name); }
public void generateJavaDoc(final EObject it, final ITreeAppendable appendable, final GeneratorConfig config) { final DocumentationAdapter adapter = IterableExtensions.<DocumentationAdapter>head(Iterables.<DocumentationAdapter>filter(it.eAdapters(), DocumentationAdapter.class)); String _documentation = null; if (adapter!=null) { _documentation=adapter.getDocumentation(); } boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(_documentation); boolean _not = (!_isNullOrEmpty); if (_not) { final Set<EObject> sourceElements = this.getSourceElements(it); if (((sourceElements.size() == 1) && (this.documentationProvider instanceof IEObjectDocumentationProviderExtension))) { final List<INode> documentationNodes = ((IEObjectDocumentationProviderExtension) this.documentationProvider).getDocumentationNodes(IterableExtensions.<EObject>head(sourceElements)); this.addJavaDocImports(it, appendable, documentationNodes); this.generateDocumentation(adapter.getDocumentation(), documentationNodes, appendable, config); } else { this.generateDocumentation(adapter.getDocumentation(), CollectionLiterals.<INode>emptyList(), appendable, config); } } }
public void toJava(final JvmAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) { JvmOperation _operation = it.getOperation(); boolean _tripleNotEquals = (_operation != null); if (_tripleNotEquals) { String _simpleName = it.getOperation().getSimpleName(); boolean _tripleEquals = (_simpleName == null); if (_tripleEquals) { return; } appendable.append(it.getOperation().getSimpleName()); appendable.append(" = "); } else { EObject _eContainer = it.eContainer(); int _size = ((JvmAnnotationReference) _eContainer).getExplicitValues().size(); boolean _greaterThan = (_size > 1); if (_greaterThan) { appendable.append("value = "); } } this.toJavaLiteral(it, appendable, config); }
public ITreeAppendable generateModifier(final JvmMember it, final ITreeAppendable appendable, final GeneratorConfig config) { if (it instanceof JvmConstructor) { return _generateModifier((JvmConstructor)it, appendable, config); } else if (it instanceof JvmOperation) { return _generateModifier((JvmOperation)it, appendable, config); } else if (it instanceof JvmField) { return _generateModifier((JvmField)it, appendable, config); } else if (it instanceof JvmGenericType) { return _generateModifier((JvmGenericType)it, appendable, config); } else if (it instanceof JvmDeclaredType) { return _generateModifier((JvmDeclaredType)it, appendable, config); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, appendable, config).toString()); } }
public ITreeAppendable generateMember(final JvmMember it, final ITreeAppendable appendable, final GeneratorConfig config) { if (it instanceof JvmConstructor) { return _generateMember((JvmConstructor)it, appendable, config); } else if (it instanceof JvmOperation) { return _generateMember((JvmOperation)it, appendable, config); } else if (it instanceof JvmField) { return _generateMember((JvmField)it, appendable, config); } else if (it instanceof JvmDeclaredType) { return _generateMember((JvmDeclaredType)it, appendable, config); } else if (it != null) { return _generateMember(it, appendable, config); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, appendable, config).toString()); } }
protected String getComplianceLevelArg() { JavaVersion javaVersion = JavaVersion.JAVA5; if (generatorConfigProvider != null) { GeneratorConfig generatorConfig = generatorConfigProvider.get(null); javaVersion = generatorConfig.getJavaSourceVersion(); } return javaVersion.getComplianceLevelArg(); }
public CharSequence generateType(final JvmDeclaredType type, final GeneratorConfig config) { final ImportManager importManager = this.createImportManager(type); final TreeAppendable bodyAppendable = this.createAppendable(type, importManager, config); bodyAppendable.openScope(); this.assignThisAndSuper(bodyAppendable, type, config); this.generateBody(type, bodyAppendable, config); bodyAppendable.closeScope(); final TreeAppendable importAppendable = this.createAppendable(type, importManager, config); this.generateFileHeader(type, importAppendable, config); String _packageName = type.getPackageName(); boolean _tripleNotEquals = (_packageName != null); if (_tripleNotEquals) { importAppendable.append("package ").append(type.getPackageName()).append(";"); importAppendable.newLine().newLine(); } List<String> _imports = importManager.getImports(); for (final String i : _imports) { importAppendable.append("import ").append(i).append(";").newLine(); } boolean _isEmpty = importManager.getImports().isEmpty(); boolean _not = (!_isEmpty); if (_not) { importAppendable.newLine(); } importAppendable.append(bodyAppendable); return importAppendable; }
protected ITreeAppendable _generateBody(final JvmGenericType it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { this.generateJavaDoc(it, appendable, config); final ITreeAppendable childAppendable = appendable.trace(it); this.generateAnnotations(it.getAnnotations(), childAppendable, true, config); this.generateModifier(it, childAppendable, config); boolean _isInterface = it.isInterface(); if (_isInterface) { childAppendable.append("interface "); } else { childAppendable.append("class "); } this._treeAppendableUtil.traceSignificant(childAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName())); this.generateTypeParameterDeclaration(it, childAppendable, config); boolean _isEmpty = it.getTypeParameters().isEmpty(); if (_isEmpty) { childAppendable.append(" "); } this.generateExtendsClause(it, childAppendable, config); this.generateMembersInBody(it, childAppendable, config); ITreeAppendable _xifexpression = null; if (((!it.isAnonymous()) && (!(it.eContainer() instanceof JvmType)))) { _xifexpression = appendable.newLine(); } _xblockexpression = _xifexpression; } return _xblockexpression; }
/** * @deprecated Additional annotations should be created in the JVM model. */ @Deprecated public ITreeAppendable generateAnnotationsWithSyntheticSuppressWarnings(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { final Function1<JvmAnnotationReference, Boolean> _function = (JvmAnnotationReference it_1) -> { JvmAnnotationType _annotation = it_1.getAnnotation(); String _identifier = null; if (_annotation!=null) { _identifier=_annotation.getIdentifier(); } String _name = SuppressWarnings.class.getName(); return Boolean.valueOf((!Objects.equal(_identifier, _name))); }; final Function1<JvmAnnotationReference, Boolean> noSuppressWarningsFilter = _function; this.generateAnnotations(IterableExtensions.<JvmAnnotationReference>filter(it.getAnnotations(), noSuppressWarningsFilter), appendable, true, config); ITreeAppendable _xifexpression = null; EObject _eContainer = it.eContainer(); boolean _tripleEquals = (_eContainer == null); if (_tripleEquals) { StringConcatenation _builder = new StringConcatenation(); _builder.append("@SuppressWarnings(\"all\")"); _xifexpression = appendable.append(_builder).newLine(); } _xblockexpression = _xifexpression; } return _xblockexpression; }
protected ITreeAppendable _generateBody(final JvmAnnotationType it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { this.generateJavaDoc(it, appendable, config); final ITreeAppendable childAppendable = appendable.trace(it); this.generateAnnotations(it.getAnnotations(), childAppendable, true, config); this.generateModifier(it, childAppendable, config); childAppendable.append("@interface "); this._treeAppendableUtil.traceSignificant(childAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName())); childAppendable.append(" {"); Iterable<JvmDeclaredType> _filter = Iterables.<JvmDeclaredType>filter(this.getMembersToBeCompiled(it), JvmDeclaredType.class); for (final JvmDeclaredType innerType : _filter) { { final ITreeAppendable innerTypeAppendable = childAppendable.trace(innerType); innerTypeAppendable.increaseIndentation(); this.generateMember(innerType, innerTypeAppendable, config); innerTypeAppendable.decreaseIndentation(); } } Iterable<JvmOperation> _filter_1 = Iterables.<JvmOperation>filter(this.getMembersToBeCompiled(it), JvmOperation.class); for (final JvmOperation operation : _filter_1) { this.generateAnnotationMethod(operation, childAppendable, config); } childAppendable.newLine().append("}"); ITreeAppendable _xifexpression = null; EObject _eContainer = it.eContainer(); boolean _not = (!(_eContainer instanceof JvmType)); if (_not) { _xifexpression = appendable.newLine(); } _xblockexpression = _xifexpression; } return _xblockexpression; }
protected ITreeAppendable _generateModifier(final JvmGenericType it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { this.generateVisibilityModifier(it, appendable); boolean _isInterface = it.isInterface(); boolean _not = (!_isInterface); if (_not) { boolean _isStatic = it.isStatic(); if (_isStatic) { appendable.append("static "); } boolean _isAbstract = it.isAbstract(); if (_isAbstract) { appendable.append("abstract "); } } boolean _isFinal = it.isFinal(); if (_isFinal) { appendable.append("final "); } ITreeAppendable _xifexpression = null; boolean _isStrictFloatingPoint = it.isStrictFloatingPoint(); if (_isStrictFloatingPoint) { _xifexpression = appendable.append("strictfp "); } _xblockexpression = _xifexpression; } return _xblockexpression; }
protected ITreeAppendable _generateModifier(final JvmOperation it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { this.generateVisibilityModifier(it, appendable); boolean _isAbstract = it.isAbstract(); if (_isAbstract) { appendable.append("abstract "); } boolean _isStatic = it.isStatic(); if (_isStatic) { appendable.append("static "); } if ((((((!it.isAbstract()) && (!it.isStatic())) && config.getJavaSourceVersion().isAtLeast(JavaVersion.JAVA8)) && (it.eContainer() instanceof JvmGenericType)) && ((JvmGenericType) it.eContainer()).isInterface())) { appendable.append("default "); } boolean _isFinal = it.isFinal(); if (_isFinal) { appendable.append("final "); } boolean _isSynchronized = it.isSynchronized(); if (_isSynchronized) { appendable.append("synchronized "); } boolean _isStrictFloatingPoint = it.isStrictFloatingPoint(); if (_isStrictFloatingPoint) { appendable.append("strictfp "); } ITreeAppendable _xifexpression = null; boolean _isNative = it.isNative(); if (_isNative) { _xifexpression = appendable.append("native "); } _xblockexpression = _xifexpression; } return _xblockexpression; }
protected ITreeAppendable _generateMember(final JvmMember it, final ITreeAppendable appendable, final GeneratorConfig config) { Class<? extends JvmMember> _class = null; if (it!=null) { _class=it.getClass(); } String _name = null; if (_class!=null) { _name=_class.getName(); } String _plus = ("generateMember not implemented for elements of type " + _name); throw new UnsupportedOperationException(_plus); }
protected ITreeAppendable _generateMember(final JvmOperation it, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { appendable.newLine(); appendable.openScope(); this.generateJavaDoc(it, appendable, config); final ITreeAppendable tracedAppendable = appendable.trace(it); this.generateAnnotations(it.getAnnotations(), tracedAppendable, true, config); this.generateModifier(it, tracedAppendable, config); this.generateTypeParameterDeclaration(it, tracedAppendable, config); JvmTypeReference _returnType = it.getReturnType(); boolean _tripleEquals = (_returnType == null); if (_tripleEquals) { tracedAppendable.append("void"); } else { this._errorSafeExtensions.serializeSafely(it.getReturnType(), "Object", tracedAppendable); } tracedAppendable.append(" "); this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName())); tracedAppendable.append("("); this.generateParameters(it, tracedAppendable, config); tracedAppendable.append(")"); this.generateThrowsClause(it, tracedAppendable, config); if ((it.isAbstract() || (!this.hasBody(it)))) { tracedAppendable.append(";"); } else { tracedAppendable.append(" "); this.generateExecutableBody(it, tracedAppendable, config); } appendable.closeScope(); _xblockexpression = appendable; } return _xblockexpression; }
public void generateFileHeader(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) { final FileHeaderAdapter fileHeaderAdapter = IterableExtensions.<FileHeaderAdapter>head(Iterables.<FileHeaderAdapter>filter(it.eAdapters(), FileHeaderAdapter.class)); String _headerText = null; if (fileHeaderAdapter!=null) { _headerText=fileHeaderAdapter.getHeaderText(); } boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(_headerText); boolean _not = (!_isNullOrEmpty); if (_not) { this.generateDocumentation(fileHeaderAdapter.getHeaderText(), this.fileHeaderProvider.getFileHeaderNodes(it.eResource()), appendable, config); } }
protected ITreeAppendable generateDocumentation(final String text, final List<INode> documentationNodes, final ITreeAppendable appendable, final GeneratorConfig config) { ITreeAppendable _xblockexpression = null; { StringConcatenation _builder = new StringConcatenation(); _builder.append("/**"); final StringConcatenation doc = ((StringConcatenation) _builder); doc.newLine(); doc.append(" * "); doc.append(text, " * "); doc.newLine(); doc.append(" */"); ITreeAppendable _xifexpression = null; boolean _isEmpty = documentationNodes.isEmpty(); boolean _not = (!_isEmpty); if (_not) { ITreeAppendable _xblockexpression_1 = null; { ITextRegionWithLineInformation documentationTrace = ITextRegionWithLineInformation.EMPTY_REGION; for (final INode node : documentationNodes) { documentationTrace = documentationTrace.merge(node.getTextRegionWithLineInformation()); } LocationData _locationData = new LocationData(documentationTrace, null); appendable.trace(_locationData).append(doc.toString()); _xblockexpression_1 = appendable.newLine(); } _xifexpression = _xblockexpression_1; } else { _xifexpression = appendable.append(doc.toString()).newLine(); } _xblockexpression = _xifexpression; } return _xblockexpression; }
protected void _toJavaLiteral(final JvmDoubleAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) { final Procedure1<Double> _function = (Double it_1) -> { String _switchResult = null; boolean _matched = false; boolean _isNaN = Double.isNaN((it_1).doubleValue()); if (_isNaN) { _matched=true; _switchResult = "Double.NaN"; } if (!_matched) { if (Objects.equal(it_1, Double.POSITIVE_INFINITY)) { _matched=true; _switchResult = "Double.POSITIVE_INFINITY"; } } if (!_matched) { if (Objects.equal(it_1, Double.NEGATIVE_INFINITY)) { _matched=true; _switchResult = "Double.NEGATIVE_INFINITY"; } } if (!_matched) { String _string = it_1.toString(); _switchResult = (_string + "d"); } appendable.append(_switchResult); }; this._loopExtensions.<Double>forEachWithShortcut(appendable, it.getValues(), _function); }
protected void _toJavaLiteral(final JvmFloatAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) { final Procedure1<Float> _function = (Float it_1) -> { String _switchResult = null; boolean _matched = false; boolean _isNaN = Float.isNaN((it_1).floatValue()); if (_isNaN) { _matched=true; _switchResult = "Float.NaN"; } if (!_matched) { if (Objects.equal(it_1, Float.POSITIVE_INFINITY)) { _matched=true; _switchResult = "Float.POSITIVE_INFINITY"; } } if (!_matched) { if (Objects.equal(it_1, Float.NEGATIVE_INFINITY)) { _matched=true; _switchResult = "Float.NEGATIVE_INFINITY"; } } if (!_matched) { String _string = it_1.toString(); _switchResult = (_string + "f"); } appendable.append(_switchResult); }; this._loopExtensions.<Float>forEachWithShortcut(appendable, it.getValues(), _function); }
protected void _toJavaLiteral(final JvmCharAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) { final Procedure1<Character> _function = (Character it_1) -> { String _doConvertToJavaString = this.doConvertToJavaString(it_1.toString()); String _plus = ("\'" + _doConvertToJavaString); String _plus_1 = (_plus + "\'"); appendable.append(_plus_1); }; this._loopExtensions.<Character>forEachWithShortcut(appendable, it.getValues(), _function); }
protected void _toJavaLiteral(final JvmStringAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) { final Procedure1<String> _function = (String it_1) -> { String _doConvertToJavaString = this.doConvertToJavaString(it_1.toString()); String _plus = ("\"" + _doConvertToJavaString); String _plus_1 = (_plus + "\""); appendable.append(_plus_1); }; this._loopExtensions.<String>forEachWithShortcut(appendable, it.getValues(), _function); }
protected void _toJavaLiteral(final JvmEnumAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) { final Procedure1<JvmEnumerationLiteral> _function = (JvmEnumerationLiteral it_1) -> { appendable.append(it_1.getDeclaringType()); appendable.append("."); appendable.append(this.makeJavaIdentifier(it_1.getSimpleName())); }; this._loopExtensions.<JvmEnumerationLiteral>forEachWithShortcut(appendable, it.getValues(), _function); }
protected void _toJavaLiteral(final JvmCustomAnnotationValue it, final ITreeAppendable appendable, final GeneratorConfig config) { boolean _isEmpty = it.getValues().isEmpty(); if (_isEmpty) { appendable.append("{}"); } else { final Procedure1<XExpression> _function = (XExpression it_1) -> { this.compiler.toJavaExpression(it_1, appendable); }; this._loopExtensions.<XExpression>forEachWithShortcut(appendable, Iterables.<XExpression>filter(it.getValues(), XExpression.class), _function); } }
public ITreeAppendable generateBody(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) { if (it instanceof JvmAnnotationType) { return _generateBody((JvmAnnotationType)it, appendable, config); } else if (it instanceof JvmEnumerationType) { return _generateBody((JvmEnumerationType)it, appendable, config); } else if (it instanceof JvmGenericType) { return _generateBody((JvmGenericType)it, appendable, config); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, appendable, config).toString()); } }
@Test public void testBug472265_01_lamda() throws Exception { GeneratorConfig generatorConfig = generatorConfigProvider.get(null); generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8); assertCompilesTo("final closures.IAcceptors.IAcceptor _function = (String x) -> {\n" + "};\n" + "closures.IAcceptors.IAcceptor a = _function;", "{var closures.IAcceptors.IAcceptor a = [x|]}", generatorConfig); }
@Test public void testBug472265_02_lamda() throws Exception { GeneratorConfig generatorConfig = generatorConfigProvider.get(null); generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8); assertCompilesTo("final closures.IAcceptors.IAcceptor2 _function = (String[] x) -> {\n" + "};\n" + "closures.IAcceptors.IAcceptor2 a = _function;", "{var closures.IAcceptors.IAcceptor2 a = [x|]}", generatorConfig); }
@Test public void testBug472265_03_lamda() throws Exception { GeneratorConfig generatorConfig = generatorConfigProvider.get(null); generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8); assertCompilesTo("final closures.IAcceptors.IAcceptor3 _function = (String... x) -> {\n" + "};\n" + "closures.IAcceptors.IAcceptor3 a = _function;", "{var closures.IAcceptors.IAcceptor3 a = [x|]}", generatorConfig); }
@Test public void testBug472265_04_lamda() throws Exception { GeneratorConfig generatorConfig = generatorConfigProvider.get(null); generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8); assertCompilesTo("final closures.IAcceptors.IAcceptor4 _function = (String x, String[] y) -> {\n" + "};\n" + "closures.IAcceptors.IAcceptor4 a = _function;", "{var closures.IAcceptors.IAcceptor4 a = [x,y|]}", generatorConfig); }
@Test public void testBug472265_05_lamda() throws Exception { GeneratorConfig generatorConfig = generatorConfigProvider.get(null); generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8); assertCompilesTo("final closures.IAcceptors.IAcceptor5 _function = (String x, String... y) -> {\n" + "};\n" + "closures.IAcceptors.IAcceptor5 a = _function;", "{var closures.IAcceptors.IAcceptor5 a = [x,y|]}", generatorConfig); }
@Test public void testBug472265_06_lamda() throws Exception { GeneratorConfig generatorConfig = generatorConfigProvider.get(null); generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8); assertCompilesTo("final closures.IAcceptors.IAcceptor6 _function = (String[] x, String[] y) -> {\n" + "};\n" + "closures.IAcceptors.IAcceptor6 a = _function;", "{var closures.IAcceptors.IAcceptor6 a = [x,y|]}", generatorConfig); }
@Test public void testBug472265_07_lamda() throws Exception { GeneratorConfig generatorConfig = generatorConfigProvider.get(null); generatorConfig.setJavaSourceVersion(JavaVersion.JAVA8); assertCompilesTo("final closures.IAcceptors.IAcceptor7 _function = (String[] x, String... y) -> {\n" + "};\n" + "closures.IAcceptors.IAcceptor7 a = _function;", "{var closures.IAcceptors.IAcceptor7 a = [x,y|]}", generatorConfig); }
protected void assertCompilesTo(final CharSequence expectedJavaCode, final CharSequence xbaseCode, GeneratorConfig generatorConfig, boolean resolve) throws Exception { XExpression model = expression(xbaseCode.toString(), resolve); XbaseCompiler compiler = get(XbaseCompiler.class); FakeTreeAppendable tracing = createAppendable(); tracing.setGeneratorConfig(generatorConfig); LightweightTypeReference returnType = typeResolver.resolveTypes(model).getReturnType(model); if (returnType == null) { throw new IllegalStateException(); } compiler.compile(model, tracing, returnType); assertEquals(expectedJavaCode.toString().trim(), tracing.getContent().toString().trim()); }