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:org.ops4j.gaderian.service.impl.LoggingInterceptorFactory.java
/** * Creates a method that delegates to the _delegate object; this is used for * methods that are not logged.//w ww . ja v a2 s. c o m */ private void addPassThruMethodImplementation(ClassFab classFab, MethodSignature sig) { BodyBuilder builder = new BodyBuilder(); builder.begin(); builder.add("return ($r) _delegate."); builder.add(sig.getName()); builder.addln("($$);"); builder.end(); classFab.addMethod(Modifier.PUBLIC, sig, builder.toString()); }
From source file:org.jsonschema2pojo.integration.config.IncludeAccessorsIT.java
@Test public void beansOmitGettersAndSettersWhenAccessorsAreDisabled() throws ClassNotFoundException, SecurityException, NoSuchMethodException, NoSuchFieldException { ClassLoader resultsClassLoader = schemaRule.generateAndCompile( "/schema/properties/primitiveProperties.json", "com.example", config("includeAccessors", false)); Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties"); try {/* w w w . ja v a2s .c o m*/ generatedType.getDeclaredMethod("getA"); fail("Disabled accessors but getter was generated"); } catch (NoSuchMethodException e) { } try { generatedType.getDeclaredMethod("setA", Integer.class); fail("Disabled accessors but getter was generated"); } catch (NoSuchMethodException e) { } assertThat(generatedType.getDeclaredField("a").getModifiers(), is(Modifier.PUBLIC)); }
From source file:de.micromata.genome.tpsb.GroovyExceptionInterceptor.java
protected static void collectMethods(Class<?> cls, Map<String, Method> collected) { for (Method m : cls.getDeclaredMethods()) { if ((m.getModifiers() & Modifier.PUBLIC) != Modifier.PUBLIC) { continue; }//from ww w . j a v a 2 s .co m if ((m.getModifiers() & Modifier.STATIC) == Modifier.STATIC) { continue; } if (m.getAnnotation(TpsbIgnore.class) != null) { continue; } if (ignoreMethods.contains(m.getName()) == true) { continue; } if (m.getReturnType().isPrimitive() == true) { continue; } String sm = methodToString(m); if (collected.containsKey(sm) == true) { continue; } collected.put(sm, m); } Class<?> scls = cls.getSuperclass(); if (scls == Object.class) { return; } collectMethods(scls, collected); }
From source file:org.modeshape.rhq.util.I18n.java
/** * Should be called in a <code>static</code> block to load the properties file and assign values to the class string fields. * /*from w w w . j a v a2s . co m*/ * @throws IllegalStateException if there is a problem reading the I8n class file or properties file */ protected void initialize() { final Map<String, Field> fields = new HashMap<String, Field>(); // collect all public, static, non-final, string fields try { for (final Field field : getClass().getDeclaredFields()) { final int modifiers = field.getModifiers(); if ((field.getType() == String.class) && ((modifiers & Modifier.PUBLIC) == Modifier.PUBLIC) && ((modifiers & Modifier.STATIC) == Modifier.STATIC) && ((modifiers & Modifier.FINAL) != Modifier.FINAL)) { fields.put(field.getName(), field); } } } catch (final Exception e) { throw new IllegalStateException(I18n.bind(UtilI18n.problemLoadingI18nClass, getClass().getName()), e); } // return if nothing to do if (ToolBox.isEmpty(fields)) { return; } // load properties file InputStream stream = null; IllegalStateException problem = null; try { final Class<? extends I18n> thisClass = getClass(); final String bundleName = thisClass.getName().replaceAll("\\.", "/").concat(".properties"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ final URL url = thisClass.getClassLoader().getResource(bundleName); stream = url.openStream(); final Collection<String> errors = new ArrayList<String>(); final Properties props = new I18nProperties(fields, thisClass, errors); props.load(stream); // log errors for any properties keys that don't have fields for (final String error : errors) { if (problem == null) { problem = new IllegalStateException(error); } this.logger.error(error); } // log errors for any fields that don't have properties for (final String fieldName : fields.keySet()) { final String error = I18n.bind(UtilI18n.missingPropertiesKey, fieldName, getClass().getName()); if (problem == null) { problem = new IllegalStateException(error); } this.logger.error(error); } } catch (final Exception e) { throw new IllegalStateException(I18n.bind(UtilI18n.problemLoadingI18nProperties, getClass().getName()), e); } finally { if (stream != null) { try { stream.close(); } catch (final Exception e) { } finally { stream = null; } } if (problem != null) { throw problem; } } }
From source file:com.khs.sherpa.endpoint.SherpaEndpoint.java
@SuppressWarnings("unchecked") // @RolesAllowed("SHERPA_ADMIN") @Action(mapping = "/sherpa/admin/describe/{value}") public Object describe(@Param("value") String value) { List<Map<String, Object>> actions = new ArrayList<Map<String, Object>>(); Set<Method> methods = null; try {//from w w w. ja v a 2s . c om methods = Reflections.getAllMethods(applicationContext.getType(value), Predicates.and(Predicates.not(SherpaPredicates.withAssignableFrom(Object.class)), ReflectionUtils.withModifier(Modifier.PUBLIC), Predicates.not(ReflectionUtils.withModifier(Modifier.ABSTRACT)), Predicates.not(SherpaPredicates.withGeneric()))); } catch (NoSuchManagedBeanExcpetion e) { throw new SherpaRuntimeException(e); } for (Method method : methods) { Map<String, Object> action = new HashMap<String, Object>(); actions.add(action); action.put("name", MethodUtil.getMethodName(method)); if (method.isAnnotationPresent(DenyAll.class)) { action.put("permission", "DenyAll"); } else if (method.isAnnotationPresent(RolesAllowed.class)) { action.put("permission", "RolesAllowed"); action.put("roles", method.getAnnotation(RolesAllowed.class).value()); } else { action.put("permission", "PermitAll"); } Map<String, String> params = new HashMap<String, String>(); Class<?>[] types = method.getParameterTypes(); Annotation[][] parameters = method.getParameterAnnotations(); for (int i = 0; i < parameters.length; i++) { Class<?> type = types[i]; Param annotation = null; if (parameters[i].length > 0) { for (Annotation an : parameters[i]) { if (an.annotationType().isAssignableFrom(Param.class)) { annotation = (Param) an; break; } } } if (annotation != null) { params.put(annotation.value(), type.getName()); } } if (params.size() > 0) { action.put("params", params); } else { action.put("params", null); } } return actions; }
From source file:de.micromata.genome.util.matcher.cls.ContainsMethod.java
/** * Match this class.//from ww w . j a v a2 s. co m * * @param cls the cls * @return true, if successful */ public boolean matchThisClass(Class<?> cls) { for (Method m : cls.getMethods()) { int mods = m.getModifiers(); if (staticMethod == true && (mods & Modifier.STATIC) != Modifier.STATIC) { continue; } if (staticMethod == false && (mods & Modifier.STATIC) == Modifier.STATIC) { continue; } if (publicMethod == true && (mods & Modifier.PUBLIC) != Modifier.PUBLIC) { continue; } if (name != null) { if (StringUtils.equals(m.getName(), name) == false) { continue; } } if (returnType != null) { if (m.getReturnType() != returnType) { continue; } } if (params != null) { Class<?>[] pt = m.getParameterTypes(); if (pt.length != params.length) { continue; } for (int i = 0; i < pt.length; ++i) { if (pt[i] != params[i]) { continue; } } } return true; } return false; }
From source file:org.eclipse.skalli.testutil.PropertyTestUtil.java
public static final void checkPropertyDefinitions(Class<?> classToCheck, Map<Class<?>, String[]> requiredProperties, Map<String, Object> values) throws IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchFieldException, InstantiationException, InvocationTargetException { Class<?> clazz = classToCheck; while (clazz != null) { // assert that the model class under test has a suitable constructor (either // a default constructor if requiredProperties is empty, or a constructor with the // correct number and type of parameters), and can be instantiated Object instance = assertExistsConstructor(clazz, requiredProperties, values); for (Field field : clazz.getDeclaredFields()) { if (hasAnnotation(field, PropertyName.class)) { // assert that the field is public static final Assert.assertTrue(clazz.getName() + ": constant " + field.getName() + " is not declared STATIC", (field.getModifiers() & Modifier.STATIC) == Modifier.STATIC); //$NON-NLS-1$ Assert.assertTrue(clazz.getName() + ": constant " + field.getName() + " is not declared PUBLIC", (field.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC); //$NON-NLS-1$ Assert.assertTrue(clazz.getName() + ": constant " + field.getName() + " is not declared FINAL", (field.getModifiers() & Modifier.FINAL) == Modifier.FINAL); //$NON-NLS-1$ // assert that the constant if of type String and has a value assigned. Object object = field.get(null); Assert.assertNotNull(clazz.getName() + ": constant " + field.getName() + " is NULL", object); //$NON-NLS-1$ Assert.assertTrue(clazz.getName() + ": constants " + field.getName() + " is not of type STRING", object instanceof String); //$NON-NLS-1$ // assert that there is a private non-static field with a name matching the // value of the constant unless the property is marked as derived String fieldName = (String) object; if (!hasAnnotation(field, Derived.class)) { Assert.assertTrue(clazz.getName() + ": must have a private field named " + fieldName, hasPrivateField(clazz, fieldName)); }//from w w w. j a v a 2 s . com // assert that the values argument contains a test value for this field Assert.assertTrue(clazz.getName() + ": no test value for field " + fieldName, values.containsKey(fieldName)); Methods methods = new Methods(); // assert that the class has a getter for this property methods.getMethod = assertExistsGetMethod(clazz, fieldName); // assert that the class has a setter for this property if it is an optional property; // required properties must be set in the constructor; // skip properties that are annotated as @Derived if (isOptionalProperty(clazz, fieldName, requiredProperties) && !hasAnnotation(field, Derived.class)) { Class<?> returnType = methods.getMethod.getReturnType(); if (!Collection.class.isAssignableFrom(returnType)) { methods.setMethod = assertExistsSetMethod(clazz, fieldName, returnType); } else { Class<?> entryType = ((Collection<?>) values.get(fieldName)).iterator().next() .getClass(); methods.addMethod = assertExistsCollectionMethod(clazz, fieldName, entryType, "add"); methods.removeMethod = assertExistsCollectionMethod(clazz, fieldName, entryType, "remove"); methods.hasMethod = assertExistsCollectionMethod(clazz, fieldName, entryType, "has"); } // call the setter/adder and getter methods with the given test value if (instance != null) { assertChangeReadCycle(clazz, fieldName, methods, instance, values.get(fieldName)); } } else { if (instance != null) { assertReadCycle(clazz, methods, instance, values.get(fieldName)); } } } } // check the properties of the parent class (EntityBase!) clazz = clazz.getSuperclass(); } }
From source file:com.tmall.wireless.tangram3.support.SimpleClickSupport.java
private void findClickMethods(Method[] methods) { for (Method method : methods) { String methodName = method.getName(); if (isValidMethodName(methodName)) { int modifiers = method.getModifiers(); if ((modifiers & Modifier.PUBLIC) != 0 && (modifiers & MODIFIERS_IGNORE) == 0) { Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length == 3 || parameterTypes.length == 4) { 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))) { if (parameterTypes.length == 4) { Class<?> clickParamsType = parameterTypes[3]; if (Map.class.isAssignableFrom(clickParamsType)) { mOnClickMethods.put(viewType, new OnClickMethod(4, method)); }//from ww w . java 2 s . co m } else { mOnClickMethods.put(viewType, new OnClickMethod(3, method)); } } } } } } }
From source file:org.eclipse.wb.android.internal.model.util.AndroidListenerProperties.java
/** * @return the {@link List} of events which are supported by given widget. *///from ww w . j a v a 2 s . c o m private static List<ListenerInfo> getWidgetEvents(XmlObjectInfo widget) { Class<?> componentClass = widget.getDescription().getComponentClass(); List<ListenerInfo> events = m_widgetEvents.get(componentClass); if (events == null) { GenericTypeResolver typeResolver = new GenericTypeResolver(null); events = Lists.newArrayList(); m_widgetEvents.put(componentClass, events); { // events in Android has 'OnXXXListener' inner class as listener interface with // appropriate 'setOnXXXListener' method in main class Pattern pattern = Pattern.compile("On.*Listener"); Class<?>[] classes = componentClass.getClasses(); if (!ArrayUtils.isEmpty(classes)) { for (Class<?> innerClass : classes) { String shortClassName = CodeUtils.getShortClass(innerClass.getName()); Matcher matcher = pattern.matcher(shortClassName); if (matcher.matches()) { // additionally check for method, it should be public (RefUtils returns with any visibility) Method method = ReflectionUtils.getMethod(componentClass, "set" + shortClassName, innerClass); if (method != null && (method.getModifiers() & Modifier.PUBLIC) != 0) { ListenerInfo listener = new ListenerInfo(method, componentClass, typeResolver); events.add(listener); } } } } } // sort Collections.sort(events, new Comparator<ListenerInfo>() { public int compare(ListenerInfo o1, ListenerInfo o2) { return o1.getSimpleName().compareTo(o2.getSimpleName()); } }); } return events; }
From source file:com.weibo.motan.demo.client.DemoRpcClient.java
public static 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 w ww.j ava2s . c om*/ 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(); }