public TypeDeclarationError(AbstractClassTypeDeclarationDescr typeDescr, String errorMessage) { super(typeDescr.getResource()); this.errorMessage = errorMessage; this.line = new int[] { typeDescr.getLine() }; this.namespace = typeDescr.getNamespace(); }
/** * Checks whether a declaration is novel, or is a retagging of an external * one * * @param typeDescr * @return */ private boolean isNovelClass( AbstractClassTypeDeclarationDescr typeDescr ) { try { PackageRegistry reg = this.pkgRegistryMap.get( typeDescr.getNamespace() ); if ( reg != null ) { String availableName = typeDescr.getType().getFullName(); reg.getTypeResolver().resolveType( availableName ); return false; } else { return false; } } catch (ClassNotFoundException cnfe) { return true; } }
String qName = typeDescr.getType().getFullName(); Class typeClass = getClassForType(qName); if (typeClass == null) { typeClass = getClassForType(typeDescr.getTypeName()); int separator = imp.lastIndexOf( '.' ); String tail = imp.substring( separator + 1 ); if (tail.equals( typeDescr.getTypeName() )) { typeDescr.setNamespace( imp.substring( 0, separator ) ); typeClass = getClassForType(typeDescr.getType().getFullName()); break; int dotPos = className.lastIndexOf( '.' ); if (dotPos >= 0) { typeDescr.setNamespace( className.substring( 0, dotPos ) ); typeDescr.setTypeName( className.substring( dotPos + 1 ) ); if ( isEmpty( typeDescr.getNamespace() ) && typeDescr.getFields().isEmpty() ) { Class<?> clz = pkgReg.getTypeResolver().resolveType( typeDescr.getTypeName() ); java.lang.Package pkg = clz.getPackage(); if (pkg != null) { typeDescr.setNamespace( pkg.getName() ); int index = typeDescr.getNamespace() != null && !typeDescr.getNamespace().isEmpty() ? typeDescr.getNamespace().length() + 1 : 0; typeDescr.setTypeName( clz.getName().substring( index ) ); if ( isEmpty( typeDescr.getNamespace() ) ) { typeDescr.setNamespace( packageDescr.getNamespace() ); // set the default namespace
String fullName = typeDescr.getType().getFullName(); AnnotationDescr traitableAnn = typeDescr.getAnnotation( Traitable.class.getSimpleName() ); boolean traitable = traitableAnn != null; String[] fullSuperTypes = new String[typeDescr.getSuperTypes().size() + 1]; int j = 0; for ( QualifiedName qname : typeDescr.getSuperTypes() ) { fullSuperTypes[j++] = qname.getFullName(); for (String annotationName : typeDescr.getAnnotationNames()) { Class annotation = resolveAnnotation( annotationName, pkgRegistry.getTypeResolver() ); try { AnnotationDefinition annotationDefinition = AnnotationDefinition.build( annotation, typeDescr.getAnnotations().get( annotationName ).getValueMap(), pkgRegistry.getTypeResolver() ); def.addAnnotation( annotationDefinition ); def.addMetaData( annotationName, typeDescr.getAnnotation( annotationName ).getSingleValue() ); if (!typeDescr.getFields().isEmpty()) { PriorityQueue<FieldDefinition> fieldDefs = sortFields( typeDescr.getFields(), pkgRegistry ); int n = fieldDefs.size(); TypeDeclaration previousTypeDeclaration = this.pkgRegistryMap.get( typeDescr.getNamespace() ).getPackage().getTypeDeclaration( typeDescr.getTypeName() );
if ( typeDescr.getAnnotation( Traitable.class.getSimpleName() ) != null || ( ! type.getKind().equals( TypeDeclaration.Kind.TRAIT ) && pkgRegistryMap.containsKey( def.getSuperClass() ) && if (!isNovelClass( typeDescr )) { try { PackageRegistry reg = this.pkgRegistryMap.get( typeDescr.getNamespace() ); String availableName = typeDescr.getType().getFullName(); Class<?> resolvedType = reg.getTypeResolver().resolveType( availableName ); updateTraitDefinition( type, || typeDescr.getAnnotation( Trait.class.getSimpleName() ) != null ) { PackageRegistry reg = this.pkgRegistryMap.get( typeDescr.getNamespace() ); String availableName = typeDescr.getType().getFullName(); Class<?> resolvedType = reg.getTypeResolver().resolveType( availableName ); if ( ! Thing.class.isAssignableFrom( resolvedType ) ) { String target = typeDescr.getTypeName() + TraitFactory.SUFFIX; TypeDeclarationDescr tempDescr = new TypeDeclarationDescr(); tempDescr.setNamespace( typeDescr.getNamespace() ); tempDescr.setFields( typeDescr.getFields() ); tempDescr.setType( target, typeDescr.getNamespace() ); tempDescr.addSuperType( typeDescr.getType() ); TypeDeclaration tempDeclr = new TypeDeclaration( target ); tempDeclr.setKind( TypeDeclaration.Kind.TRAIT ); String fullName = typeDescr.getType().getFullName();
QualifiedName name = tdescr.getType(); } else { this.results.add( new TypeDeclarationError( tdescr, "Found duplicate declaration for type " + tdescr.getTypeName() ) ); for ( QualifiedName sup : tdescr.getSuperTypes() ) { if ( ! Object.class.getName().equals( name.getFullName() ) ) { if ( ! hasCircularDependency( tdescr.getType(), sup, taxonomy ) ) { supers.add( sup ); } else { circular = true; this.results.add( new TypeDeclarationError( tdescr, "Found circular dependency for type " + tdescr.getTypeName() ) ); break; tdescr.getSuperTypes().clear(); for ( TypeFieldDescr field : tdescr.getFields().values() ) { QualifiedName typeName = new QualifiedName( field.getPattern().getObjectType() ); if ( ! hasCircularDependency( name, typeName, taxonomy ) ) {
AnnotationDescr annotationDescr = typeDescr.getAnnotation( TypeDeclaration.ATTR_TIMESTAMP ); String timestamp = ( annotationDescr != null ) ? annotationDescr.getSingleValue() : null; if (timestamp != null) { annotationDescr = typeDescr.getAnnotation( TypeDeclaration.ATTR_DURATION ); String duration = ( annotationDescr != null ) ? annotationDescr.getSingleValue() : null; if (duration != null) { annotationDescr = typeDescr.getAnnotation( TypeDeclaration.ATTR_EXPIRE ); String expiration = ( annotationDescr != null ) ? annotationDescr.getSingleValue() : null; if (expiration != null) { boolean dynamic = typeDescr.getAnnotationNames().contains( TypeDeclaration.ATTR_PROP_CHANGE_SUPPORT ); type.setDynamic( dynamic ); boolean propertyReactive = propertySpecificOption.isPropSpecific( typeDescr.getAnnotationNames().contains(TypeDeclaration.ATTR_PROP_SPECIFIC), typeDescr.getAnnotationNames().contains(TypeDeclaration.ATTR_NOT_PROP_SPECIFIC)); setPropertyReactive(typeDescr.getResource(), type, propertyReactive);
private void fillFieldTypes( AbstractClassTypeDeclarationDescr typeDescr, PackageDescr packageDescr ) { for (TypeFieldDescr field : typeDescr.getFields().values()) { String declaredType = field.getPattern().getObjectType(); if (declaredType != null) { int separator = declaredType.lastIndexOf( "." ); boolean qualified = separator > 0; // check if a simple name corresponds to a f.q.n. if (!qualified) { declaredType = resolveType( declaredType, packageDescr, this.pkgRegistryMap.get( typeDescr.getNamespace() ) ); field.getPattern().setObjectType( declaredType ); } } } }
public void addField( TypeFieldDescr field ) { if ( this.fields == null ) { this.fields = new LinkedHashMap<String, TypeFieldDescr>(); } field.setResource(getResource()); this.fields.put( field.getFieldName(), field ); }