Java Code Examples for javax.lang.model.element.TypeElement.accept()

The following are Jave code examples for showing how to use accept() of the javax.lang.model.element.TypeElement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: java-code-templates   File: Validator.java   Source Code and License Vote up 6 votes
boolean validateTemplate(final TypeElement templateElement) {
	try {
		assertThat(templateElement.getKind() == CLASS || templateElement.getKind() == ENUM,
				templateElement, ValidationMessages.ONLY_CLASS_OR_ENUM_TEMPLATE);

		assertThat(!isAnnotationPresent(templateElement, Descriptor.class), templateElement,
				ValidationMessages.NO_DESCRIPTOR_AND_TEMPLATE);

		// Repeated annotation container
		assertThat(!isAnnotationPresent(templateElement, Descriptors.class), templateElement,
				ValidationMessages.NO_DESCRIPTOR_AND_TEMPLATE);

		// Ensure that there are no template method name collisions
		templateElement.accept(TemplateMethodValidationVisitor.INSTANCE, Sets.newHashSet());

		// Ensure that static finals are initializable
		templateElement.accept(TemplateFieldValidationVisitor.INSTANCE, trees);

		return true;
	} catch (final ProcessorException pe) {
		pe.emitError(messager);
		return false;
	}
}
 
Example 2
Project: OpenJSharp   File: WebServiceAp.java   Source Code and License Vote up 5 votes
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (context.getRound() != 1) {
        return true;
    }
    context.incrementRound();
    WebService webService;
    WebServiceProvider webServiceProvider;
    WebServiceVisitor webServiceVisitor = new WebServiceWrapperGenerator(this, context);
    boolean processedEndpoint = false;
    Collection<TypeElement> classes = new ArrayList<TypeElement>();
    filterClasses(classes, roundEnv.getRootElements());
    for (TypeElement element : classes) {
        webServiceProvider = element.getAnnotation(WebServiceProvider.class);
        webService = element.getAnnotation(WebService.class);
        if (webServiceProvider != null) {
            if (webService != null) {
                processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_AND_WEBSERVICEPROVIDER(element.getQualifiedName()));
            }
            processedEndpoint = true;
        }

        if (webService == null) {
            continue;
        }

        element.accept(webServiceVisitor, null);
        processedEndpoint = true;
    }
    if (!processedEndpoint) {
        if (isCommandLineInvocation) {
            if (!ignoreNoWebServiceFoundWarning) {
                processWarning(WebserviceapMessages.WEBSERVICEAP_NO_WEBSERVICE_ENDPOINT_FOUND());
            }
        } else {
            processError(WebserviceapMessages.WEBSERVICEAP_NO_WEBSERVICE_ENDPOINT_FOUND());
        }
    }
    return true;
}
 
Example 3
Project: openjdk-jdk10   File: WebServiceAp.java   Source Code and License Vote up 5 votes
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (context.getRound() != 1) {
        return true;
    }
    context.incrementRound();
    WebService webService;
    WebServiceProvider webServiceProvider;
    WebServiceVisitor webServiceVisitor = new WebServiceWrapperGenerator(this, context);
    boolean processedEndpoint = false;
    Collection<TypeElement> classes = new ArrayList<TypeElement>();
    filterClasses(classes, roundEnv.getRootElements());
    for (TypeElement element : classes) {
        webServiceProvider = element.getAnnotation(WebServiceProvider.class);
        webService = element.getAnnotation(WebService.class);
        if (webServiceProvider != null) {
            if (webService != null) {
                processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_AND_WEBSERVICEPROVIDER(element.getQualifiedName()));
            }
            processedEndpoint = true;
        }

        if (webService == null) {
            continue;
        }

        element.accept(webServiceVisitor, null);
        processedEndpoint = true;
    }
    if (!processedEndpoint) {
        if (isCommandLineInvocation) {
            if (!ignoreNoWebServiceFoundWarning) {
                processWarning(WebserviceapMessages.WEBSERVICEAP_NO_WEBSERVICE_ENDPOINT_FOUND());
            }
        } else {
            processError(WebserviceapMessages.WEBSERVICEAP_NO_WEBSERVICE_ENDPOINT_FOUND());
        }
    }
    return true;
}
 
Example 4
Project: java-code-templates   File: Validator.java   Source Code and License Vote up 5 votes
Optional<DescriptorInfo> validateDescriptor(final TypeElement descriptor, final AnnotationMirror annotation) {
	try {
		// Run DescriptorInfo validations
		final DescriptorInfo info = DescriptorInfo.create(annotation, descriptor);

		// Ensure that all types referenced in "copyTypeAnnotationsTo" are
		// either the template type itself or one of its nested types.
		final String templateClassFQ = info.templateTypeName().toString();
		info.outputAnnotationTargets().forEach(annotationTarget -> {
			assertThat(annotationTarget.getQualifiedName().toString().startsWith(templateClassFQ),
					descriptor, ValidationMessages.COPY_TYPE_ANNOTATION_TEMPLATE_AND_NESTED);
		});

		assertThat((descriptor.getKind() == CLASS && descriptor.getModifiers().contains(ABSTRACT))
				|| (descriptor.getKind() == INTERFACE),
				descriptor,
				ValidationMessages.ONLY_ABSTRACT_OR_INTERFACE_DESCRIPTOR);

		assertThat(!isAnnotationPresent(descriptor, Template.class), descriptor,
				ValidationMessages.NO_DESCRIPTOR_AND_TEMPLATE);

		descriptor.accept(DescriptorValidationVisitor.INSTANCE, descriptor);

		return Optional.of(info);
	} catch (final ProcessorException pe) {
		pe.emitError(messager);
		return Optional.empty();
	}
}
 
Example 5
Project: OpenJSharp   File: WebServiceVisitor.java   Source Code and License Vote up 4 votes
private void inspectEndpointInterface(String endpointInterfaceName, TypeElement d) {
    TypeElement intTypeElement = getEndpointInterfaceElement(endpointInterfaceName, d);
    if (intTypeElement != null)
        intTypeElement.accept(this, null);
}
 
Example 6
Project: openjdk-jdk10   File: WebServiceVisitor.java   Source Code and License Vote up 4 votes
private void inspectEndpointInterface(String endpointInterfaceName, TypeElement d) {
    TypeElement intTypeElement = getEndpointInterfaceElement(endpointInterfaceName, d);
    if (intTypeElement != null)
        intTypeElement.accept(this, null);
}