List of usage examples for java.lang Class getInterfaces
public Class<?>[] getInterfaces()
From source file:org.compass.core.accessor.BasicPropertyAccessor.java
private static BasicSetter getSetterOrNull(Class theClass, String propertyName) { if (theClass == Object.class || theClass == null) return null; Method method = setterMethod(theClass, propertyName); if (method != null) { if (!ClassUtils.isPublic(theClass, method)) { method.setAccessible(true);//from w w w. j a v a 2 s. c om } return new BasicSetter(theClass, method, propertyName); } else { BasicSetter setter = getSetterOrNull(theClass.getSuperclass(), propertyName); if (setter == null) { Class[] interfaces = theClass.getInterfaces(); for (int i = 0; setter == null && i < interfaces.length; i++) { setter = getSetterOrNull(interfaces[i], propertyName); } } return setter; } }
From source file:gov.nih.nci.iso21090.hibernate.property.CollectionPropertyAccessor.java
/** * @param theClass Target class in which the value is to be set * @param propertyName Target property name * @return returns Setter class instance */// ww w . ja v a 2s . co m @SuppressWarnings("PMD.AccessorClassGeneration") private static CollectionPropertySetter getSetterOrNull(Class theClass, String propertyName) { if (theClass == Object.class || theClass == null) { return null; } Method method = setterMethod(theClass, propertyName); if (method != null) { if (!ReflectHelper.isPublic(theClass, method)) { method.setAccessible(true); } return new CollectionPropertySetter(theClass, method, propertyName); } else { CollectionPropertySetter setter = getSetterOrNull(theClass.getSuperclass(), propertyName); if (setter == null) { Class[] interfaces = theClass.getInterfaces(); for (int i = 0; setter == null && i < interfaces.length; i++) { setter = getSetterOrNull(interfaces[i], propertyName); } } return setter; } }
From source file:org.jiemamy.utils.reflect.GenericUtil.java
/** * ??(???)??????{@link Map}??/*from w ww .ja va 2s. c o m*/ * * @param clazz ??(???) * @return ????????{@link Map} * @throws IllegalArgumentException ?{@code null}??? */ public static Map<TypeVariable<?>, Type> getTypeVariableMap(Class<?> clazz) { Validate.notNull(clazz); Map<TypeVariable<?>, Type> map = Maps.newLinkedHashMap(); Class<?> superClass = clazz.getSuperclass(); Type superClassType = clazz.getGenericSuperclass(); if (superClass != null) { gatherTypeVariables(superClass, superClassType, map); } Class<?>[] interfaces = clazz.getInterfaces(); Type[] interfaceTypes = clazz.getGenericInterfaces(); for (int i = 0; i < interfaces.length; ++i) { gatherTypeVariables(interfaces[i], interfaceTypes[i], map); } return map; }
From source file:jp.terasoluna.fw.util.GenericsUtil.java
/** * ?????? <code>ParameterizedType</code>??? * @param <T> ???//from w w w. j a v a 2 s. c o m * @param genericClass ?? * @param ancestorTypeList <code>ParameterizedType</code> ? * @param clazz ? * @return ?????????<code>true</code> ????????<code>false</code> */ protected static <T> boolean checkInterfaceAncestors(Class<T> genericClass, List<ParameterizedType> ancestorTypeList, Class<?> clazz) { boolean genericTypeFound = false; Type[] interfaceTypes = clazz.getGenericInterfaces(); for (Type interfaceType : interfaceTypes) { genericTypeFound = checkParameterizedType(interfaceType, genericClass, ancestorTypeList); if (genericTypeFound) { return true; } @SuppressWarnings("rawtypes") Class[] interfaces = clazz.getInterfaces(); for (Class<?> interfaceClass : interfaces) { if (checkInterfaceAncestors(genericClass, ancestorTypeList, interfaceClass)) { return true; } } } return false; }
From source file:org.jiemamy.utils.reflect.GenericUtil.java
/** * ??(???)???????{@code map}??/* www . j a v a 2s .c o m*/ * * @param clazz * @param type * @param map ????????{@link Map} */ protected static void gatherTypeVariables(Class<?> clazz, Type type, Map<TypeVariable<?>, Type> map) { if (clazz == null) { return; } gatherTypeVariables(type, map); Class<?> superClass = clazz.getSuperclass(); Type superClassType = clazz.getGenericSuperclass(); if (superClass != null) { gatherTypeVariables(superClass, superClassType, map); } Class<?>[] interfaces = clazz.getInterfaces(); Type[] interfaceTypes = clazz.getGenericInterfaces(); for (int i = 0; i < interfaces.length; ++i) { gatherTypeVariables(interfaces[i], interfaceTypes[i], map); } }
From source file:org.eclipse.wb.internal.core.model.description.helpers.DescriptionHelper.java
/** * Adds {@link ClassResourceInfo}'s for given component class and all its super classes and * interfaces./*from w ww. ja va 2 s. c o m*/ */ public static void addDescriptionResources(LinkedList<ClassResourceInfo> descriptions, ILoadingContext context, Class<?> currentClass) throws Exception { if (currentClass != null) { ResourceInfo resource = getComponentDescriptionResource(context, currentClass); if (resource != null) { validateComponentDescription(resource); descriptions.addFirst(new ClassResourceInfo(currentClass, resource)); } // handle interfaces for (Class<?> interfaceClass : currentClass.getInterfaces()) { addDescriptionResources(descriptions, context, interfaceClass); } // handle super class addDescriptionResources(descriptions, context, currentClass.getSuperclass()); } }
From source file:com.google.gdt.eclipse.designer.ie.util.ReflectionUtils.java
/** * @return the {@link Field} of given class with given name or <code>null</code> if no such {@link Field} * found.//from w w w . ja v a 2 s . c o m */ public static Field getFieldByName(Class<?> clazz, String name) { Assert.isNotNull(clazz); Assert.isNotNull(name); // check fields of given class and its super classes while (clazz != null) { // check all declared field Field[] declaredFields = clazz.getDeclaredFields(); for (Field field : declaredFields) { if (field.getName().equals(name)) { field.setAccessible(true); return field; } } // check interfaces { Class<?>[] interfaceClasses = clazz.getInterfaces(); for (Class<?> interfaceClass : interfaceClasses) { Field field = getFieldByName(interfaceClass, name); if (field != null) { return field; } } } // check superclass clazz = clazz.getSuperclass(); } // not found return null; }
From source file:org.ballerinalang.composer.service.workspace.tools.ModelGenerator.java
public static JsonObject getContext() { // Set alias for the classes alias.put("ImportNode", "ImportPackageNode"); alias.put("RecordLiteralKeyValueNode", "RecordKeyValueNode"); alias.put("XmlnsNode", "XMLNSDeclarationNode"); alias.put("ArrayLiteralExprNode", "ArrayLiteralNode"); alias.put("BinaryExprNode", "BinaryExpressionNode"); alias.put("ConnectorInitExprNode", "ConnectorInitNode"); alias.put("FieldBasedAccessExprNode", "FieldBasedAccessNode"); alias.put("IndexBasedAccessExprNode", "IndexBasedAccessNode"); alias.put("LambdaNode", "LambdaFunctionNode"); alias.put("RecordLiteralExprNode", "RecordLiteralNode"); alias.put("SimpleVariableRefNode", "SimpleVariableReferenceNode"); alias.put("TernaryExprNode", "TernaryExpressionNode"); alias.put("TypeCastExprNode", "TypeCastNode"); alias.put("TypeConversionExprNode", "TypeConversionNode"); alias.put("UnaryExprNode", "UnaryExpressionNode"); alias.put("XmlAttributeNode", "XMLAttributeNode"); alias.put("XmlCommentLiteralNode", "XMLCommentLiteralNode"); alias.put("XmlElementLiteralNode", "XMLElementLiteralNode"); alias.put("XmlPiLiteralNode", "XMLProcessingInstructionLiteralNode"); alias.put("XmlQnameNode", "XMLQNameNode"); alias.put("XmlQuotedStringNode", "XMLQuotedStringNode"); alias.put("XmlTextLiteralNode", "XMLTextLiteralNode"); alias.put("TryNode", "TryCatchFinallyNode"); alias.put("VariableDefNode", "VariableDefinitionNode"); alias.put("BuiltInRefTypeNode", "BuiltInReferenceTypeNode"); alias.put("EnumeratorNode", "EnumNode"); List<Class<?>> list = ModelGenerator.find("org.ballerinalang.model.tree"); NodeKind[] nodeKinds = NodeKind.class.getEnumConstants(); JsonObject nodes = new JsonObject(); for (NodeKind node : nodeKinds) { String nodeKind = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, node.toString()); String nodeClassName = nodeKind + "Node"; try {/*from www .ja v a 2 s . c om*/ String actualClassName = (alias.get(nodeClassName) != null) ? alias.get(nodeClassName) : nodeClassName; Class<?> clazz = list.stream() .filter(nodeClass -> nodeClass.getSimpleName().equals(actualClassName)).findFirst().get(); JsonObject nodeObj = new JsonObject(); nodeObj.addProperty("kind", nodeKind); nodeObj.addProperty("name", nodeClassName); nodeObj.addProperty("fileName", CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, nodeClassName)); JsonArray attr = new JsonArray(); JsonArray bools = new JsonArray(); JsonArray imports = new JsonArray(); List<String> parents = Arrays.asList(clazz.getInterfaces()).stream() .map(parent -> parent.getSimpleName()).collect(Collectors.toList()); // tag object with supper type if (parents.contains("StatementNode")) { nodeObj.addProperty("isStatement", true); JsonObject imp = new JsonObject(); imp.addProperty("returnType", "StatementNode"); imp.addProperty("returnTypeFile", "statement-node"); imports.add(imp); } else { nodeObj.addProperty("isStatement", false); } if (parents.contains("ExpressionNode")) { nodeObj.addProperty("isExpression", true); JsonObject imp = new JsonObject(); imp.addProperty("returnType", "ExpressionNode"); imp.addProperty("returnTypeFile", "expression-node"); imports.add(imp); } else { nodeObj.addProperty("isExpression", false); } if (!parents.contains("StatementNode") && !parents.contains("ExpressionNode")) { JsonObject imp = new JsonObject(); imp.addProperty("returnType", "Node"); imp.addProperty("returnTypeFile", "node"); imports.add(imp); } Method[] methods = clazz.getMethods(); for (Method m : methods) { String methodName = m.getName(); if ("getKind".equals(methodName) || "getWS".equals(methodName) || "getPosition".equals(methodName)) { continue; } if (methodName.startsWith("get")) { JsonObject attribute = new JsonObject(); JsonObject imp = new JsonObject(); attribute.addProperty("property", toJsonName(m.getName(), 3)); attribute.addProperty("methodSuffix", m.getName().substring(3)); attribute.addProperty("list", List.class.isAssignableFrom(m.getReturnType())); attribute.addProperty("isNode", Node.class.isAssignableFrom(m.getReturnType())); if (Node.class.isAssignableFrom(m.getReturnType())) { String returnClass = m.getReturnType().getSimpleName(); if (alias.containsValue(m.getReturnType().getSimpleName())) { returnClass = getKindForAliasClass(m.getReturnType().getSimpleName()); } imp.addProperty("returnType", returnClass); attribute.addProperty("returnType", returnClass); imp.addProperty("returnTypeFile", CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, returnClass)); if (!imports.contains(imp)) { imports.add(imp); } } attr.add(attribute); } if (methodName.startsWith("is")) { JsonObject attribute = new JsonObject(); JsonObject imp = new JsonObject(); attribute.addProperty("property", toJsonName(m.getName(), 2)); attribute.addProperty("methodSuffix", m.getName().substring(2)); attribute.addProperty("list", List.class.isAssignableFrom(m.getReturnType())); attribute.addProperty("isNode", Node.class.isAssignableFrom(m.getReturnType())); if (Node.class.isAssignableFrom(m.getReturnType())) { String returnClass = m.getReturnType().getSimpleName(); if (alias.containsValue(m.getReturnType().getSimpleName())) { returnClass = getKindForAliasClass(m.getReturnType().getSimpleName()); } imp.addProperty("returnType", returnClass); attribute.addProperty("returnType", returnClass); imp.addProperty("returnTypeFile", CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, returnClass)); if (!imports.contains(imp)) { imports.add(imp); } } bools.add(attribute); } } nodeObj.add("attributes", attr); nodeObj.add("bools", bools); nodeObj.add("imports", imports); nodes.add(nodeClassName, nodeObj); } catch (NoSuchElementException e) { out.println("alias.put(\"" + nodeClassName + "\", \"\");"); } } out.println(nodes); return nodes; }
From source file:com.dnw.json.J.java
/** * Finds the corresponding type converter. * /*from w w w . ja va2 s . c om*/ * @author manbaum * @since Oct 14, 2014 * @param type the given type. * @return the corresponding type converter. */ private final static K<?> findConverter(Class<?> type) { K<?> k = cache.get(type); if (k != null) return k; k = map.get(type); if (k != null) { cache.put(type, k); return k; } Class<?> s = type.getSuperclass(); if (s != null) { k = findConverter(s); if (k != null) return k; } for (Class<?> i : type.getInterfaces()) { k = findConverter(i); if (k != null) return k; } return null; }
From source file:org.apache.openjpa.enhance.Reflection.java
/** * Gets the declaring class of the given method signature but also checks * if the method is declared in an interface. If yes, then returns the * interface. //from w ww . ja v a 2 s. c o m */ public static Class getDeclaringClass(Method m) { if (m == null) return null; Class cls = m.getDeclaringClass(); Class[] intfs = cls.getInterfaces(); for (Class intf : intfs) { if (getDeclaringMethod(intf, m) != null) cls = intf; } return cls; }