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 boolean isOperatorFromExtension(XAbstractFeatureCall featureCall, String concreteSyntax, QualifiedName operatorSymbol, Class<?> definingExtensionClass) { if(!equal(concreteSyntax, operatorSymbol.getLastSegment())) return false; List<QualifiedName> methodNames = getMethodNames(featureCall, operatorSymbol); JvmDeclaredType definingJvmType = (JvmDeclaredType) typeReferences.findDeclaredType(definingExtensionClass, featureCall); if (definingJvmType == null) return false; JvmIdentifiableElement feature = featureCall.getFeature(); if (definingJvmType != feature.eContainer()) { return false; } for (QualifiedName methodName : methodNames) { if (methodName.getLastSegment().equals(feature.getSimpleName())) { return true; } } return false; }
@Test public void testDefaultAnnotationAnnotationValueByReference() throws Exception { String typeName = Bug334943Client.class.getName(); JvmDeclaredType client = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); JvmOperation operation = Iterables.get(client.getDeclaredOperations(), 0); List<JvmAnnotationReference> annotations = operation.getAnnotations(); assertEquals(1, annotations.size()); JvmAnnotationReference annotation = annotations.get(0); for (JvmAnnotationValue value : annotation.getValues()) { if ("enumValue".equals(value.getValueName())) { JvmEnumAnnotationValue enumValue = (JvmEnumAnnotationValue) value; assertEquals(1, enumValue.getValues().size()); assertEquals("FirstValue", enumValue.getValues().get(0).getSimpleName()); } } }
public IScope createTypeScope(EObject context, EReference reference) { if (context.eClass() == TypesPackage.Literals.JVM_INNER_TYPE_REFERENCE) { JvmInnerTypeReference casted = (JvmInnerTypeReference) context; JvmParameterizedTypeReference outerType = casted.getOuter(); JvmType outerRawType = outerType.getType(); if (outerRawType instanceof JvmDeclaredType) { Iterable<JvmDeclaredType> nestedTypes = ((JvmDeclaredType) outerRawType).getAllNestedTypes(); List<IEObjectDescription> descriptions = Lists.newArrayList(); for(JvmDeclaredType nestedType: nestedTypes) { descriptions.add(EObjectDescription.create(nestedType.getSimpleName(), nestedType)); } return new SimpleScope(descriptions); } return IScope.NULLSCOPE; } else { final IScope delegateScope = getDelegate().getScope(context, reference); return delegateScope; } }
public boolean removeImport(JvmDeclaredType type) { List<XImportDeclaration> addedImportDeclarationsToRemove = findOriginalImports(type, null, addedImportDeclarations, false, false); addedImportDeclarations.removeAll(addedImportDeclarationsToRemove); List<XImportDeclaration> originalImportDeclarationsToRemove = findOriginalImports(type, null, originalImportDeclarations, false, false); removedImportDeclarations.addAll(originalImportDeclarationsToRemove); for (Map.Entry<String, List<JvmDeclaredType>> entry : plainImports.entrySet()) { List<JvmDeclaredType> values = entry.getValue(); if (values.size() == 1) { if (values.get(0) == type) { plainImports.remove(type.getSimpleName()); return true; } } Iterator<JvmDeclaredType> iterator = values.iterator(); while (iterator.hasNext()) { JvmDeclaredType value = iterator.next(); if (value == type) { iterator.remove(); return true; } } } return false; }
public ResolvedFeatures toResolvedOperations(final Class<?> type) { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("typeof("); String _canonicalName = type.getCanonicalName(); _builder.append(_canonicalName); _builder.append(")"); XExpression _expression = this.expression(_builder); final XTypeLiteral typeLiteral = ((XTypeLiteral) _expression); JvmType _type = typeLiteral.getType(); final ResolvedFeatures result = this.overrideHelper.getResolvedFeatures(((JvmDeclaredType) _type)); return result; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Override public JvmDeclaredType getContextJvmDeclaredType(EObject model) { if(model != null) { JvmIdentifiableElement logicalContainer = logicalContainerProvider.getNearestLogicalContainer(model); if(logicalContainer != null) return EcoreUtil2.getContainerOfType(logicalContainer, JvmDeclaredType.class); EObject currentElement = model; do { for(EObject jvmElement: associations.getJvmElements(currentElement)) { if(jvmElement instanceof JvmDeclaredType) return (JvmDeclaredType) jvmElement; } currentElement = currentElement.eContainer(); } while (currentElement != null); } return null; }
@Override protected void preApply() { XAbstractFeatureCall expression = getExpression(); JvmType type = getType(); if (expression instanceof XMemberFeatureCall) { if (type instanceof JvmDeclaredType) { JvmDeclaredType declaredType = (JvmDeclaredType) type; if (declaredType.getDeclaringType() == null) { helper.applyPackageFragment((XMemberFeatureCall) expression, declaredType); } else { String queriedName = description.getName().toString(); // may be Map$Entry String qualifiedName = declaredType.getIdentifier(); String packageName = Strings.emptyIfNull(declaredType.getPackageName()); if (packageName.length() + 1 + queriedName.length() == qualifiedName.length()) { helper.applyPackageFragment((XMemberFeatureCall) expression, declaredType); } } } } }
public ParameterizedTypeReference(ITypeReferenceOwner owner, JvmType type) { super(owner); if (type == null) { throw new NullPointerException("type may not be null"); } if (type instanceof JvmArrayType) { throw new IllegalArgumentException("type may not be an array type"); } if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) { EObject container = type.eContainer(); if (container instanceof JvmDeclaredType) { checkStaticFlag((JvmDeclaredType)type); } } this.type = type; this.resolved = !(type instanceof JvmTypeParameter); }
public JvmAnnotationValue getConstructorParameterAnnotationValue(String name, boolean defaultValue) { String typeName = TestAnnotation.Annotated.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class, "Annotated(java.lang.String,java.lang.String,java.lang.String)"); JvmAnnotationTarget target = constructor.getParameters().get(0); JvmAnnotationValue result = getDefaultOrExplicitAnnotationValue(name, target); if (defaultValue) { if (isDefaultValueSupported()) { assertTrue(result.eContainer() instanceof JvmOperation); } else { assertFalse(result.eContainer() instanceof JvmOperation); } } else { assertFalse(result.eContainer() instanceof JvmOperation); } return result; }
@Override protected List<IEObjectDescription> getAllLocalElements() { List<IEObjectDescription> result = super.getAllLocalElements(); if (getSession().isInstanceContext() && !isExplicitStaticFeatureCall()) { ITypeReferenceOwner owner = getReceiverType().getOwner(); QualifiedThisOrSuperDescription thisDescription = new QualifiedThisOrSuperDescription(THIS, owner.newParameterizedTypeReference(getTypeLiteral()), getBucket().getId(), true, getReceiver()); addToList(thisDescription, result); JvmType receiverRawType = getTypeLiteral(); if (receiverRawType instanceof JvmDeclaredType) { JvmType referencedType = receiverRawType; // If the receiver type is an interface, 'super' always refers to that interface if (!(receiverRawType instanceof JvmGenericType && ((JvmGenericType) receiverRawType).isInterface())) { JvmTypeReference superType = ((JvmDeclaredType) receiverRawType).getExtendedClass(); if (superType != null) { referencedType = superType.getType(); } } QualifiedThisOrSuperDescription superDescription = new QualifiedThisOrSuperDescription(SUPER, owner.newParameterizedTypeReference(referencedType), getBucket().getId(), true, getReceiver()); addToList(superDescription, result); } } return result; }
@Test public void testGetField_1() throws Exception { JvmDeclaredType type = getType(Y.class); JvmMember addMethod = Iterables.find(type.getMembers(), new Predicate<JvmMember>() { @Override public boolean apply(JvmMember input) { if (input instanceof JvmField) { return input.getSimpleName().equals("z"); } return false; } }); Field field = Y.class.getDeclaredField("z"); assertEquals(field, getJavaReflectAccess().getField((JvmField) addMethod)); }
protected void computeAllFeatures( JvmDeclaredType type, Multimap<String, AbstractResolvedOperation> processedOperations, Set<String> processedFields, ListMultimap<String, JvmFeature> result, Set<String> seenNames) { Iterable<JvmFeature> features = type.getAllFeatures(); for(JvmFeature feature: features) { if (!seenNames.contains(feature.getSimpleName())) { if (feature instanceof JvmOperation) { JvmOperation operation = (JvmOperation) feature; String simpleName = operation.getSimpleName(); if (processedOperations.containsKey(simpleName)) { if (isOverridden(operation, processedOperations.get(simpleName))) { continue; } } BottomResolvedOperation resolvedOperation = createResolvedOperation(operation); processedOperations.put(simpleName, resolvedOperation); result.put(simpleName, operation); } else if (feature instanceof JvmField && processedFields.add(feature.getSimpleName())) { result.put(feature.getSimpleName(), feature); } } } }
protected void computeAllFeatures( JvmDeclaredType type, String name, Multimap<String, AbstractResolvedOperation> processedOperations, Set<String> processedFields, List<JvmFeature> result) { Iterable<JvmFeature> features = type.findAllFeaturesByName(name); for(JvmFeature feature: features) { if (feature instanceof JvmOperation) { JvmOperation operation = (JvmOperation) feature; String simpleName = operation.getSimpleName(); if (processedOperations.containsKey(simpleName)) { if (isOverridden(operation, processedOperations.get(simpleName))) { continue; } } BottomResolvedOperation resolvedOperation = createResolvedOperation(operation); processedOperations.put(simpleName, resolvedOperation); result.add(operation); } else if (feature instanceof JvmField && processedFields.add(feature.getSimpleName())) { result.add(feature); } } }
@Override public void importStaticExtension(JvmDeclaredType type, boolean strict) { staticExtensionImports.add(type); if (!strict) { bogusStaticImports.add(type); } }
@Test public void test_arrayWildcard_02() { JvmOperation arrayWildcard = getMethodFromParameterizedMethods("arrayWildcard(java.util.List[])"); JvmTypeReference paramType = arrayWildcard.getParameters().get(0).getParameterType(); assertEquals("java.util.List<? extends java.lang.Object>[]", paramType.getIdentifier()); assertTrue(paramType.getType() instanceof JvmArrayType); JvmArrayType arrayType = (JvmArrayType) paramType.getType(); assertTrue(arrayType.getComponentType() instanceof JvmDeclaredType); assertTrue(paramType instanceof JvmGenericArrayTypeReference); assertTrue( ((JvmGenericArrayTypeReference) paramType).getComponentType() instanceof JvmParameterizedTypeReference); }
protected JvmDeclaredType findBestMatch(Collection<JvmDeclaredType> types, TypeUsages usages, RewritableImportSection importSection) { Iterator<JvmDeclaredType> iterator = types.iterator(); JvmDeclaredType currentBestMatch = iterator.next(); while (iterator.hasNext()) { JvmDeclaredType nextType = iterator.next(); if (isBetter(nextType, currentBestMatch, usages, importSection)) { currentBestMatch = nextType; } } return currentBestMatch; }
@Test public void testAnnotationType_01() throws Exception { String typeName = TestAnnotation.class.getName(); JvmType type = getTypeProvider().findTypeByName(typeName); assertNotNull(type); assertTrue(type instanceof JvmAnnotationType); assertTrue(((JvmDeclaredType) type).isAbstract()); assertFalse(((JvmDeclaredType) type).isStatic()); diagnose(type); Resource resource = type.eResource(); getAndResolveAllFragments(resource); recomputeAndCheckIdentifiers(resource); }
@Override public Boolean caseJvmDeclaredType(JvmDeclaredType object) { if (collectedSuperTypes.add(object)) { for (JvmTypeReference superType : object.getSuperTypes()) { doSwitch(superType); } return Boolean.TRUE; } return Boolean.FALSE; }
public JvmAnnotationValue getConstructorParameterAnnotationValue(String name) { String typeName = TestAnnotation.Annotated.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); JvmConstructor constructor = getConstructorFromType(type, TestAnnotation.Annotated.class, "Annotated(java.lang.String,java.lang.String,java.lang.String)"); JvmAnnotationTarget target = constructor.getParameters().get(0); return getExplicitAnnotationValue(name, target); }
@Override public boolean isVisible(JvmMember member) { // TODO private visibility? JvmVisibility visibility = member.getVisibility(); if (visibility == JvmVisibility.PUBLIC) { return true; } JvmDeclaredType type = member instanceof JvmDeclaredType ? (JvmDeclaredType) member : member.getDeclaringType(); if (type == rawContextType || EcoreUtil.isAncestor(rawContextType, type)) { return true; } if (type != null && visibility == JvmVisibility.PROTECTED) { if (superTypeNames == null) { this.superTypeNames = computeSuperTypeNames(); } if (superTypeNames.contains(type.getIdentifier())) { return true; } if (type == member) { JvmDeclaredType declaringType = member.getDeclaringType(); if (declaringType != null && superTypeNames.contains(declaringType.getIdentifier())) { return true; } } } if (type != null && (rawContextType == null || rawContextType instanceof JvmDeclaredType) && (visibility == JvmVisibility.DEFAULT || visibility == JvmVisibility.PROTECTED)) { if (Strings.isEmpty(packageName) && Strings.isEmpty(type.getPackageName()) || (packageName != null && packageName.equals(type.getPackageName()))) { return true; } } return parent.isVisible(member); }
@Test public void testDeprecatedBit_02() { String typeName = DeprecatedMembers.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); assertTrue(type.isSetDeprecated()); assertFalse(type.isDeprecated()); for (JvmMember member : type.getMembers()) { assertTrue(member.isSetDeprecated()); assertTrue(member.isDeprecated()); } }
private boolean hasStaticImport(Map<JvmDeclaredType, Set<String>> imports, String memberName) { for (Entry<JvmDeclaredType, Set<String>> entry : imports.entrySet()) { Set<String> value = entry.getValue(); if (value != null && value.contains(memberName)) { return true; } } return false; }
@Test public void testAnnotatedParameter_06() throws Exception { String typeName = TestAnnotation.Annotated.class.getName(); JvmAnnotationType annotationType = (JvmAnnotationType) getTypeProvider() .findTypeByName(TestAnnotation.NestedAnnotation.class.getName()); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, TestAnnotation.Annotated.class, "method(java.lang.String,java.lang.String,java.lang.String)"); JvmAnnotationTarget target = method.getParameters().get(2); assertEquals(1, target.getAnnotations().size()); JvmAnnotationReference annotationReference = target.getAnnotations().get(0); assertSame(annotationType, annotationReference.getAnnotation()); }
@Test public void testAnnotationWithStringDefault_01() throws Exception { String typeName = TestAnnotationWithStringDefault.Annotated.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); List<JvmAnnotationReference> annotations = type.getAnnotations(); assertEquals(1, annotations.size()); JvmAnnotationReference annotationReference = annotations.get(0); assertEquals(TestAnnotationWithStringDefault.class.getName(), annotationReference.getAnnotation().getIdentifier()); checkDefaultAnnotationValues(annotationReference); }
@Test public void testAnnotatedParameter_05() throws Exception { String typeName = TestAnnotation.Annotated.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); JvmOperation method = getMethodFromType(type, TestAnnotation.Annotated.class, "method(java.lang.String,java.lang.String,java.lang.String)"); JvmAnnotationTarget target = method.getParameters().get(1); assertEquals(0, target.getAnnotations().size()); }
@Test public void testAnnotationWithStringDefault_03() throws Exception { String typeName = TestAnnotationWithStringDefault.AnnotatedInterface.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); List<JvmAnnotationReference> annotations = type.getAnnotations(); assertEquals(1, annotations.size()); JvmAnnotationReference annotationReference = annotations.get(0); assertEquals(TestAnnotationWithStringDefault.class.getName(), annotationReference.getAnnotation().getIdentifier()); checkDefaultAnnotationValues(annotationReference); }
@SuppressWarnings("deprecation") @Test public void testDeprecatedBit_01() { String typeName = org.eclipse.xtext.common.types.testSetups.DeprecatedClass.class.getName(); JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName); assertTrue(type.isSetDeprecated()); assertTrue(type.isDeprecated()); for (JvmMember member : type.getMembers()) { assertTrue(member.isSetDeprecated()); assertFalse(member.isDeprecated()); } }
@Override protected void getAllLocalElements(TypeBucket bucket, JvmDeclaredType type, List<IEObjectDescription> result) { Iterable<JvmFeature> features = type.getAllFeatures(); for(JvmFeature feature: features) { if (feature.isStatic() && helper.isPossibleExtension(feature) && helper.isMatchingFirstParameterDeepCheck((JvmOperation) feature)) { fastAddDescriptions(feature, bucket, result); } } }
@Override public String getQualifiedName(char innerClassDelimiter) { JvmDeclaredType declaringType = getDeclaringType(); if (declaringType != null) return declaringType.getQualifiedName(innerClassDelimiter); return getSimpleName(); }
@Check public void checkNoForwardReferences(XExpression fieldInitializer) { JvmIdentifiableElement container = logicalContainerProvider.getLogicalContainer(fieldInitializer); if (container instanceof JvmField) { JvmField field = (JvmField) container; boolean staticField = field.isStatic(); JvmDeclaredType declaredType = field.getDeclaringType(); if (declaredType == null) { return; } Collection<JvmField> illegalFields = Sets.newHashSet(); for(int i = declaredType.getMembers().size() - 1; i>=0; i--) { JvmMember member = declaredType.getMembers().get(i); if (member instanceof JvmField) { if (((JvmField) member).isStatic() == staticField) { illegalFields.add((JvmField) member); } } if (member == field) break; } TreeIterator<EObject> iterator = EcoreUtil2.eAll(fieldInitializer); while(iterator.hasNext()) { EObject object = iterator.next(); if (object instanceof XFeatureCall) { JvmIdentifiableElement feature = ((XFeatureCall) object).getFeature(); if (illegalFields.contains(((XFeatureCall) object).getFeature())) { error("Cannot reference the field '" + feature.getSimpleName() + "' before it is defined", object, null, INSIGNIFICANT_INDEX, ILLEGAL_FORWARD_REFERENCE); } } else if (isLocalClassSemantics(object)) { iterator.prune(); } } } }
private boolean removeStaticImport(Map<String, List<XImportDeclaration>> staticImports, JvmMember member) { JvmDeclaredType declaringType = member.getDeclaringType(); String identifier = declaringType.getIdentifier(); List<XImportDeclaration> list = staticImports.get(identifier); if (list == null) { return false; } if (list.size() == 1) { staticImports.remove(identifier); return true; } int indexToRemove = -1; for (int i = 0; i < list.size(); i++) { XImportDeclaration staticImportDeclaration = list.get(i); if (staticImportDeclaration.isWildcard()) { if (indexToRemove == -1) { indexToRemove = i; } continue; } if (Objects.equal(member.getSimpleName(), staticImportDeclaration.getMemberName())) { indexToRemove = i; break; } } if (indexToRemove == -1) { indexToRemove = 0; } list.remove(indexToRemove); return true; }
/** * @deprecated build your own :-) */ @Deprecated public /* @Nullable */ JvmOperation toHashCodeMethod(/* @Nullable */ final EObject sourceElement, final boolean extendsSomethingWithProperHashCode, /* @Nullable */ final JvmDeclaredType declaredType) { if (sourceElement == null || declaredType == null) return null; return toHashCodeMethod(sourceElement, extendsSomethingWithProperHashCode, toArray(filter(declaredType.getMembers(), JvmField.class), JvmField.class)); }
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; }
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); } }
@Override protected void acceptType(JvmType type, JvmType usedType, ITextRegion refRegion) { JvmMember currentContext = getCurrentContext(); if (currentContext == null) { return; } if (type == null || type.eIsProxy()) { throw new IllegalArgumentException(); } if (type instanceof JvmDeclaredType && !isIgnored(type, refRegion)) { getTypeUsages().addTypeUsage((JvmDeclaredType) type, (JvmDeclaredType) usedType, refRegion, currentContext); } }
private List<ReplaceRegion> getReplacedUsageSites(Map<String, JvmDeclaredType> resolvedConflicts, TypeUsages typeUsages, RewritableImportSection newImportSection) { List<ReplaceRegion> result = newArrayList(); for (Map.Entry<String, JvmDeclaredType> textToType : resolvedConflicts.entrySet()) { getReplacedUsagesOf(textToType, typeUsages, newImportSection, result); } return result; }
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; }