Example usage for javax.lang.model.element Modifier VOLATILE

List of usage examples for javax.lang.model.element Modifier VOLATILE

Introduction

In this page you can find the example usage for javax.lang.model.element Modifier VOLATILE.

Prototype

Modifier VOLATILE

To view the source code for javax.lang.model.element Modifier VOLATILE.

Click Source Link

Document

The modifier volatile

Usage

From source file:io.soabase.halva.processor.caseclass.Templates.java

void addField(CaseClassItem item, TypeSpec.Builder builder, TypeName type, boolean makeFinal,
        boolean makeVolatile, Settings settings) {
    TypeName localType;//from   w w w. ja  v a 2s . c o  m
    if (makeFinal) {
        localType = type;
    } else {
        localType = item.hasDefaultValue() ? type.box() : type;
    }
    FieldSpec.Builder fieldBuilder = FieldSpec.builder(localType, item.getName(), Modifier.PRIVATE);
    if (makeFinal) {
        fieldBuilder.addModifiers(Modifier.FINAL);
    }
    if (makeVolatile) {
        fieldBuilder.addModifiers(Modifier.VOLATILE);
    }
    Set<AnnotationSpec> annotationSpecs = new HashSet<>();
    if (settings.json) {
        List<AnnotationSpec> parent = parentJsonAnnotations(item.getElement());
        if (parent.isEmpty()) {
            AnnotationSpec annotationSpec = AnnotationSpec
                    .builder(ClassName.get("com.fasterxml.jackson.annotation", "JsonProperty")).build();
            parent = Collections.singletonList(annotationSpec);
        }
        annotationSpecs.addAll(parent);
    }
    if (settings.validate) {
        item.getElement().getAnnotationMirrors().stream().map(AnnotationSpec::get)
                .forEach(annotationSpecs::add);
    }
    fieldBuilder.addAnnotations(annotationSpecs);
    builder.addField(fieldBuilder.build());
}

From source file:com.github.benmanes.caffeine.cache.node.AddExpiration.java

private void addAccessExpiration() {
    if (!context.generateFeatures.contains(Feature.EXPIRE_ACCESS)) {
        return;/*from  ww w .  j  av a 2 s . co  m*/
    }
    context.nodeSubtype.addField(newFieldOffset(context.className, "accessTime"))
            .addField(long.class, "accessTime", Modifier.VOLATILE)
            .addMethod(newGetter(Strength.STRONG, TypeName.LONG, "accessTime", Visibility.LAZY))
            .addMethod(newSetter(TypeName.LONG, "accessTime", Visibility.LAZY));
    addTimeConstructorAssignment(context.constructorByKey, "accessTime");
    addTimeConstructorAssignment(context.constructorByKeyRef, "accessTime");
}

From source file:com.github.benmanes.caffeine.cache.node.AddExpiration.java

private void addWriteExpiration() {
    if (!Feature.useWriteTime(context.parentFeatures) && Feature.useWriteTime(context.generateFeatures)) {
        context.nodeSubtype.addField(newFieldOffset(context.className, "writeTime"))
                .addField(long.class, "writeTime", Modifier.VOLATILE)
                .addMethod(newGetter(Strength.STRONG, TypeName.LONG, "writeTime", Visibility.LAZY))
                .addMethod(newSetter(TypeName.LONG, "writeTime", Visibility.LAZY));
        addTimeConstructorAssignment(context.constructorByKey, "writeTime");
        addTimeConstructorAssignment(context.constructorByKeyRef, "writeTime");
    }/*from ww w . j a  va2s  .co m*/
}