List of usage examples for java.lang.reflect Modifier PUBLIC
int PUBLIC
To view the source code for java.lang.reflect Modifier PUBLIC.
Click Source Link
From source file:com.tmall.wireless.tangram3.support.ExposureSupport.java
private void findExposureMethods(Method[] methods) { for (Method method : methods) { String methodName = method.getName(); if (isValidExposureMethodName(methodName)) { int modifiers = method.getModifiers(); if ((modifiers & Modifier.PUBLIC) != 0 && (modifiers & MODIFIERS_IGNORE) == 0) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length == 3) { Class<?> viewType = parameterTypes[0]; Class<?> cellType = parameterTypes[1]; Class<?> clickIntType = parameterTypes[2]; if (View.class.isAssignableFrom(viewType) && BaseCell.class.isAssignableFrom(cellType) && (clickIntType.equals(int.class) || clickIntType.equals(Integer.class))) { mOnExposureMethods.put(viewType, new OnTraceMethod(3, method)); }/* w w w .j av a2 s . c o m*/ } } } } }
From source file:com.alibaba.dubbo.demo.consumer.DemoAction.java
public DubboBenchmark.BenchmarkMessage prepareArgs() throws InvocationTargetException, IllegalAccessException { boolean b = true; int i = 100000; String s = "??"; DubboBenchmark.BenchmarkMessage.Builder builder = DubboBenchmark.BenchmarkMessage.newBuilder(); Method[] methods = builder.getClass().getDeclaredMethods(); for (Method m : methods) { if (m.getName().startsWith("setField") && ((m.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC)) { Parameter[] params = m.getParameters(); if (params.length == 1) { String n = params[0].getParameterizedType().getTypeName(); m.setAccessible(true);//from ww w. ja va 2 s . c o m if (n.endsWith("java.lang.String")) { m.invoke(builder, new Object[] { s }); } else if (n.endsWith("int")) { m.invoke(builder, new Object[] { i }); } else if (n.equals("boolean")) { m.invoke(builder, new Object[] { b }); } } } } return builder.build(); }
From source file:pl.burningice.plugins.image.ast.AbstractImageContainerTransformation.java
protected FieldNode getTransientsField(ClassNode node) { FieldNode transientFields = node.getDeclaredField("transients"); if (transientFields != null) { return transientFields; }//from w w w . ja v a2 s .c o m transientFields = new FieldNode("transients", Modifier.PRIVATE | Modifier.STATIC, new ClassNode(List.class), new ClassNode(node.getClass()), new ListExpression()); node.addField(transientFields); addGetter(transientFields, node, Modifier.PUBLIC | Modifier.STATIC); addSetter(transientFields, node, Modifier.PUBLIC | Modifier.STATIC); return transientFields; }
From source file:com.liuguangqiang.permissionhelper.PermissionHelper.java
/** * Invoke a method with annotation PermissionGranted. * * @param obj/*from w w w . j a va 2s .c o m*/ * @param permission */ private void invokeGrantedMethod(Object obj, String permission) { Class clazz = obj.getClass(); PermissionGranted permissionGranted; for (Method method : clazz.getMethods()) { if (method.isAnnotationPresent(PermissionGranted.class)) { permissionGranted = method.getAnnotation(PermissionGranted.class); if (permissionGranted.permission().equals(permission)) { if (method.getModifiers() != Modifier.PUBLIC) { throw new IllegalArgumentException( String.format("Annotation method %s must be public.", method)); } if (method.getParameterTypes().length > 0) { throw new RuntimeException(String.format("Cannot execute non-void method %s.", method)); } try { method.invoke(obj); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } } }
From source file:pl.burningice.plugins.image.ast.FileImageContainerTransformation.java
public FieldNode getTransientsField(ClassNode node) { FieldNode transientFields = node.getDeclaredField("transients"); if (transientFields != null) { return transientFields; }//from w w w .ja va 2s. c o m transientFields = new FieldNode("transients", Modifier.PRIVATE | Modifier.STATIC, new ClassNode(List.class), new ClassNode(node.getClass()), new ListExpression()); node.addField(transientFields); addGetter(transientFields, node, Modifier.PUBLIC | Modifier.STATIC); addSetter(transientFields, node, Modifier.PUBLIC | Modifier.STATIC); return transientFields; }
From source file:com.tmall.wireless.tangram.support.ExposureSupport.java
private void findExposureMethods(Method[] methods) { for (Method method : methods) { String methodName = method.getName(); if (!methodName.equals(ON_EXPOSURE_METHOD_NAME) && methodName.startsWith(ON_EXPOSURE_METHOD_NAME) || (methodName.startsWith(ON_EXPOSURE_METHOD_PREFIX) && methodName.endsWith(ON_EXPOSURE_METHOD_POSTFIX))) { int modifiers = method.getModifiers(); if ((modifiers & Modifier.PUBLIC) != 0 && (modifiers & MODIFIERS_IGNORE) == 0) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length == 3) { Class<?> viewType = parameterTypes[0]; Class<?> cellType = parameterTypes[1]; Class<?> clickIntType = parameterTypes[2]; if (View.class.isAssignableFrom(viewType) && BaseCell.class.isAssignableFrom(cellType) && (clickIntType.equals(int.class) || clickIntType.equals(Integer.class))) { mOnExposureMethods.put(viewType, new OnTraceMethod(3, method)); }/*from w w w .ja v a2s. c om*/ } } } } }
From source file:hu.bme.mit.sette.common.model.snippet.SnippetInputFactoryContainer.java
/** * Validates the class and its annotations. * * @param validator/*w w w . jav a2 s . c om*/ * a validator */ private void validateClass(final AbstractValidator<?> validator) { // check: "public final class", no superclass, interface, declared // class, exactly one constructor ClassValidator v = new ClassValidator(javaClass); v.type(ClassType.REGULAR_CLASS); v.withModifiers(Modifier.PUBLIC | Modifier.FINAL); v.withoutModifiers(Modifier.ABSTRACT); v.synthetic(false); v.superclass(Object.class).interfaceCount(0).memberClassCount(0); v.declaredConstructorCount(1); // check: no SETTE annotations if (!SetteAnnotationUtils.getSetteAnnotations(javaClass).isEmpty()) { v.addException("The class must not have any SETTE annotations"); } validator.addChildIfInvalid(v); }
From source file:org.ops4j.gaderian.strategy.TestStrategyFactory.java
public void testBuildImplementationClass() { ClassFactory factory = createMock(ClassFactory.class); ClassFab cf = createMock(ClassFab.class); MethodFab mf = createMock(MethodFab.class); ServiceImplementationFactoryParameters fp = createMock(ServiceImplementationFactoryParameters.class); expect(fp.getServiceInterface()).andReturn(ToStringStrategy.class); final StrategyParameter param = new StrategyParameter(); expect(fp.getFirstParameter()).andReturn(param); expect(factory.newClass("NewClass", Object.class)).andReturn(cf); cf.addInterface(ToStringStrategy.class); cf.addField("_registry", StrategyRegistry.class); Capture<Class[]> classCapture = new Capture<Class[]>(); cf.addConstructor(capture(classCapture), (Class[]) eq(null), eq("_registry = $1;")); expect(cf.addMethod(Modifier.PRIVATE, new MethodSignature(ToStringStrategy.class, "_getStrategy", new Class[] { Object.class }, null), "return (org.ops4j.gaderian.strategy.ToStringStrategy) _registry.getStrategy($1.getClass());")) .andReturn(mf);/*from www .j a va 2s .co m*/ expect(cf.addMethod(Modifier.PUBLIC, new MethodSignature(String.class, "toString", new Class[] { Object.class }, null), "return ($r) _getStrategy($1).toString($$);")).andReturn(mf); expect(fp.getServiceId()).andReturn("foo.Bar"); ClassFabUtils.addToStringMethod(cf, StrategyMessages.toString("foo.Bar", ToStringStrategy.class)); expectLastCall().andReturn(mf); expect(cf.createClass()).andReturn(String.class); replayAllRegisteredMocks(); StrategyFactory f = new StrategyFactory(); f.setClassFactory(factory); f.buildImplementationClass(fp, "NewClass"); verifyAllRegisteredMocks(); Class[] value = classCapture.getValue(); assertNotNull(value); assertEquals("unexpected constructor length", 1, value.length); }
From source file:org.gvnix.service.roo.addon.addon.JavaParserServiceImpl.java
/** * {@inheritDoc}//w ww . jav a 2 s . c om * <p> * Adds @org.springframework.stereotype.Service annotation to the class. * </p> */ public void createServiceClass(JavaType serviceClass) { // Service class String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(serviceClass, LogicalPath.getInstance(Path.SRC_MAIN_JAVA, "")); // Service annotations List<AnnotationMetadata> serviceAnnotations = new ArrayList<AnnotationMetadata>(); serviceAnnotations.add(new AnnotationMetadataBuilder(new JavaType("org.springframework.stereotype.Service"), new ArrayList<AnnotationAttributeValue<?>>()).build()); ClassOrInterfaceTypeDetailsBuilder serviceDetails = new ClassOrInterfaceTypeDetailsBuilder( declaredByMetadataId, Modifier.PUBLIC, serviceClass, PhysicalTypeCategory.CLASS); for (AnnotationMetadata annotationMetadata : serviceAnnotations) { serviceDetails.addAnnotation(annotationMetadata); } typeManagementService.createOrUpdateTypeOnDisk(serviceDetails.build()); }
From source file:io.stallion.reflection.PropertyUtils.java
/** * Build a map of direct javabeans properties of the target object. Only read/write properties (ie: those who have * both a getter and a setter) are returned. * @param target the target object from which to get properties names. * @return a Map of String with properties names as key and their values * @throws PropertyException if an error happened while trying to get a property. *//*ww w .j a v a 2 s . c om*/ public static Map<String, Object> getProperties(Object target, Class<? extends Annotation>... excludeAnnotations) throws PropertyException { Map<String, Object> properties = new HashMap<String, Object>(); Class clazz = target.getClass(); Method[] methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; String name = method.getName(); Boolean hasExcludeAnno = false; if (excludeAnnotations.length > 0) { for (Class<? extends Annotation> anno : excludeAnnotations) { if (method.isAnnotationPresent(anno)) { hasExcludeAnno = true; } } } if (hasExcludeAnno) { continue; } if (method.getModifiers() == Modifier.PUBLIC && method.getParameterTypes().length == 0 && (name.startsWith("get") || name.startsWith("is")) && containsSetterForGetter(clazz, method)) { String propertyName; if (name.startsWith("get")) propertyName = Character.toLowerCase(name.charAt(3)) + name.substring(4); else if (name.startsWith("is")) propertyName = Character.toLowerCase(name.charAt(2)) + name.substring(3); else throw new PropertyException( "method '" + name + "' is not a getter, thereof no setter can be found"); try { Object propertyValue = method.invoke(target, (Object[]) null); // casting to (Object[]) b/c of javac 1.5 warning if (propertyValue != null && propertyValue instanceof Properties) { Map propertiesContent = getNestedProperties(propertyName, (Properties) propertyValue); properties.putAll(propertiesContent); } else { properties.put(propertyName, propertyValue); } } catch (IllegalAccessException ex) { throw new PropertyException("cannot set property '" + propertyName + "' - '" + name + "' is null and cannot be auto-filled", ex); } catch (InvocationTargetException ex) { throw new PropertyException("cannot set property '" + propertyName + "' - '" + name + "' is null and cannot be auto-filled", ex); } } // if } // for return properties; }