Java 8 VariableElement - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 VariableElement class.

This code example shows how to use the following methods:asType, getAnnotationMirrors, getModifiers, getConstantValue, getSimpleName
  private final String summary;
 
  public FieldSummary(VariableElement element) {
    StringBuilder builder = new StringBuilder();
 
    builder.append(Annotations.printAnnotations(element.getAnnotationMirrors()));
    builder.append(Modifiers.printModifiers(element.getModifiers()));
 
    builder.append(element.asType())
        .append(" ")
        .append(element.getSimpleName());
 
    // If the field represents a compile-time constant (and therefore might be inlined) we need to 
    // capture the default value. 
    if (isCompileTimeConstant(element)) {
      builder.append(" = ").append(element.getConstantValue());
    } 
 
    builder.append("\n");
 

7
CodeRank
This code example shows how to use the following methods:asType, getAnnotationMirrors, getModifiers, getConstantValue, getSimpleName
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
 
class RenderableTypes { 
 
  public Renderable deriveFor(Element element) {
    if (element.getModifiers().contains(Modifier.PRIVATE)) {
      return new EmptySummary(); 
    } 
 
    switch (element.getKind()) {
      case ANNOTATION_TYPE:
      case CLASS:
      case ENUM:
      case INTERFACE:
        return new TypeSummary(this, (TypeElement) element);
 
      case CONSTRUCTOR:
        return new ConstructorSummary((ExecutableElement) element);

7
CodeRank
This code example shows how to use the following methods:asType, getModifiers, getConstantValue, getSimpleName
 
public class FieldsGenerator { 
 
	private static void validateField(VariableElement field) {
		// Check if field is "public static final" 
		Set<Modifier> modifiers = field.getModifiers();
		if ( modifiers.size() != 3
		     || !modifiers.contains(Modifier.PUBLIC)
		     || !modifiers.contains(Modifier.STATIC)
		     || !modifiers.contains(Modifier.FINAL) ) {
			throw new RuntimeException("Field " + field.getSimpleName() + " is not declared public static final");
		} 
 
		// Check suported types (int, long, float, String) 
		TypeMirror field_type = field.asType();
		if ( "java.lang.String".equals(field_type.toString()) ) {
		} else if ( field_type instanceof PrimitiveType ) {
			PrimitiveType field_type_prim = (PrimitiveType)field_type;
			TypeKind field_kind = field_type_prim.getKind();
			if ( field_kind != TypeKind.INT

7
CodeRank
This code example shows how to use the following methods:asType, getSimpleName
		return null; 
	} 
 
	@Override 
	public Void visitEnumConstant(VariableElement c, JAnnotationArrayMember p) {
		JClass annotationClass = helper.typeMirrorToJClass(c.asType(), holder);
		JExpression expression = JExpr.direct(annotationClass.fullName() + "." + c.getSimpleName());
		p.param(expression);
		return null; 
	} 
 
	@Override 
	public Void visitAnnotation(AnnotationMirror a, JAnnotationArrayMember p) {
		helper.addAnnotation(p, a, holder);
		return null; 
	} 
} 
6
CodeRank
This code example shows how to use the following methods:asType, getSimpleName
		return null; 
	} 
 
	@Override 
	public Void visitEnumConstant(VariableElement c, String p) {
		JClass annotationClass = helper.typeMirrorToJClass(c.asType(), holder);
		JExpression expression = JExpr.direct(annotationClass.fullName() + "." + c.getSimpleName());
		use.param(p, expression);
		return null; 
	} 
 
	@Override 
	public Void visitType(TypeMirror t, String p) {
		JClass annotationClass = helper.typeMirrorToJClass(t, holder);
		JExpression dotclass = JExpr.dotclass(annotationClass);
		use.param(p, dotclass);
		return null; 
	} 
 
	@Override 
6
CodeRank
This code example shows how to use the following methods:getAnnotation, getSimpleName
        writer.generateInterfaceHeader(proxySimpleName, reflection.getClassRepresenter().getModifiers(), "ValueProxy");
    } 
 
    protected void generateGetter(InterfaceGenerationHelper writer, VariableElement getterField) {
        // Check for embedded types. 
        UseProxy useProxyAnnotation = getterField.getAnnotation(UseProxy.class);
        UseProxyName useProxyNameAnnotation = getterField.getAnnotation(UseProxyName.class);
        if (useProxyAnnotation != null) {
            writer.generateGetter(getterField.getSimpleName().toString(), getProxyTypeMirrorName(useProxyAnnotation,
                    getterField.asType()));
        } else if (useProxyNameAnnotation != null) {
            writer.generateGetter(getterField.getSimpleName().toString(), useProxyNameAnnotation.value());
        } else { 
            writer.generateGetter(getterField);
        } 
    } 
 
    protected void generateSetter(InterfaceGenerationHelper writer, VariableElement setterField) {
        // Check for embedded types. 
        UseProxy useProxyAnnotation = setterField.getAnnotation(UseProxy.class);
6
CodeRank
This code example shows how to use the following methods:asType, getSimpleName
    @Getter 
    @Setter 
    private boolean isFinalField;
 
    public FieldInfo(@NonNull VariableElement e) {
        fieldName = e.getSimpleName().toString();
        fieldTypeName = e.asType().toString();
    } 
 
    public FieldInfo(@NonNull String fieldName, TypeMirror fieldType) {
        this.fieldName = fieldName;
        this.fieldTypeName = fieldType.toString();
    } 
     
    public FieldInfo(@NonNull String fieldName, @NonNull String fieldTypeName) {
        this.fieldName = fieldName;
        this.fieldTypeName = fieldTypeName;
    } 
 
    public void setInheritanceLevel(int inheritanceLevel) {
6
CodeRank
This code example shows how to use the following methods:getSimpleName
class EnumConstantSummary implements Renderable { 
 
  private final String summary;
 
  public EnumConstantSummary(VariableElement element) {
    summary = element.getSimpleName().toString() + "\n";
  } 
 
  @Override 
  public void appendTo(StringBuilder builder) {
    builder.append(summary);
  } 
} 
5
CodeRank
This code example shows how to use the following methods:asType
 
		List<? extends VariableElement> parameters = executableElement.getParameters();
 
		if (parameters.size() == 1) {
			VariableElement parameter = parameters.get(0);
			TypeMirror parameterType = parameter.asType();
			if (!parameterTypeQualifiedNames.contains(parameterType.toString())) {
				valid.invalidate();
				annotationHelper.printAnnotationError(executableElement, "%s can only be used on a method with no parameter or a parameter of type " + parameterTypeQualifiedNames + ", not " + parameterType);
			} 
		} 
	} 
 
	public void zeroOrOneBundleParameter(ExecutableElement executableElement, IsValid valid) {
		zeroOrOneSpecificParameter(executableElement, CanonicalNameConstants.BUNDLE, valid);
	} 
 
	public void hasOneOrTwoParametersAndFirstIsBoolean(ExecutableElement executableElement, IsValid valid) {
		List<? extends VariableElement> parameters = executableElement.getParameters();
 
5
CodeRank
This code example shows how to use the following methods:asType, getSimpleName
 
    /** 
     * Returns the field's type together with the field's simple name. 
     */ 
    public String manufactureField(VariableElement fieldElement) {
        return fieldElement.asType().toString() + " " + fieldElement.getSimpleName();
    } 
 
    public void print(Object o) { 
        writer.print(manufactureIndentation() + o);
    } 
 
    public void print(String s, Object... parameters) {
        print(replaceParameters(s, parameters));
    } 
 
    public void println() { 
        writer.println();
    } 
 
5
CodeRank
See Code Examples for Java 8 VariableElement Methods: