本文整理汇总了Java中javax.lang.model.element.ExecutableElement.getEnclosingElement方法的典型用法代码示例。如果您正苦于以下问题:Java ExecutableElement.getEnclosingElement方法的具体用法?Java ExecutableElement.getEnclosingElement怎么用?Java ExecutableElement.getEnclosingElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.ExecutableElement
的用法示例。
在下文中一共展示了ExecutableElement.getEnclosingElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collectSubscribers
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private void collectSubscribers(Set<? extends TypeElement> annotations, RoundEnvironment env, Messager messager) {
for (TypeElement annotation : annotations) {
Set<? extends Element> elements = env.getElementsAnnotatedWith(annotation);
for (Element element : elements) {
if (element instanceof ExecutableElement) {
ExecutableElement method = (ExecutableElement) element;
if (checkHasNoErrors(method, messager)) {
TypeElement classElement = (TypeElement) method.getEnclosingElement();
methodsByClass.putElement(classElement, method);
}
} else {
messager.printMessage(Diagnostic.Kind.ERROR, "@Subscribe is only valid for methods", element);
}
}
}
}
示例2: isSetter
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
protected boolean isSetter(TypeElement element, ExecutableElement x, boolean includeStatic) {
final String name = x.getSimpleName().toString();
final TypeMirror returnType = x.getReturnType();
final boolean isStatic = includeStatic && x.getParameters().size() == 2;
if (x.getParameters().size() != (isStatic ? 2 : 1)) {
return false;
}
if (isStatic && !types().isSameType(x.getParameters().get(0).asType(), element.asType())) {
return false;
}
if (!name.startsWith("set")) {
return false;
}
if (returnType.getKind().equals(TypeKind.VOID)) {
return true;
}
return x.getEnclosingElement() != null && types().isAssignable(x.getEnclosingElement().asType(), returnType);
}
示例3: getMethodColoring
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private Collection<ColoringAttributes> getMethodColoring(ExecutableElement mdecl, boolean nct) {
Collection<ColoringAttributes> c = new ArrayList<ColoringAttributes>();
addModifiers(mdecl, c);
if (mdecl.getKind() == ElementKind.CONSTRUCTOR) {
c.add(ColoringAttributes.CONSTRUCTOR);
//#146820:
if (nct && mdecl.getEnclosingElement() != null && info.getElements().isDeprecated(mdecl.getEnclosingElement())) {
c.add(ColoringAttributes.DEPRECATED);
}
} else
c.add(ColoringAttributes.METHOD);
return c;
}
示例4: TimedMethodModel
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
TimedMethodModel(ModelContext ctx, ExecutableElement method, TimeThis annotation) throws ModelException {
this.annotation = annotation;
this.method = method;
this.scope = getScope(method);
String msg = "method " + method.getSimpleName() + " in " + method.getEnclosingElement();
List<? extends VariableElement> params = method.getParameters();
if (params.isEmpty()) {
throw new ModelException(msg + ": expected at least one " + ProcessingContext.class.getCanonicalName() + " parameter");
}
boolean first = true;
for (VariableElement param : params) {
TypeMirror paramType = param.asType();
if (first) {
if (!ctx.isProcessingContext(paramType)) {
throw new ModelException(msg + ": first parameter must be of type " + ProcessingContext.class.getCanonicalName());
}
first = false;
continue;
}
checkPublicType(ctx, paramType, method, false, msg);
}
TypeMirror returnType = method.getReturnType();
checkPublicType(ctx, returnType, method, true, msg);
}
示例5: initCreationString
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private static String initCreationString (ExecutableElement element, CompilationInfo javac) {
TypeElement enclClass = (TypeElement) element.getEnclosingElement();
String code = "new MethodDescriptor(%1$s.class.getMethod(\"%2$s\", new Class[] {%3$s}))"; // NOI18N
String paramdelim = ", "; //NOI18N
StringBuilder sb = new StringBuilder();
for (VariableElement param : element.getParameters()) {
sb.append(paramdelim).append(getTypeClass(param.asType(), javac)).append(".class"); // NOI18N
}
return String.format(
code,
enclClass.getQualifiedName(),
element.getSimpleName(),
sb.length() == 0? sb: sb.substring(paramdelim.length())
);
}
示例6: validateGlideTypeParameters
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private static void validateGlideTypeParameters(ExecutableElement executableElement) {
if (executableElement.getParameters().size() != 1) {
throw new IllegalArgumentException("@GlideType methods must take a"
+ " RequestBuilder object as their first and only parameter, but given multiple for: "
+ executableElement.getEnclosingElement() + "#" + executableElement);
}
VariableElement first = executableElement.getParameters().get(0);
TypeMirror argumentType = first.asType();
if (!argumentType.toString().startsWith("com.bumptech.glide.RequestBuilder")) {
throw new IllegalArgumentException("@GlideType methods must take a"
+ " RequestBuilder object as their first and only parameter, but given: " + argumentType);
}
}
示例7: guessField
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
public static VariableElement guessField(ExecutableElement getter) {
String name = getter.getSimpleName().toString().substring(3);
String guessFieldName = name.substring(0,1).toLowerCase() + name.substring(1);
TypeElement typeElement = (TypeElement) getter.getEnclosingElement();
for (VariableElement variableElement : ElementFilter.fieldsIn(typeElement.getEnclosedElements())) {
if (variableElement.getSimpleName().contentEquals(guessFieldName)) {
return variableElement;
}
}
Logger.getLogger(JpaControllerUtil.class.getName()).log(Level.WARNING, "Cannot detect the field associated with property: {0}", guessFieldName);
return null;
}
示例8: guessGetter
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
* TODO: actually it's guess setter from setter, need to review if it's a problem of expected
* @param setter
* @return
*/
public static VariableElement guessGetter(ExecutableElement setter) {
String name = setter.getSimpleName().toString().substring(3);
String guessGetterName = "set" + name;
TypeElement typeElement = (TypeElement) setter.getEnclosingElement();
for (VariableElement variableElement : ElementFilter.fieldsIn(typeElement.getEnclosedElements())) {
if (variableElement.getSimpleName().contentEquals(guessGetterName)) {
return variableElement;
}
}
Logger.getLogger(JpaControllerUtil.class.getName()).log(Level.INFO, "Cannot detect setter associated with getter: {0}", guessGetterName);
return null;
}
示例9: visitExecutable
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
@Override
public StringBuilder visitExecutable(ExecutableElement e, Boolean p) {
if (p != Boolean.TRUE || e.getEnclosingElement() == null) {
return DEFAULT_VALUE.append(e.getSimpleName());
} else {
return e.getEnclosingElement().accept(this, p).
append(".").
append(e.getSimpleName());
}
}
示例10: isOverridden
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private boolean isOverridden(ExecutableElement methodBase, TypeElement origin) {
Element impl = getImplementationOf(methodBase, origin);
if (impl == null || impl == methodBase && origin != methodBase.getEnclosingElement()) {
return false;
}
return true;
}
示例11: augmentProperties
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
* Explicitly add properties that elude reflection implicit strategy
* @param element
* @param props
*/
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
protected void augmentProperties(ExecutableElement element, Properties props) {
final TypeElement typedElement = (TypeElement) element.getEnclosingElement();
if (beanAnnotationClass != null && element.getAnnotation(beanAnnotationClass) != null) {
props.put("kind", "ENDPOINT");
} else {
props.put("kind", "BEAN");
props.put("entrypoint", typedElement.getQualifiedName().toString() + "::" + element.getSimpleName());
}
}
示例12: methodsIn
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
* Returns all public methods of a type element, whether inherited or
* declared directly. It excludes methods of {@link Object} that are useless
* for bean patterns.
* @param clazz class to search
* @param javac javac
* @return list of public methods
*/
public static List<? extends ExecutableElement> methodsIn(TypeElement clazz, CompilationInfo javac) {
List<ExecutableElement> result = ElementFilter.methodsIn(javac.getElements().getAllMembers(clazz));
final TypeElement objectElement = javac.getElements().getTypeElement("java.lang.Object"); // NOI18N
for (int i = result.size() - 1; i >= 0; i--) {
ExecutableElement method = result.get(i);
if (!method.getModifiers().contains(Modifier.PUBLIC) || objectElement == method.getEnclosingElement()) {
result.remove(i);
}
}
return result;
}
示例13: addComments
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void addComments(ExecutableElement property, Content propertyDocTree) {
TypeElement holder = (TypeElement)property.getEnclosingElement();
if (!utils.getFullBody(property).isEmpty()) {
if (holder.equals(typeElement) ||
(!utils.isPublic(holder) || utils.isLinkable(holder))) {
writer.addInlineComment(property, propertyDocTree);
} else {
Content link =
writer.getDocLink(LinkInfoImpl.Kind.PROPERTY_COPY,
holder, property,
utils.isIncluded(holder)
? holder.getSimpleName() : holder.getQualifiedName(),
false);
Content codeLink = HtmlTree.CODE(link);
Content descfrmLabel = HtmlTree.SPAN(HtmlStyle.descfrmTypeLabel,
utils.isClass(holder)
? contents.descfrmClassLabel
: contents.descfrmInterfaceLabel);
descfrmLabel.addContent(Contents.SPACE);
descfrmLabel.addContent(codeLink);
propertyDocTree.addContent(HtmlTree.DIV(HtmlStyle.block, descfrmLabel));
writer.addInlineComment(property, propertyDocTree);
}
}
}
示例14: buildMethodTags
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
* Build the method tags.
*
* @param methodsContentTree content tree to which the documentation will be added
*/
protected void buildMethodTags(Content methodsContentTree) {
methodWriter.addMemberTags((ExecutableElement)currentMember, methodsContentTree);
ExecutableElement method = (ExecutableElement)currentMember;
if (method.getSimpleName().toString().compareTo("writeExternal") == 0
&& utils.getSerialDataTrees(method).isEmpty()) {
if (configuration.serialwarn) {
TypeElement encl = (TypeElement) method.getEnclosingElement();
messages.warning(currentMember,
"doclet.MissingSerialDataTag", encl.getQualifiedName().toString(),
method.getSimpleName().toString());
}
}
}
示例15: visitMemberSelect
import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
@Override
public Void visitMemberSelect(MemberSelectTree node, Void p) {
Void d = super.visitMemberSelect(node, p);
Element el = info.getTrees().getElement(getCurrentPath());
messageMethod = null;
if (el == null || el.getKind() != ElementKind.METHOD) {
return d;
}
ExecutableElement ee = (ExecutableElement)el;
String sn = ee.getSimpleName().toString();
for (MessagePattern desc : descriptions) {
if (!desc.getMethodNamePattern().matcher(sn).matches()) {
continue;
}
// check the defining type
el = ee.getEnclosingElement();
if (el == null || !(el.getKind().isClass() || el.getKind().isInterface())) {
continue;
}
TypeElement tel = (TypeElement)el;
if (!desc.getOwnerTypePattern().matcher(tel.getQualifiedName().toString()).matches()) {
continue;
}
messageMethod = desc;
methodName = sn;
methodOwnerPath = new TreePath(getCurrentPath(), node.getExpression());
break;
}
return d;
}