本文整理汇总了Java中javax.lang.model.element.ExecutableElement.getModifiers方法的典型用法代码示例。如果您正苦于以下问题:Java ExecutableElement.getModifiers方法的具体用法?Java ExecutableElement.getModifiers怎么用?Java ExecutableElement.getModifiers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.ExecutableElement
的用法示例。
在下文中一共展示了ExecutableElement.getModifiers方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isMethodTestable
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
* Checks whether a test for the given method should be created.
* Access modifiers of the given method are compared to this creator's
* settings.
*
* @param m method to be checked
* @return <code>true</code> if this creator is configured to create tests
* for methods having the given method's access modifiers;
* <code>false</code> otherwise
*/
public boolean isMethodTestable(ExecutableElement method) {
Set<Modifier> modifiers = method.getModifiers();
if (modifiers.isEmpty()) {
/*
* EnumSet.copyOf(modifiers) may throw an exception if 'modifiers'
* is empty.
*/
return isTestPackagePrivateMethods();
} else {
return (isTestPackagePrivateMethods()
&& !EnumSet.copyOf(modifiers).removeAll(ACCESS_MODIFIERS))
|| EnumSet.copyOf(modifiers).removeAll(getMethodAccessModifiers());
}
}
示例2: MethodItem
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
public MethodItem(int substitutionOffset, ExecutableElement element, boolean isInherited, boolean isDeprecated) {
super(substitutionOffset);
this.elementHandle = ElementHandle.create(element);
this.isDeprecated = isDeprecated;
this.isInherited = isInherited;
this.simpleName = element.getSimpleName().toString();
this.modifiers = element.getModifiers();
this.params = new ArrayList<ParamDesc>();
Iterator<? extends VariableElement> it = element.getParameters().iterator();
Iterator<? extends TypeMirror> tIt = ((ExecutableType) element.asType()).getParameterTypes().iterator();
while(it.hasNext() && tIt.hasNext()) {
TypeMirror tm = tIt.next();
this.params.add(new ParamDesc(tm.toString(), getTypeName(tm, false, element.isVarArgs() && !tIt.hasNext()).toString(), it.next().getSimpleName().toString()));
}
TypeMirror retType = element.getReturnType();
this.typeName = getTypeName(retType, false).toString();
this.isPrimitive = retType.getKind().isPrimitive() || retType.getKind() == TypeKind.VOID;
}
示例3: initialize
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
@Override
void initialize(final Element element, CompilationController info) {
ExecutableElement method = (ExecutableElement) element;
final Set<Modifier> modifiers = method.getModifiers();
final Icon labelIcon = ElementIcons.getElementIcon(element.getKind(), element.getModifiers());
final String labelText = UIUtilities.createHeader(method, info.getElements().isDeprecated(element), false, false, true);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Dimension preferredSize = label.getPreferredSize();
label.setText(labelText);
label.setIcon(labelIcon);
label.setPreferredSize(preferredSize);
label.setMinimumSize(preferredSize);
btn_usages.setVisible(!modifiers.contains(Modifier.STATIC));
btn_overriders.setVisible(!(modifiers.contains(Modifier.STATIC) || modifiers.contains(Modifier.PRIVATE) || element.getKind() == ElementKind.CONSTRUCTOR));
btn_usages_overriders.setVisible(btn_usages.isVisible() && btn_overriders.isVisible());
}
});
}
示例4: getScope
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private static Modifier getScope(ExecutableElement method) throws ModelException {
Modifier result = Modifier.PUBLIC;
for (Modifier mod : method.getModifiers()) {
switch (mod) {
case PROTECTED:
case PUBLIC:
result = mod;
break;
case PRIVATE:
case FINAL:
case STATIC:
throw new ModelException("timed method " + method.getSimpleName() + "() in " + method.getEnclosingElement() + " is " + mod);
default:
break;
}
}
return result;
}
示例5: makeMethodString
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
* Creates a String representation of a method element with everything
* necessary to track all public aspects of it in an API.
* @param e Element to create String for.
* @return String representation of element.
*/
protected String makeMethodString(ExecutableElement e) {
StringBuilder result = new StringBuilder();
for (Modifier modifier : e.getModifiers()) {
result.append(modifier.toString());
result.append(" ");
}
result.append(e.getReturnType().toString());
result.append(" ");
result.append(e.toString());
List<? extends TypeMirror> thrownTypes = e.getThrownTypes();
if (!thrownTypes.isEmpty()) {
result.append(" throws ");
for (Iterator<? extends TypeMirror> iterator = thrownTypes
.iterator(); iterator.hasNext();) {
TypeMirror typeMirror = iterator.next();
result.append(typeMirror.toString());
if (iterator.hasNext()) {
result.append(", ");
}
}
}
return result.toString();
}
示例6: shouldProcessMethod
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
protected boolean shouldProcessMethod(ExecutableElement method, WebMethod webMethod) {
builder.log("should process method: " + method.getSimpleName() + " hasWebMethods: " + hasWebMethods + " ");
/*
Fix for https://jax-ws.dev.java.net/issues/show_bug.cgi?id=577
if (hasWebMethods && webMethod == null) {
builder.log("webMethod == null");
return false;
}
*/
Collection<Modifier> modifiers = method.getModifiers();
boolean staticFinal = modifiers.contains(Modifier.STATIC) || modifiers.contains(Modifier.FINAL);
if (staticFinal) {
if (webMethod != null) {
builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_METHOD_IS_STATIC_OR_FINAL(method.getEnclosingElement(),
method), method);
}
return false;
}
boolean result = (endpointReferencesInterface ||
method.getEnclosingElement().equals(typeElement) ||
(method.getEnclosingElement().getAnnotation(WebService.class) != null));
builder.log("endpointReferencesInterface: " + endpointReferencesInterface);
builder.log("declaring class has WebService: " + (method.getEnclosingElement().getAnnotation(WebService.class) != null));
builder.log("returning: " + result);
return result;
}
示例7: overriding
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
static MethodSpec.Builder overriding(ExecutableElement method) {
String methodName = method.getSimpleName().toString();
MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName)
.addAnnotation(Override.class);
Set<Modifier> modifiers = method.getModifiers();
modifiers = new LinkedHashSet<>(modifiers);
modifiers.remove(Modifier.ABSTRACT);
Modifier defaultModifier = null;
// Modifier.DEFAULT doesn't exist until Java 8.
try {
defaultModifier = Modifier.valueOf("DEFAULT");
} catch (IllegalArgumentException e) {
// Ignored.
}
modifiers.remove(defaultModifier);
builder = builder.addModifiers(modifiers);
for (TypeParameterElement typeParameterElement : method.getTypeParameters()) {
TypeVariable var = (TypeVariable) typeParameterElement.asType();
builder = builder.addTypeVariable(TypeVariableName.get(var));
}
builder = builder.returns(TypeName.get(method.getReturnType()))
.addParameters(getParameters(method))
.varargs(method.isVarArgs());
for (TypeMirror thrownType : method.getThrownTypes()) {
builder = builder.addException(TypeName.get(thrownType));
}
return builder;
}
示例8: isExecutable
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private static boolean isExecutable(ExecutableElement method) {
if (method == null) {
return false;
}
Set<Modifier> modifiers = method.getModifiers();
if (modifiers.contains(Modifier.ABSTRACT) || modifiers.contains(Modifier.NATIVE)) {
return false;
}
return true;
}
示例9: dump
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private String dump(ExecutableElement ee) {
StringBuilder result = new StringBuilder();
for (Modifier m : ee.getModifiers()) {
result.append(m.toString());
result.append(' ');
}
result.append(ee.getReturnType().toString() + " " + ee.toString());
return result.toString();
}
示例10: generateWriteToJson
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private MethodSpec generateWriteToJson(Context context, ExecutableElement writeMethodElement,
List<JsonProperty> properties, Map<TypeMirror, FieldSpec> typeAdapters,
NameAllocator nameAllocator) {
Set<Modifier> modifierSet = new TreeSet<>(writeMethodElement.getModifiers());
modifierSet.remove(ABSTRACT);
MethodSpec.Builder builder =
MethodSpec.methodBuilder(writeMethodElement.getSimpleName().toString())
.addAnnotation(Override.class)
.addModifiers(modifierSet)
.returns(JSON_OBJ_CLASS_NAME);
FieldSpec json = FieldSpec.builder(JSON_OBJ_CLASS_NAME, nameAllocator.newName("json")).build();
builder.addStatement("$1T $2N = new $1T()", JSON_OBJ_CLASS_NAME, json);
Types types = context.processingEnvironment().getTypeUtils();
for (JsonProperty prop : properties) {
if (prop.typeAdapter != null && typeAdapters.containsKey(prop.typeAdapter)) {
builder.addCode(
JsonGeneratorUtils.writeWithAdapter(typeAdapters.get(prop.typeAdapter), json, prop));
} else {
//TODO Discuss: Is null check needed?
builder.beginControlFlow("try");
if (prop.nullable()) {
builder.beginControlFlow("if ($N() != null)", prop.methodName);
builder.addCode(JsonGeneratorUtils.writeValue(types, prop, json));
builder.endControlFlow();
} else {
builder.addCode(JsonGeneratorUtils.writeValue(types, prop, json));
}
builder.endControlFlow("catch($T e) {}", JSON_EXCEPTION);
}
}
builder.addStatement("return $N", json);
return builder.build();
}
示例11: visitExecutable
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public Void visitExecutable(ExecutableElement e, Void p) {
if (isNonPrivate(e)) {
PubMethod m = new PubMethod(e.getModifiers(),
getTypeParameters(e.getTypeParameters()),
TypeDesc.fromType(e.getReturnType()),
e.getSimpleName().toString(),
getTypeDescs(getParamTypes(e)),
getTypeDescs(e.getThrownTypes()));
collectedApi.methods.put(m.asSignatureString(), m);
}
return null;
}
示例12: isAbstract
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private static boolean isAbstract(ExecutableElement element) {
for (Modifier modifier : element.getModifiers()) {
if (modifier == Modifier.ABSTRACT) {
return true;
}
}
return false;
}
示例13: isTestableEJBMethod
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private boolean isTestableEJBMethod(ExecutableElement method){
Set<Modifier> modifiers = method.getModifiers();
return !(modifiers.isEmpty() || !EnumSet.copyOf(modifiers).removeAll(ACCESS_MODIFIERS)) &&
!modifiers.contains(Modifier.PROTECTED);
}