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.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test(expected = IllegalArgumentException.class) public void illegalModifierPublic() { memberCriteria.withModifiers(Modifier.PUBLIC); }
From source file:org.gvnix.addon.gva.security.providers.safe.SafeSecurityProviderAuthenticationFilterMetadata.java
/** * Gets <code>getAttemptAuthentication</code> method. <br> * //from w w w .j a v a 2s . com * @return */ private MethodMetadata getAttemptAuthentication() { // Define method parameter types List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(); parameterTypes .add(AnnotatedJavaType.convertFromJavaType(new JavaType("javax.servlet.http.HttpServletRequest"))); parameterTypes .add(AnnotatedJavaType.convertFromJavaType(new JavaType("javax.servlet.http.HttpServletResponse"))); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(ATTEMPT_AUTHENTICATION_METHOD, parameterTypes); if (method != null) { // If it already exists, just return the method and omit its // generation via the ITD return method; } // Define method annotations List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); AnnotationMetadataBuilder overrideAnnotation = new AnnotationMetadataBuilder(); overrideAnnotation.setAnnotationType(new JavaType("java.lang.Override")); annotations.add(overrideAnnotation); // Define method throws types List<JavaType> throwsTypes = new ArrayList<JavaType>(); throwsTypes.add(new JavaType("org.springframework.security.core.AuthenticationException")); // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); parameterNames.add(new JavaSymbolName("request")); parameterNames.add(new JavaSymbolName("response")); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildAttemptAuthenticationMethodBody(bodyBuilder); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, ATTEMPT_AUTHENTICATION_METHOD, new JavaType("org.springframework.security.core.Authentication"), parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:org.gvnix.addon.geo.addon.GvNIXGeoConversionServiceMetadata.java
/** * Gets <code>getStringToPointConverter</code> method. <br> * /*from ww w. j a v a 2 s. c o m*/ * @return */ private MethodMetadata getStringToPointConverterMethod() { // Define method parameter types List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(STRING_TO_POINT_METHOD, parameterTypes); if (method != null) { // If it already exists, just return the method and omit its // generation via the ITD return method; } // Define method annotations List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildGetStringToPointConverterMethodBody(bodyBuilder); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, STRING_TO_POINT_METHOD, CONVERTER_STRING_POINT, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:org.gvnix.addon.jpa.addon.audit.providers.envers.EnversRevisionLogEntityMetadataBuilder.java
private MethodMetadata getNewRevisionMethod() { // Define method parameter types List<AnnotatedJavaType> parameterTypes = helper.toAnnotedJavaType(JavaType.OBJECT); // Check if a method exist in type final MethodMetadata method = helper.methodExists(TO_STRING_METHOD, parameterTypes); if (method != null) { // If it already exists, just return the method return method; }// w w w . j a va2 s .c o m // Define method annotations (none in this case) List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(0); // Define method throws types (none in this case) List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names (none in this case) List<JavaSymbolName> parameterNames = helper.toSymbolName("revisionEntity"); // Create the method body InvocableMemberBodyBuilder body = new InvocableMemberBodyBuilder(); buildNewRevisionMethodBody(body); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(context.getMetadataId(), Modifier.PUBLIC, NEW_REVISION_METHOD, JavaType.VOID_PRIMITIVE, parameterTypes, parameterNames, body); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata }
From source file:org.gvnix.addon.gva.security.providers.safe.SafeSecurityProviderMetadata.java
/** * Gets <code>retrieveUser</code> method. <br> * /*from w w w . ja v a 2 s. c om*/ * @return */ private MethodMetadata getRetrieveUserMethod() { // Define method parameter types List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType.convertFromJavaTypes(JavaType.STRING, new JavaType("org.springframework.security.authentication.UsernamePasswordAuthenticationToken")); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(RETRIEVE_USER_METHOD, parameterTypes); if (method != null) { // If it already exists, just return the method and omit its // generation via the ITD return method; } // Define method annotations List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); parameterNames.add(new JavaSymbolName("userTokenized")); parameterNames.add(new JavaSymbolName("authentication")); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildRetrieveUserMethodBody(bodyBuilder); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, RETRIEVE_USER_METHOD, new JavaType("org.springframework.security.core.userdetails.UserDetails"), parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:ch.algotrader.esper.aggregation.GenericTALibFunctionFactory.java
private Class<?> getReturnClass(String className, Map<String, Class<?>> fields) throws CannotCompileException, NotFoundException { String fqClassName = this.getClass().getPackage().getName() + ".talib." + className; try {/* www . j a v a2s. com*/ // see if the class already exists return Class.forName(fqClassName); } catch (ClassNotFoundException e) { // otherwise create the class ClassPool pool = ClassPool.getDefault(); CtClass ctClass = pool.makeClass(fqClassName); for (Map.Entry<String, Class<?>> entry : fields.entrySet()) { // generate a public field (we don't need a setter) String fieldName = entry.getKey(); CtClass valueClass = pool.get(entry.getValue().getName()); CtField ctField = new CtField(valueClass, fieldName, ctClass); ctField.setModifiers(Modifier.PUBLIC); ctClass.addField(ctField); // generate the getter method String methodName = "get" + StringUtils.capitalize(fieldName); CtMethod ctMethod = CtNewMethod.make(valueClass, methodName, new CtClass[] {}, new CtClass[] {}, "{ return this." + fieldName + ";}", ctClass); ctClass.addMethod(ctMethod); } return ctClass.toClass(); } }
From source file:com.all.app.BeanStatisticsWriter.java
private List<CSVColumn> auto(Object object) { List<CSVColumn> columns = new ArrayList<CSVColumn>(); Method[] declaredMethods = object.getClass().getDeclaredMethods(); for (Method method : declaredMethods) { boolean noArguments = method.getParameterTypes().length == 0; boolean isVoid = method.getReturnType().equals(void.class); boolean isPublic = (method.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC; boolean isNotStatic = (method.getModifiers() & Modifier.STATIC) != Modifier.STATIC; boolean isGetter = method.getName().startsWith("get"); if (isGetter && noArguments && isPublic && isNotStatic && !isVoid) { columns.add(new CSVColumnMethodReflected(method.getName(), method.getName())); }//from w w w .j a v a2s. co m } return columns; }
From source file:org.gvnix.addon.geo.addon.GvNIXGeoConversionServiceMetadata.java
/** * Gets <code>writeWkt</code> method. <br> * /*from w ww. j a v a 2 s .co m*/ * @return */ private MethodMetadata getWriteWktMethod() { // Define method parameter types List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(); parameterTypes.add(new AnnotatedJavaType(GEOMETRY_TYPE)); // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(WRITE_WKT_METHOD, parameterTypes); if (method != null) { // If it already exists, just return the method and omit its // generation via the ITD return method; } // Define method annotations List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter names List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); parameterNames.add(new JavaSymbolName("geometry")); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildWriteWktMethodBody(bodyBuilder); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, WRITE_WKT_METHOD, JavaType.STRING, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:org.gvnix.flex.FlexScaffoldMetadata.java
private MethodMetadata getUpdateMethod() { JavaSymbolName methodName = new JavaSymbolName("update"); MethodMetadata method = methodExists(methodName); if (method != null) { return method; }/*w ww .j a v a2s .c o m*/ List<AnnotatedJavaType> paramTypes = new ArrayList<AnnotatedJavaType>(); paramTypes.add(new AnnotatedJavaType(this.entity, new ArrayList<AnnotationMetadata>())); List<JavaSymbolName> paramNames = new ArrayList<JavaSymbolName>(); paramNames.add(new JavaSymbolName(this.entityReference)); InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine("if (" + this.entityReference + " == null) throw new IllegalArgumentException(\"A " + this.entityReference + " is required\");"); // fix for https://jira.springsource.org/browse/ROOFLEX-16 bodyBuilder.appendFormalLine(this.entityReference + "=" + this.entityReference + "." + new JpaCrudAnnotationValues(this.entityMetadata).getMergeMethod() + "();"); bodyBuilder.appendFormalLine("return " + this.entityReference + ";"); return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, this.entity, paramTypes, paramNames, bodyBuilder).build(); }
From source file:org.codehaus.groovy.grails.compiler.injection.GrailsASTUtils.java
/** * Adds a delegate method to the target class node where the first argument * is to the delegate method is 'this'. In other words a method such as * foo(Object instance, String bar) would be added with a signature of foo(String) * and 'this' is passed to the delegate instance * * @param classNode The class node//from ww w .ja v a 2 s . c o m * @param delegate The expression that looks up the delegate * @param declaredMethod The declared method * @param thisAsFirstArgument Whether 'this' should be passed as the first argument to the method * @return The added method node or null if it couldn't be added */ public static MethodNode addDelegateInstanceMethod(ClassNode classNode, Expression delegate, MethodNode declaredMethod, AnnotationNode markerAnnotation, boolean thisAsFirstArgument, Map<String, ClassNode> genericsPlaceholders) { Parameter[] parameterTypes = thisAsFirstArgument ? getRemainingParameterTypes(declaredMethod.getParameters()) : declaredMethod.getParameters(); String methodName = declaredMethod.getName(); if (classNode.hasDeclaredMethod(methodName, copyParameters(parameterTypes, genericsPlaceholders))) { return null; } String propertyName = GrailsClassUtils.getPropertyForGetter(methodName); if (propertyName != null && parameterTypes.length == 0 && classNode.hasProperty(propertyName)) { return null; } propertyName = GrailsClassUtils.getPropertyForSetter(methodName); if (propertyName != null && parameterTypes.length == 1 && classNode.hasProperty(propertyName)) { return null; } BlockStatement methodBody = new BlockStatement(); ArgumentListExpression arguments = createArgumentListFromParameters(parameterTypes, thisAsFirstArgument, genericsPlaceholders); ClassNode returnType = replaceGenericsPlaceholders(declaredMethod.getReturnType(), genericsPlaceholders); MethodCallExpression methodCallExpression = new MethodCallExpression(delegate, methodName, arguments); methodCallExpression.setMethodTarget(declaredMethod); ThrowStatement missingMethodException = createMissingMethodThrowable(classNode, declaredMethod); VariableExpression apiVar = addApiVariableDeclaration(delegate, declaredMethod, methodBody); IfStatement ifStatement = createIfElseStatementForApiMethodCall(methodCallExpression, apiVar, missingMethodException); methodBody.addStatement(ifStatement); MethodNode methodNode = new MethodNode(methodName, Modifier.PUBLIC, returnType, copyParameters(parameterTypes, genericsPlaceholders), GrailsArtefactClassInjector.EMPTY_CLASS_ARRAY, methodBody); methodNode.addAnnotations(declaredMethod.getAnnotations()); if (shouldAddMarkerAnnotation(markerAnnotation, methodNode)) { methodNode.addAnnotation(markerAnnotation); } classNode.addMethod(methodNode); return methodNode; }