本文整理汇总了Java中com.google.auto.common.MoreElements.asExecutable方法的典型用法代码示例。如果您正苦于以下问题:Java MoreElements.asExecutable方法的具体用法?Java MoreElements.asExecutable怎么用?Java MoreElements.asExecutable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.auto.common.MoreElements
的用法示例。
在下文中一共展示了MoreElements.asExecutable方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseConstructors
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private static List<AutoReducerConstructor> parseConstructors(TypeElement typeElement) throws ValidationException {
List<AutoReducerConstructor> constructors = new ArrayList<>();
boolean hasNonDefaultConstructors = false;
for (Element element : typeElement.getEnclosedElements()) {
if (element.getKind() == ElementKind.CONSTRUCTOR) {
ExecutableElement executableElement = MoreElements.asExecutable(element);
if (executableElement.getModifiers().contains(Modifier.PRIVATE)) continue;
List<? extends VariableElement> parameters = executableElement.getParameters();
hasNonDefaultConstructors |= parameters.size() != 0;
constructors.add(new AutoReducerConstructor(executableElement));
}
}
//if we only have one default constructor, it can be omitted
if (!hasNonDefaultConstructors && constructors.size() == 1) return Collections.emptyList();
//this is the case when all constructors are private
if (constructors.size() == 0)
throw new ValidationException(typeElement, "No accessible constructors available for class %s", typeElement);
return constructors;
}
示例2: getVisibleExecutableElements
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
/**
* Get Map of public and protected methods.
* Map entry represent format like [{@link Visibility#PUBLIC} - {@link List<ExecutableElement>}]
* @param element element from methods will be extracted
* @param env {@link ProcessingEnvironment}
* @return Map
*/
private static Map<Visibility, ? extends List<ExecutableElement>> getVisibleExecutableElements(TypeElement element, ProcessingEnvironment env) {
HashMap<Visibility, List<ExecutableElement>> map = new HashMap<Visibility, List<ExecutableElement>>();
// Initialize
for (Visibility v : Visibility.values()) {
addValueToMapList(v, null, map);
}
List<? extends Element> allMembers = env
.getElementUtils()
.getAllMembers(element);
// Get only public and protected methods with @ShareProtected annotation.
for (Element member : allMembers) {
if (member.getKind() != ElementKind.METHOD)
continue;
// Skip methods from link java.lang.Object
if (member.getEnclosingElement().equals(env.getElementUtils().getTypeElement(Object.class.getName()))) {
continue;
}
ExecutableElement executableMember = MoreElements.asExecutable(member);
Set<Modifier> modifiers = executableMember.getModifiers();
// skip non valid methods
if (modifiers.contains(Modifier.FINAL) || modifiers.contains(Modifier.STATIC))
continue;
if (modifiers.contains(Modifier.PROTECTED)) {
addValueToMapList(Visibility.PROTECTED, executableMember, map);
} else if (modifiers.contains(Modifier.PUBLIC)) {
addValueToMapList(Visibility.PUBLIC, executableMember, map);
}
}
return map;
}
示例3: processElement
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
@Override
public boolean processElement(Element element, Errors.ElementErrors elementErrors) {
// @AutoX applied on annotation
if (element.getKind() == ElementKind.ANNOTATION_TYPE) {
// @AutoX is applied on another annotation, find out the targets of that annotation
Set<? extends Element> targetElements = roundEnvironment.getElementsAnnotatedWith(MoreElements.asType(element));
for (Element targetElement : targetElements) {
if (!process(targetElement, element)) {
return false;
}
}
return true;
}
// @AutoX applied on method
// only valid for @AutoExpose with @Provides
if (element.getKind() == ElementKind.METHOD) {
if (processedAnnotation.equals(AutoInjector.class)) {
errors.addInvalid(element, "@AutoInjector cannot be applied on the method %s", element.getSimpleName());
return false;
}
if (!MoreElements.isAnnotationPresent(element, Provides.class)) {
errors.addInvalid(element, "@AutoExpose can be applied on @Provides method only, %s is missing it", element.getSimpleName());
return false;
}
ExecutableElement executableElement = MoreElements.asExecutable(element);
Element returnElement = MoreTypes.asElement(executableElement.getReturnType());
return process(returnElement, element);
}
process(element, element);
return !errors.hasErrors();
}
示例4: findConstructor
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
/**
* @return The constructor of the dispatcher
*/
@Nullable
private ExecutableElement findConstructor() {
for (Element element : typeElement().getEnclosedElements()) {
if (element.getKind() == ElementKind.CONSTRUCTOR) {
return MoreElements.asExecutable(element);
}
}
return null;
}
示例5: hasErrorHandler
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
public boolean hasErrorHandler() {
for (Element element : typeElement().getEnclosedElements()) {
if (element.getKind() == ElementKind.METHOD) {
ExecutableElement method = MoreElements.asExecutable(element);
if (method.getSimpleName().toString().equals(DISPATCH_ERROR_HANDLER_NAME)
&& method.getParameters().size() == 1
&& method.getParameters().get(0).asType().toString().equals(Throwable.class.getCanonicalName())
) {
return true;
}
}
}
return false;
}
示例6: hasDispatchMethodByName
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private boolean hasDispatchMethodByName(String name) {
for (Element element : typeElement().getEnclosedElements()) {
if (element.getKind() == ElementKind.METHOD) {
ExecutableElement method = MoreElements.asExecutable(element);
if (method.getSimpleName().toString().equals(name)
&& Visibility.ofElement(method).compareTo(Visibility.DEFAULT) >= 0
&& method.getParameters().size() == 0) {
return true;
}
}
}
return false;
}
示例7: parseStringReducerElement
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
public static StringReducerElement parseStringReducerElement(Element element, Map<String, ActionCreatorElement> knownActionCreators, Env env) throws ValidationException {
if (element.getKind() != ElementKind.CLASS) {
throw new ValidationException(element, "You can apply %s only to classes", AutoReducer.class.getSimpleName());
}
TypeElement typeElement = (TypeElement) element;
if (MoreTypes.asDeclared(typeElement.asType()).getEnclosingType().getKind() != TypeKind.NONE) {
throw new ValidationException(element, "%s annotated reducers should not be inner classes. Probably 'static' modifier missing", AutoReducer.class.getSimpleName());
}
DeclaredType declaredType = (DeclaredType) typeElement.asType();
DeclaredType reducerSuperInterface = Utils.getReducerSuperInterface(declaredType);
if (reducerSuperInterface == null) {
throw new ValidationException(typeElement, "%s should implement %s interface", typeElement, Reducer.class.getSimpleName());
}
TypeMirror stateType = reducerSuperInterface.getTypeArguments().get(0);
List<ReduceAction> actions = new ArrayList<>();
AutoReducerInit initMethod = null;
for (Element enclosedElement : typeElement.getEnclosedElements()) {
if(enclosedElement.getKind() != ElementKind.METHOD) continue;
ExecutableElement executableElement = MoreElements.asExecutable(enclosedElement);
if (enclosedElement.getAnnotation(AutoReducer.InitialState.class) != null) {
if(initMethod != null) {
throw new ValidationException(enclosedElement, "Methods %s and %s are both annotated with @AutoReducer.InitialState. Only one @AutoReducer.InitialState method is allowed", initMethod.executableElement, executableElement);
}
initMethod = AutoReducerInit.parse(env, executableElement, stateType);
} else {
ReduceAction reduceAction = ReduceAction.parseReduceAction(env, stateType, executableElement, knownActionCreators);
if (reduceAction != null) {
actions.add(reduceAction);
}
}
}
List<AutoReducerConstructor> constructors = parseConstructors(typeElement);
final DeclaredType stateDeclaredType = (DeclaredType) stateType;
return new StringReducerElement(stateDeclaredType, actions, initMethod, typeElement, constructors);
}