public static boolean isGeneric(JavaType type) { return type.getAttributes().containsKey(IS_GENERIC) && (type.getAttributes().get(IS_GENERIC) instanceof Boolean) && (Boolean) type.getAttributes().get(IS_GENERIC); } }
public static final Set<JavaType> getTerminatingTypes(JavaType type) { Set<JavaType> result = new LinkedHashSet<JavaType>(); if (type.getAttributes().containsKey(TERMINATING_TYPES)) { result.addAll((Collection<JavaType>) type.getAttributes().get(TERMINATING_TYPES)); } if (type.getAttributes().containsKey(IS_COMPOSITE) && (Boolean) type.getAttributes().get(IS_TERMINAL) && !(type.getAttributes().get(ORIGINAL_RETURN_TYPE).equals(TRANSPARENT))) { result.add((JavaType) type.getAttributes().get(ORIGINAL_RETURN_TYPE)); } return result; }
private static Set<String> getKeywords(Set<JavaType> types) { Set<String> result = new LinkedHashSet<String>(); for (JavaType type : types) { Set<String> keywords = (Set<String>) type.getAttributes().get(KEYWORDS); result.addAll(keywords != null ? keywords : Collections.<String>emptySet()); } return result; } }
public static boolean isEntryPoint(JavaClazz clazz) { return clazz.getType().getAttributes().containsKey(IS_ENTRYPOINT) && (clazz.getType().getAttributes().get(IS_ENTRYPOINT) instanceof Boolean) && (Boolean) clazz.getType().getAttributes().get(IS_ENTRYPOINT); }
public static boolean isCardinalityMultiple(JavaClazz clazz) { return clazz.getType().getAttributes().containsKey(CARDINALITY_MULTIPLE) && (clazz.getType().getAttributes().get(CARDINALITY_MULTIPLE) instanceof Boolean) && (Boolean) clazz.getType().getAttributes().get(CARDINALITY_MULTIPLE); }
public static boolean isTerminal(JavaClazz clazz) { return clazz.getType().getAttributes().containsKey(IS_TERMINAL) && (clazz.getType().getAttributes().get(IS_TERMINAL) instanceof Boolean) && (Boolean) clazz.getType().getAttributes().get(IS_TERMINAL); }
private static boolean isSatisfied(JavaClazz candidate, Set<JavaType> visited) { Set<String> visitedKeywords = getKeywords(visited); Boolean multiple = (Boolean) candidate.getType().getAttributes().get(CARDINALITY_MULTIPLE); Set<String> requiresAll = (Set<String>) candidate.getType().getAttributes().get(REQUIRES_ALL); Set<String> requiresAny = (Set<String>) candidate.getType().getAttributes().get(REQUIRES_ANY); Set<String> exclusive = (Set<String>) candidate.getType().getAttributes().get(EXCLUSIVE); //Eliminate circles if not supported if (!multiple && visited.contains(candidate.getType())) { return false; } //Check if path contains exclusive keywords for (String e : exclusive) { if (visitedKeywords.contains(e)) { return false; } } //Check if "All" requirements are meet for (String a : requiresAll) { if (!visitedKeywords.contains(a)) { return false; } } for (String a : requiresAny) { if (visitedKeywords.contains(a)) { return true; } } return requiresAny.isEmpty(); }
private static Set<JavaType> findGenerifiables(Set<JavaClazz> interfaces) { if (interfaces.size() < 2) { return Collections.<JavaType>emptySet(); } //1st pass find all generics Set<JavaType> allGenerics = new LinkedHashSet<JavaType>(); for (JavaClazz clazz : interfaces) { popullateGenericTypes(clazz.getType(), allGenerics); } //2nd pass collect common generics Set<JavaType> common = new LinkedHashSet<JavaType>(allGenerics); for (JavaClazz clazz : interfaces) { Set<JavaType> ownGenerics = new LinkedHashSet<JavaType>(); popullateGenericTypes(clazz.getType(), ownGenerics); common.remove(clazz.getType()); common.retainAll(ownGenerics); } Set<JavaType> result = new LinkedHashSet<JavaType>(); for (JavaType type : common) { Boolean isGeneric = type.getAttributes().containsKey(IS_GENERIC) ? (Boolean) type.getAttributes().get(IS_GENERIC) : false; if (!isGeneric) { result.add(type); } } return result; }
@Override public JavaProperty apply(VariableElement variableElement) { JavaProperty property = delegate.apply(variableElement); boolean isBuildable = property.getType().getAttributes().containsKey(BUILDABLE) ? (Boolean) property.getType().getAttributes().get(BUILDABLE) : false; Map<String, Object> attributes = new HashMap<String, Object>(property.getAttributes()); attributes.put(BUILDABLE, isBuildable); return new JavaPropertyBuilder(property).withAttributes(attributes).build(); } }
@Override public JavaType apply(String fullName) { JavaType type = delegate.apply(fullName); if (type == null) { return null; } TypeElement typeElement = elements.getTypeElement(fullName); boolean isBuildable = false; if (fullName.endsWith("[]")) { typeElement = elements.getTypeElement(fullName.substring(0, fullName.length() - 2)); isBuildable = isBuildable(typeElement); } else if (type.isCollection()) { for (JavaType genericType : type.getGenericTypes()) { isBuildable = isBuildable(elements.getTypeElement(genericType.getFullyQualifiedName())); } } else { isBuildable = isBuildable(typeElement); } Map<String, Object> attributes = new HashMap<String, Object>(type.getAttributes()); attributes.put(BUILDABLE, isBuildable); return new JavaTypeBuilder(type).withAttributes(attributes).build(); }
boolean buildable = (Boolean) toAdd.getType().getAttributes().get(BUILDABLE); if (toAdd.isArray()) { JavaProperty asList = arrayAsList(toAdd, buildable);