Example usage for javax.lang.model.element AnnotationMirror toString

List of usage examples for javax.lang.model.element AnnotationMirror toString

Introduction

In this page you can find the example usage for javax.lang.model.element AnnotationMirror toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java

public static boolean isOfAnnotationType(AnnotationMirror am, String annotationType) {
    return annotationType.equals(am.toString().substring(1));
}

From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java

public static boolean isEntity(JavaSource source) {
    final boolean[] isBoolean = new boolean[1];

    try {//w  w  w.  j av a2  s.  c  o  m
        source.runUserActionTask(new AbstractTask<CompilationController>() {

            public void run(CompilationController controller) throws IOException {
                controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);

                TypeElement classElement = getTopLevelClassElement(controller);
                if (classElement == null) {
                    return;
                }

                List<? extends AnnotationMirror> annotations = controller.getElements()
                        .getAllAnnotationMirrors(classElement);

                for (AnnotationMirror annotation : annotations) {
                    if (annotation.toString().equals("@javax.persistence.Entity")) {
                        //NOI18N
                        isBoolean[0] = true;

                        break;
                    }
                }
            }
        }, true);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }

    return isBoolean[0];
}

From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java

public static String getIdFieldName(JavaSource source) {
    final String[] fieldName = new String[1];

    try {//from  w ww  . j  a  va  2 s  .  c o  m
        source.runUserActionTask(new AbstractTask<CompilationController>() {

            public void run(CompilationController controller) throws IOException {
                controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
                TypeElement classElement = getTopLevelClassElement(controller);
                if (classElement == null) {
                    return;
                }
                List<VariableElement> fields = ElementFilter.fieldsIn(classElement.getEnclosedElements());

                for (VariableElement field : fields) {
                    List<? extends AnnotationMirror> annotations = field.getAnnotationMirrors();

                    for (AnnotationMirror annotation : annotations) {
                        if (annotation.toString().equals("@javax.persistence.Id")) {
                            //NOI18N
                            fieldName[0] = field.getSimpleName().toString();
                            return;
                        }
                    }
                }
            }
        }, true);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }

    return fieldName[0];
}