public static Set<String> getKeywords(Collection<TypeDef> types) { Set<String> result = new HashSet<String>(); for (TypeDef type : types) { Set<String> keywords = (Set<String>) type.getAttributes().get(KEYWORDS); if (keywords != null) { result.addAll(keywords); } } return result; }
public Set<String> scopeKeywords(Collection<TypeDef> clazzes) { Set<String> result = new LinkedHashSet<String>(); for (TypeDef clazz : clazzes) { Set<String> keywords = (Set<String>) clazz.getAttributes().get(KEYWORDS); result.addAll(keywords != null ? keywords : Collections.<String>emptySet()); } return result; } };
public static Set<String> getClasses(Collection<TypeDef> types) { Set<String> result = new HashSet<String>(); for (TypeDef type : types) { Set<String> classes = (Set<String>) type.getAttributes().get(CLASSES); if (classes != null) { result.addAll(classes); } } return result; }
public static Set<String> getMethods(Collection<TypeDef> types) { Set<String> result = new HashSet<String>(); for (TypeDef type : types) { Set<String> methods = (Set<String>) type.getAttributes().get(METHODS); if (methods != null) { result.addAll(methods); } } return result; }
public static LinkedList<String> getScopes(Collection<TypeDef> types) { Stack<String> stack = new Stack<String>(); for (TypeDef type : types) { String scope = (String) type.getAttributes().get(BEGIN_SCOPE); if (scope != null && !scope.isEmpty()) { stack.push(scope); } scope = (String) type.getAttributes().get(END_SCOPE); if (scope != null && !scope.isEmpty()) { try { String found = stack.pop(); if (!scope.equals(found)) { throw new IllegalStateException("End of scope:" + scope + " but active scope was:" + found); } } catch (EmptyStackException e) { throw new IllegalStateException("Expected active scope:" + scope + " but not was active.", e); } } } return new LinkedList<String>(stack); } }
public static boolean isSatisfied(TypeDef candidate, List<TypeDef> path) { Set<String> keywordsAndScopes = new LinkedHashSet<String>(); Set<String> visitedKeywords = getKeywords(path); Deque<String> activeScopes = getScopes(path); keywordsAndScopes.addAll(visitedKeywords); keywordsAndScopes.addAll(activeScopes); TransitionFilter filter = (TransitionFilter) candidate.getAttributes().get(FILTER); Boolean multiple = (Boolean) candidate.getAttributes().get(CARDINALITY_MULTIPLE); Set<String> keywords = (Set<String>) candidate.getAttributes().get(KEYWORDS); if (!activeScopes.isEmpty() && !keywords.contains(activeScopes.getLast())) { return false; } int lastIndex = path.lastIndexOf(candidate); if (!multiple && path.contains(candidate)) { //Eliminate circles if not explicitly specified return false; } else if (multiple && lastIndex > 0 && lastIndex < path.size() - 1) { //We only accept repetition of the last element. Other wise we can end up in infinite loops return false; } return filter.apply(path); }
/** * Creates a {@link ClassRef} for the current definition with the specified arguments. * * @param arguments The arguments to be passed to the reference. */ public ClassRef toReference(List<TypeRef> arguments) { List<TypeRef> actualArguments = new ArrayList<TypeRef>(); for (int i = 0; i < parameters.size(); i++) { if (i < arguments.size()) { actualArguments.add(arguments.get(i)); } else { actualArguments.add(new WildcardRef()); } } return new ClassRefBuilder() .withDefinition(this) .withArguments(actualArguments) .withAttributes(getAttributes()) .build(); }
if (getAttributes().containsKey(ALSO_IMPORT)) { Object obj = getAttributes().get(ALSO_IMPORT); if (obj instanceof ClassRef) { refs.add((ClassRef) obj);
/** * Creates a {@link ClassRef} for the current definition with the specified arguments. * * @param arguments The arguments to be passed to the reference. */ public ClassRef toReference(TypeRef... arguments) { List<TypeRef> actualArguments = new ArrayList<TypeRef>(); for (int i = 0; i < parameters.size(); i++) { if (i < arguments.length) { actualArguments.add(arguments[i]); } else { actualArguments.add(new WildcardRef()); } } return new ClassRefBuilder() .withDefinition(this) .withArguments(actualArguments) .withAttributes(getAttributes()) .build(); }
/** * Creates a {@link ClassRef} for internal use inside the scope of the type (methods, properties * etc). It uses as arguments the same 'letters' as the parameters definition. */ public ClassRef toInternalReference() { List<TypeRef> arguments = new ArrayList<TypeRef>(); for (TypeParamDef parameter : parameters) { arguments.add(parameter.toReference()); } return new ClassRefBuilder() .withDefinition(this) .withArguments(arguments) .withAttributes(getAttributes()) .build(); }
if (typeDef.getAttributes().containsKey(EDIATABLE_ENABLED) && (Boolean) typeDef.getAttributes().get(EDIATABLE_ENABLED)) { generateFromResources(ClazzAs.EDITABLE_BUILDER.apply(typeDef), Constants.DEFAULT_SOURCEFILE_TEMPLATE_LOCATION);
.withAnnotations(annotationRefs) .addToAnnotations(inheritedPojoRef) .withAttributes(item.getAttributes()) .build()); .withImplementsList(implementsList) .withExtendsList(extendsList) .addToAttributes(item.getAttributes()) .build();
public TypeDefFluentImpl(TypeDef instance){ this.withKind(instance.getKind()); this.withPackageName(instance.getPackageName()); this.withName(instance.getName()); this.withComments(instance.getComments()); this.withAnnotations(instance.getAnnotations()); this.withExtendsList(instance.getExtendsList()); this.withImplementsList(instance.getImplementsList()); this.withParameters(instance.getParameters()); this.withProperties(instance.getProperties()); this.withConstructors(instance.getConstructors()); this.withMethods(instance.getMethods()); this.withOuterType(instance.getOuterType()); this.withInnerTypes(instance.getInnerTypes()); this.withModifiers(instance.getModifiers()); this.withAttributes(instance.getAttributes()); }
public TypeDefBuilder(TypeDef instance,Boolean validationEnabled){ this.fluent = this; this.withKind(instance.getKind()); this.withPackageName(instance.getPackageName()); this.withName(instance.getName()); this.withComments(instance.getComments()); this.withAnnotations(instance.getAnnotations()); this.withExtendsList(instance.getExtendsList()); this.withImplementsList(instance.getImplementsList()); this.withParameters(instance.getParameters()); this.withProperties(instance.getProperties()); this.withConstructors(instance.getConstructors()); this.withMethods(instance.getMethods()); this.withOuterType(instance.getOuterType()); this.withInnerTypes(instance.getInnerTypes()); this.withModifiers(instance.getModifiers()); this.withAttributes(instance.getAttributes()); this.validationEnabled = validationEnabled; }
public TypeDefBuilder(TypeDefFluent<?> fluent,TypeDef instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withKind(instance.getKind()); fluent.withPackageName(instance.getPackageName()); fluent.withName(instance.getName()); fluent.withComments(instance.getComments()); fluent.withAnnotations(instance.getAnnotations()); fluent.withExtendsList(instance.getExtendsList()); fluent.withImplementsList(instance.getImplementsList()); fluent.withParameters(instance.getParameters()); fluent.withProperties(instance.getProperties()); fluent.withConstructors(instance.getConstructors()); fluent.withMethods(instance.getMethods()); fluent.withOuterType(instance.getOuterType()); fluent.withInnerTypes(instance.getInnerTypes()); fluent.withModifiers(instance.getModifiers()); fluent.withAttributes(instance.getAttributes()); this.validationEnabled = validationEnabled; } public TypeDefBuilder(TypeDef instance){