List of usage examples for java.lang.reflect Modifier isInterface
public static boolean isInterface(int mod)
From source file:uk.gov.gchq.gaffer.example.gettingstarted.walkthrough.WalkthroughRunner.java
private static void keepPublicConcreteClasses(final List classes) { if (null != classes) { final Iterator<Class> itr = classes.iterator(); for (Class clazz = null; itr.hasNext(); clazz = itr.next()) { if (null != clazz) { final int modifiers = clazz.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers) || Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) { itr.remove();// ww w . j a va 2 s.co m } } } } }
From source file:org.lightjason.agentspeak.common.CCommon.java
/** * get all classes within an Java package as action * * @param p_package full-qualified package name or empty for default package * @return action stream/* w w w. jav a 2s. co m*/ */ @SuppressWarnings("unchecked") public static Stream<IAction> actionsFromPackage(final String... p_package) { return ((p_package == null) || (p_package.length == 0) ? Stream.of(MessageFormat.format("{0}.{1}", PACKAGEROOT, "action.buildin")) : Arrays.stream(p_package)).flatMap(j -> { try { return ClassPath.from(Thread.currentThread().getContextClassLoader()) .getTopLevelClassesRecursive(j).parallelStream().map(ClassPath.ClassInfo::load) .filter(i -> !Modifier.isAbstract(i.getModifiers())) .filter(i -> !Modifier.isInterface(i.getModifiers())) .filter(i -> Modifier.isPublic(i.getModifiers())) .filter(IAction.class::isAssignableFrom).map(i -> { try { return (IAction) i.newInstance(); } catch (final IllegalAccessException | InstantiationException l_exception) { LOGGER.warning(CCommon.languagestring(CCommon.class, "actioninstantiate", i, l_exception)); return null; } }) // action can be instantiate .filter(Objects::nonNull) // check usable action name .filter(CCommon::actionusable); } catch (final IOException l_exception) { throw new UncheckedIOException(l_exception); } }); }
From source file:org.glowroot.agent.weaving.ClassAnalyzer.java
ClassAnalyzer(ThinClass thinClass, List<Advice> advisors, List<ShimType> shimTypes, List<MixinType> mixinTypes, @Nullable ClassLoader loader, AnalyzedWorld analyzedWorld, @Nullable CodeSource codeSource, byte[] classBytes, @Nullable Class<?> classBeingRedefined, boolean noLongerNeedToWeaveMainMethods) { this.thinClass = thinClass; this.loader = loader; ImmutableList<String> interfaceNames = ClassNames.fromInternalNames(thinClass.interfaces()); className = ClassNames.fromInternalName(thinClass.name()); intf = Modifier.isInterface(thinClass.access()); String superClassName = ClassNames.fromInternalName(thinClass.superName()); analyzedClassBuilder = ImmutableAnalyzedClass.builder().modifiers(thinClass.access()).name(className) .superName(superClassName).addAllInterfaceNames(interfaceNames); boolean ejbRemote = false; boolean ejbStateless = false; for (String annotation : thinClass.annotations()) { if (annotation.equals("Ljavax/ejb/Remote;")) { ejbRemote = true;/*from w ww . ja v a 2s . c o m*/ } else if (annotation.equals("Ljavax/ejb/Stateless;")) { ejbStateless = true; } } ParseContext parseContext = ImmutableParseContext.of(className, codeSource); List<AnalyzedClass> interfaceAnalyzedHierarchy = Lists.newArrayList(); // it's ok if there are duplicates in the superAnalyzedClasses list (e.g. an interface // that appears twice in a type hierarchy), it's rare, dups don't cause an issue for // callers, and so it doesn't seem worth the (minor) performance hit to de-dup every // time List<AnalyzedClass> superAnalyzedClasses = Lists.newArrayList(); for (String interfaceName : interfaceNames) { interfaceAnalyzedHierarchy .addAll(analyzedWorld.getAnalyzedHierarchy(interfaceName, loader, className, parseContext)); } superAnalyzedClasses.addAll(interfaceAnalyzedHierarchy); if (intf) { matchedShimTypes = getMatchedShimTypes(shimTypes, className, ImmutableList.<AnalyzedClass>of(), ImmutableList.<AnalyzedClass>of()); matchedMixinTypes = getMatchedMixinTypes(mixinTypes, className, classBeingRedefined, ImmutableList.<AnalyzedClass>of(), ImmutableList.<AnalyzedClass>of()); hasMainMethod = false; isClassLoader = false; } else { List<AnalyzedClass> superAnalyzedHierarchy = analyzedWorld.getAnalyzedHierarchy(superClassName, loader, className, parseContext); superAnalyzedClasses.addAll(superAnalyzedHierarchy); matchedShimTypes = getMatchedShimTypes(shimTypes, className, superAnalyzedHierarchy, interfaceAnalyzedHierarchy); matchedMixinTypes = getMatchedMixinTypes(mixinTypes, className, classBeingRedefined, superAnalyzedHierarchy, interfaceAnalyzedHierarchy); if (noLongerNeedToWeaveMainMethods) { hasMainMethod = false; } else { hasMainMethod = hasMainOrPossibleProcrunStartMethod(thinClass.nonBridgeMethods()) || className.equals("org.apache.commons.daemon.support.DaemonLoader"); } if (className.startsWith("org.glowroot.agent.tests.")) { // e.g. see AnalyzedClassPlanBeeWithMoreBadPreloadCacheIT isClassLoader = false; } else { boolean isClassLoader = false; for (AnalyzedClass superAnalyzedClass : superAnalyzedHierarchy) { if (superAnalyzedClass.name().equals(ClassLoader.class.getName())) { isClassLoader = true; break; } } this.isClassLoader = isClassLoader; } } analyzedClassBuilder.addAllShimTypes(matchedShimTypes); analyzedClassBuilder.addAllMixinTypes(matchedMixinTypes.reweavable()); analyzedClassBuilder.addAllNonReweavableMixinTypes(matchedMixinTypes.nonReweavable()); if ((ejbRemote || ejbStateless) && !intf) { Set<String> ejbRemoteInterfaces = getEjbRemoteInterfaces(thinClass, superAnalyzedClasses); if (ejbRemoteInterfaces.isEmpty()) { this.superAnalyzedClasses = ImmutableList.copyOf(superAnalyzedClasses); analyzedClassBuilder.ejbRemote(ejbRemote); } else if (loader == null) { logger.warn("instrumenting @javax.ejb.Remote not currently supported in bootstrap" + " class loader: {}", className); this.superAnalyzedClasses = ImmutableList.copyOf(superAnalyzedClasses); analyzedClassBuilder.ejbRemote(false); } else { List<AnalyzedClass> ejbHackedSuperAnalyzedClasses = hack(thinClass, loader, superAnalyzedClasses, ejbRemoteInterfaces); this.superAnalyzedClasses = ImmutableList.copyOf(ejbHackedSuperAnalyzedClasses); analyzedClassBuilder.ejbRemote(true); } } else { this.superAnalyzedClasses = ImmutableList.copyOf(superAnalyzedClasses); analyzedClassBuilder.ejbRemote(ejbRemote); } Set<String> superClassNames = Sets.newHashSet(); superClassNames.add(className); for (AnalyzedClass analyzedClass : superAnalyzedClasses) { superClassNames.add(analyzedClass.name()); } this.superClassNames = ImmutableSet.copyOf(superClassNames); adviceMatchers = AdviceMatcher.getAdviceMatchers(className, thinClass.annotations(), superClassNames, advisors); if (intf) { shortCircuitBeforeAnalyzeMethods = false; } else { shortCircuitBeforeAnalyzeMethods = !hasSuperAdvice(this.superAnalyzedClasses) && matchedShimTypes.isEmpty() && matchedMixinTypes.reweavable().isEmpty() && adviceMatchers.isEmpty(); } this.classBytes = classBytes; this.hackAdvisors = loader != null; }
From source file:org.gvnix.service.roo.addon.addon.ws.export.WSExportXmlElementMetadata.java
public WSExportXmlElementMetadata(String id, JavaType aspectName, PhysicalTypeMetadata physicalType, List<FieldMetadata> fields, JavaParserService javaParserService) { super(id, aspectName, physicalType); // Validate metadata identifier is of type gvNIX xml element metadata Validate.isTrue(isValid(id), "Metadata identification string '" + id + "' does not appear to be valid"); if (!isValid()) { return;/*from ww w . j a v a2 s .c o m*/ } // Get the gvNIX xml element annotation AnnotationMetadata annotation = governorTypeDetails .getTypeAnnotation(new JavaType(GvNIXXmlElement.class.getName())); if (annotation != null) { // Add to class XmlRoot, XmlType and XmlEnum or XmlAccessorType List<AnnotationMetadata> annotationTypeList = getAnnotations(annotation, fields); for (AnnotationMetadata annotationMetadata : annotationTypeList) { builder.addAnnotation(annotationMetadata); } // If is not a enumeration type if (!governorTypeDetails.getPhysicalTypeCategory().equals(PhysicalTypeCategory.ENUMERATION)) { // Add XmlElement annotation for each field List<DeclaredFieldAnnotationDetails> declaredFields = getXmlElementAnnotations(fields, javaParserService); for (DeclaredFieldAnnotationDetails declaredField : declaredFields) { builder.addFieldAnnotation(declaredField); } // Avoid if abstract class or interface (can't add method) if (!Modifier.isAbstract(governorTypeDetails.getModifier()) && !Modifier.isInterface(governorTypeDetails.getModifier())) { // Add annotation and method to avoid cycles convert to XML addCycleDetection(id); } } } // Build the aspect Java defined into builder itdTypeDetails = builder.build(); }
From source file:org.spring.guice.module.GuiceModuleMetadata.java
private boolean visible(Class<?> type) { Class<?> cls = type;// www . ja v a 2 s. c o m while (cls != null && cls != Object.class) { if (!Modifier.isInterface(cls.getModifiers()) && !Modifier.isPublic(cls.getModifiers()) && !Modifier.isProtected(cls.getModifiers())) { return false; } cls = cls.getDeclaringClass(); } return true; }
From source file:uk.gov.gchq.gaffer.schemabuilder.service.SchemaBuilderService.java
private static void keepPublicConcreteClasses(final Collection<Class> classes) { if (null != classes) { final Iterator<Class> itr = classes.iterator(); for (Class clazz = null; itr.hasNext(); clazz = itr.next()) { if (null != clazz) { final int modifiers = clazz.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers) || Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) { itr.remove();//from w ww .j a va 2s .co m } } } } }
From source file:gaffer.rest.service.SimpleGraphConfigurationService.java
private static void keepPublicConcreteClasses(final Collection<Class> classes) { if (null != classes) { final Iterator<Class> itr = classes.iterator(); while (itr.hasNext()) { final Class clazz = itr.next(); if (null != clazz) { final int modifiers = clazz.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers) || Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) { itr.remove();//from w ww. ja va 2 s. co m } } } } }
From source file:com.dragome.compiler.parser.Parser.java
public TypeDeclaration parse() { DescendingVisitor classWalker = new DescendingVisitor(jc, new EmptyVisitor() { public void visitConstantClass(ConstantClass obj) { ConstantPool cp = jc.getConstantPool(); String bytes = obj.getBytes(cp); fileUnit.addDependency(bytes.replace("/", ".")); }/*from www .j ava 2s. com*/ }); classWalker.visit(); org.apache.bcel.classfile.Method[] bcelMethods = jc.getMethods(); ObjectType type = new ObjectType(jc.getClassName()); Map<String, String> annotationsValues = getAnnotationsValues(jc.getAttributes()); TypeDeclaration typeDecl = new TypeDeclaration(type, jc.getAccessFlags(), annotationsValues); Project.singleton.addTypeAnnotations(typeDecl); fileUnit.isInterface = Modifier.isInterface(typeDecl.getAccess()); fileUnit.isAbstract = Modifier.isAbstract(typeDecl.getAccess()); fileUnit.setAnnotations(annotationsValues); if (!type.getClassName().equals("java.lang.Object")) { ObjectType superType = new ObjectType(jc.getSuperclassName()); typeDecl.setSuperType(superType); ClassUnit superUnit = Project.getSingleton().getOrCreateClassUnit(superType.getClassName()); fileUnit.setSuperUnit(superUnit); String[] interfaceNames = jc.getInterfaceNames(); for (int i = 0; i < interfaceNames.length; i++) { ObjectType interfaceType = new ObjectType(interfaceNames[i]); ClassUnit interfaceUnit = Project.getSingleton().getOrCreateClassUnit(interfaceType.getClassName()); fileUnit.addInterface(interfaceUnit); } } Field[] fields = jc.getFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; VariableDeclaration variableDecl = new VariableDeclaration(VariableDeclaration.NON_LOCAL); variableDecl.setName(field.getName()); variableDecl.setModifiers(field.getModifiers()); variableDecl.setType(field.getType()); typeDecl.addField(variableDecl); } for (int i = 0; i < bcelMethods.length; i++) { Method method = bcelMethods[i]; Attribute[] attributes = method.getAttributes(); Map<String, String> methodAnnotationsValues = getAnnotationsValues(attributes); MethodBinding binding = MethodBinding.lookup(jc.getClassName(), method.getName(), method.getSignature()); String genericSignature = method.getGenericSignature(); if (genericSignature != null && !genericSignature.equals(method.getSignature())) { Signature signature = Project.getSingleton().getSignature(binding.toString()).relative(); String normalizedSignature = DragomeJavaScriptGenerator.normalizeExpression(signature); String normalizedClassname = DragomeJavaScriptGenerator.normalizeExpression(type.getClassName()); Project.getSingleton().addGenericSignature( normalizedClassname + "|" + normalizedSignature + "|" + genericSignature); // System.out.println(genericSignature); } if (DragomeJsCompiler.compiler.getSingleEntryPoint() != null) { Signature signature = Project.getSingleton().getSignature(binding.toString()); String singleSignature = DragomeJsCompiler.compiler.getSingleEntryPoint(); if (!signature.toString().equals(singleSignature)) continue; } MethodDeclaration methodDecl = new MethodDeclaration(binding, method.getAccessFlags(), method.getCode(), methodAnnotationsValues); typeDecl.addMethod(methodDecl); parseMethod(typeDecl, methodDecl, method); } return typeDecl; }
From source file:ca.uhn.fhir.rest.method.BaseResourceReturningMethodBinding.java
@SuppressWarnings("unchecked") public BaseResourceReturningMethodBinding(Class<?> theReturnResourceType, Method theMethod, FhirContext theContext, Object theProvider) { super(theMethod, theContext, theProvider); Class<?> methodReturnType = theMethod.getReturnType(); if (Collection.class.isAssignableFrom(methodReturnType)) { myMethodReturnType = MethodReturnTypeEnum.LIST_OF_RESOURCES; Class<?> collectionType = ReflectionUtil.getGenericCollectionTypeOfMethodReturnType(theMethod); if (collectionType != null) { if (!Object.class.equals(collectionType) && !IBaseResource.class.isAssignableFrom(collectionType)) { throw new ConfigurationException( "Method " + theMethod.getDeclaringClass().getSimpleName() + "#" + theMethod.getName() + " returns an invalid collection generic type: " + collectionType); }/*from www .j a v a 2 s .c o m*/ } myResourceListCollectionType = collectionType; } else if (IBaseResource.class.isAssignableFrom(methodReturnType)) { if (Modifier.isAbstract(methodReturnType.getModifiers()) == false && theContext .getResourceDefinition((Class<? extends IBaseResource>) methodReturnType).isBundle()) { myMethodReturnType = MethodReturnTypeEnum.BUNDLE_RESOURCE; } else { myMethodReturnType = MethodReturnTypeEnum.RESOURCE; } } else if (Bundle.class.isAssignableFrom(methodReturnType)) { myMethodReturnType = MethodReturnTypeEnum.BUNDLE; } else if (IBundleProvider.class.isAssignableFrom(methodReturnType)) { myMethodReturnType = MethodReturnTypeEnum.BUNDLE_PROVIDER; } else if (MethodOutcome.class.isAssignableFrom(methodReturnType)) { myMethodReturnType = MethodReturnTypeEnum.METHOD_OUTCOME; } else { throw new ConfigurationException("Invalid return type '" + methodReturnType.getCanonicalName() + "' on method '" + theMethod.getName() + "' on type: " + theMethod.getDeclaringClass().getCanonicalName()); } if (theReturnResourceType != null) { if (IBaseResource.class.isAssignableFrom(theReturnResourceType)) { if (Modifier.isAbstract(theReturnResourceType.getModifiers()) || Modifier.isInterface(theReturnResourceType.getModifiers())) { // If we're returning an abstract type, that's ok } else { myResourceType = (Class<? extends IResource>) theReturnResourceType; myResourceName = theContext.getResourceDefinition(myResourceType).getName(); } } } myPreferTypesList = createPreferTypesList(); }
From source file:com.feilong.core.lang.ClassUtil.java
/** * <code>ownerClass</code> ??. * //from www . j ava2 s . c o m * @param ownerClass * class * @return true<br> * <code>ownerClass</code> null,false * @see java.lang.Class#getModifiers() * @see java.lang.reflect.Modifier#isInterface(int) */ public static boolean isInterface(Class<?> ownerClass) { return null == ownerClass ? false : Modifier.isInterface(ownerClass.getModifiers());// ?? }