Example usage for java.lang.reflect Modifier PUBLIC

List of usage examples for java.lang.reflect Modifier PUBLIC

Introduction

In this page you can find the example usage for java.lang.reflect Modifier PUBLIC.

Prototype

int PUBLIC

To view the source code for java.lang.reflect Modifier PUBLIC.

Click Source Link

Document

The int value representing the public modifier.

Usage

From source file:org.gvnix.addon.geo.addon.GvNIXGeoConversionServiceMetadata.java

/**
 * Gets <code>installGeoLabelsConverter</code> method. <br>
 * /*from w w w.ja  va 2  s .c  om*/
 * @return
 */
private MethodMetadata getInstallGeoLabelsConverterMethod() {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    parameterTypes.add(new AnnotatedJavaType(new JavaType("org.springframework.format.FormatterRegistry")));

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(INSTALL_GEO_LABLES_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("registry"));

    // Create the method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    buildInstallGeoLabelsConvertersMethodBody(bodyBuilder);

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC,
            INSTALL_GEO_LABLES_METHOD, JavaType.VOID_PRIMITIVE, parameterTypes, parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    methodBuilder.setThrowsTypes(throwsTypes);

    return methodBuilder.build(); // Build and return a MethodMetadata
    // instance
}

From source file:com.ms.commons.test.tool.GenerateTestCase.java

private static CompilationUnit makeCompilationUnit(String packageName, String testcaseName, String comment) {
    CompilationUnit unit = new CompilationUnit();
    unit.setPackage(new PackageDeclaration(makeNameExpr(packageName)));

    JavadocComment javadocComment = new JavadocComment("\r\n * " + comment + "\r\n ");
    List<ClassOrInterfaceType> testCaseExtends = new ArrayList<ClassOrInterfaceType>();
    testCaseExtends.add(new ClassOrInterfaceType("BaseTestCase"));
    List<BodyDeclaration> members = new ArrayList<BodyDeclaration>();
    ClassOrInterfaceDeclaration clazz = new ClassOrInterfaceDeclaration(javadocComment, Modifier.PUBLIC, null,
            false, testcaseName, null, testCaseExtends, null, members);
    MemberValuePair mvp = new MemberValuePair("contextKey",
            new StringLiteralExpr("Your context key or set 'useDataSourceContextKey = true'"));
    clazz.setAnnotations(Arrays.asList(
            (AnnotationExpr) new NormalAnnotationExpr(makeNameExpr("TestCaseInfo"), Arrays.asList(mvp))));
    unit.setTypes(Arrays.asList((TypeDeclaration) clazz));
    return unit;// ww  w .jav  a 2 s .  co m
}

From source file:org.gvnix.addon.jpa.addon.audit.providers.envers.EnversRevisionLogEntityMetadataBuilder.java

private MethodMetadata getHashCodeMethod() {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(0);

    // 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;
    }/*from  w ww . j ava 2s  .  c om*/

    // Define method annotations (none in this case)
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();

    // 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 = new ArrayList<JavaSymbolName>(0);

    // Create the method body
    InvocableMemberBodyBuilder body = new InvocableMemberBodyBuilder();
    body.appendFormalLine(String.format("return new %s(17, 31).append(%s).append(%s).toHashCode();",
            helper.getFinalTypeName(HASH_CODE_BUILDER), ID_FIELD, TIMESTAMP_FIELD));

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(context.getMetadataId(), Modifier.PUBLIC,
            HASH_CODE_METHOD, JavaType.INT_PRIMITIVE, parameterTypes, parameterNames, body);
    methodBuilder.setAnnotations(annotations);
    methodBuilder.setThrowsTypes(throwsTypes);

    return methodBuilder.build(); // Build and return a MethodMetadata
}

From source file:com.github.geequery.codegen.ast.JavaUnit.java

public void addSetter(String fieldName) {
    JavaField field = this.getFieldAsJavaField(fieldName);
    if (field == null)
        throw new IllegalArgumentException("field not exit while generate getter:" + fieldName);
    String methodName = "set" + StringUtils.capitalize(fieldName);
    JavaMethod method = new JavaMethod(methodName);
    method.setModifier(Modifier.PUBLIC);
    method.addparam(field.getType().getSimpleName(), "arg");
    method.addContent("this." + field.getName() + "=arg;");
    this.addMethod(method);
}

From source file:org.codehaus.groovy.grails.compiler.web.ControllerActionTransformer.java

/**
 * Converts a method into a controller action.  If the method accepts parameters,
 * a no-arg counterpart is created which delegates to the original.
 *
 * @param classNode The controller class
 * @param methodNode   The method to be converted
 * @return The no-arg wrapper method, or null if none was created.
 *//* ww  w. j av a 2s.com*/
private MethodNode convertToMethodAction(ClassNode classNode, MethodNode methodNode, SourceUnit source,
        GeneratorContext context) {

    final ClassNode returnType = methodNode.getReturnType();
    Parameter[] parameters = methodNode.getParameters();

    for (Parameter param : parameters) {
        if (param.hasInitialExpression()) {
            String paramName = param.getName();
            String methodName = methodNode.getName();
            String initialValue = param.getInitialExpression().getText();
            String methodDeclaration = methodNode.getText();
            String message = "Parameter [%s] to method [%s] has default value [%s].  "
                    + "Default parameter values are not allowed in controller action methods. ([%s])";
            String formattedMessage = String.format(message, paramName, methodName, initialValue,
                    methodDeclaration);
            GrailsASTUtils.error(source, methodNode, formattedMessage);
        }
    }

    MethodNode method = null;
    if (methodNode.getParameters().length > 0) {
        method = new MethodNode(methodNode.getName(), Modifier.PUBLIC, returnType, ZERO_PARAMETERS,
                EMPTY_CLASS_ARRAY, addOriginalMethodCall(methodNode, initializeActionParameters(classNode,
                        methodNode, methodNode.getName(), parameters, source, context)));
        copyAnnotations(methodNode, method);
        annotateActionMethod(parameters, method);
    } else {
        annotateActionMethod(parameters, methodNode);
    }

    return method;
}

From source file:org.codehaus.groovy.grails.compiler.injection.test.TestMixinTransformation.java

static protected BlockStatement getOrCreateMethodBody(ClassNode classNode, MethodNode setupMethod,
        String name) {//from ww w  .j a  va2s  .co  m
    BlockStatement methodBody;
    if (setupMethod.getDeclaringClass().getName().equals(TestCase.class.getName())) {
        methodBody = new BlockStatement();
        setupMethod = new MethodNode(name, Modifier.PUBLIC, setupMethod.getReturnType(),
                GrailsArtefactClassInjector.ZERO_PARAMETERS, null, methodBody);
        classNode.addMethod(setupMethod);
    } else {
        final Statement setupMethodBody = setupMethod.getCode();
        if (!(setupMethodBody instanceof BlockStatement)) {
            methodBody = new BlockStatement();
            if (setupMethodBody != null) {
                if (!(setupMethodBody instanceof ReturnStatement)) {
                    methodBody.addStatement(setupMethodBody);
                }
            }
            setupMethod.setCode(methodBody);
        } else {
            methodBody = (BlockStatement) setupMethodBody;
        }
    }
    return methodBody;
}

From source file:org.gvnix.addon.jpa.addon.audit.JpaAuditMetadata.java

/**
 * @return revision item class definition
 *//*  w  ww.  j a v  a2  s  .c  o  m*/
private ClassOrInterfaceTypeDetails getRevisionClass() {

    // Check class exists
    ClassOrInterfaceTypeDetails innerClass = governorTypeDetails.getDeclaredInnerType(revisonItemType);

    if (innerClass != null) {
        // If class exists (already pushed-in) we can do nothing
        return innerClass;
    }

    // Create class builder for inner class
    ClassOrInterfaceTypeDetailsBuilder classBuilder = new ClassOrInterfaceTypeDetailsBuilder(getId(),
            Modifier.PUBLIC + Modifier.STATIC, revisonItemType, PhysicalTypeCategory.CLASS);

    // Add revisionLog-provider required artifacts
    revisionLogBuilder.addCustomArtifactToRevisionItem(classBuilder);

    // Add Revision item common methods
    classBuilder.addMethod(createRevisionItemGetItemMethod());
    classBuilder.addMethod(createRevisionItemGetRevisionNumberMethod());
    classBuilder.addMethod(createRevisionItemGetRevisionUserMethod());
    classBuilder.addMethod(createRevisionItemGetRevisionDateMethod());
    classBuilder.addMethod(createRevisionItemIsCreateMethod());
    classBuilder.addMethod(createRevisionItemIsUpdateMethod());
    classBuilder.addMethod(createRevisionItemIsDeleteMethod());
    classBuilder.addMethod(createRevisionItemGetTypeMethod());

    // Build class definition from builder
    return classBuilder.build();
}

From source file:com.github.geequery.codegen.ast.JavaUnit.java

public void addGetter(String fieldName) {
    JavaField field = this.getFieldAsJavaField(fieldName);
    if (field == null)
        throw new IllegalArgumentException("field not exit while generate getter:" + fieldName);
    String methodName = "get" + StringUtils.capitalize(fieldName);

    JavaMethod method = new JavaMethod(methodName);
    method.setModifier(Modifier.PUBLIC);
    method.setReturnType(field.getType());
    method.addContent("return this." + fieldName + ";");
    this.addMethod(method);
}

From source file:org.gvnix.addon.jpa.addon.audit.providers.envers.EnversRevisionLogMetadataBuilder.java

/**
 * @return creates getAuditReader() method
 *//*from  ww w .  j av  a 2  s  .co m*/
private MethodMetadata getAuditReaderStaticMethod() {
    return commonGetAuditReaderStaticMethod(context, AUDIT_READER_STATIC_METHOD,
            Modifier.PUBLIC + Modifier.STATIC, "return %s.get(entityManager());", null);
}

From source file:eu.annocultor.tools.GeneratorOfXmlSchemaForConvertersDoclet.java

static void printConstructorDoc(ConstructorDoc constr, PrintWriter out) throws Exception {
    if (constr.modifierSpecifier() == Modifier.PUBLIC) {
        String affix = constr.annotations()[0].elementValues()[1].value().toString();
        affix = StringUtils.stripEnd(StringUtils.stripStart(affix, "\""), "\"");
        out.println("  <h2 id=\"Constructor " + constr.name() + "-" + affix + "\">Constructor <code>" + affix
                + "</code></h2>");
        out.println();//from  ww w.j a  v a 2  s. com
        out.println(" <p>" + constr.commentText() + "</p>");
        out.println();
        out.println(" <p>Sample use:</p>");
        out.println("<div class=\"source\"><pre>");

        out.println(StringEscapeUtils.escapeHtml("<ac:" + constr.qualifiedName() + "-" + affix + ">"));
        findType(constr, new Formatter(out) {

            @Override
            public void formatElementStart(String name, String type, boolean array) {
                writer.print(StringEscapeUtils.escapeHtml("  <ac:" + name + " rdf:datatype=\"" + type + "\">"));
            }

            @Override
            public void formatDocumentation(String doc) {
                writer.print(" <i style=\"font-family: Times\">" + StringEscapeUtils.escapeHtml(doc) + "</i> ");
            }

            @Override
            public void formatElementEnd(String name) {
                writer.println(StringEscapeUtils.escapeHtml("</ac:" + name + ">"));
            }

        });

        out.println(StringEscapeUtils.escapeHtml("</ac:" + constr.qualifiedName() + "-" + affix + ">"));
        out.println("</pre></div>");
    }
    out.println();
    out.flush();
}