当前位置: 首页>>代码示例>>Java>>正文


Java ExecutableElement类代码示例

本文整理汇总了Java中javax.lang.model.element.ExecutableElement的典型用法代码示例。如果您正苦于以下问题:Java ExecutableElement类的具体用法?Java ExecutableElement怎么用?Java ExecutableElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExecutableElement类属于javax.lang.model.element包,在下文中一共展示了ExecutableElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Property

import javax.lang.model.element.ExecutableElement; //导入依赖的package包/类
Property( PropertyPattern pp, CompilationInfo javac, BiAnalyser bia ) throws GenerateBeanException {
    super( pp, bia );
    mode = pp.getMode();
    pattern = pp;

    TypeElement declaringClass = pattern.getDeclaringClass().resolve(javac);
    declaringClassName = declaringClass.getQualifiedName().toString();
    ElementHandle<ExecutableElement> getterHandle = pattern.getGetterMethod();
    getterName = getterHandle == null? null: getterHandle.resolve(javac).getSimpleName().toString();
    ElementHandle<ExecutableElement> setterHandle = pattern.getSetterMethod();
    setterName = setterHandle == null? null: setterHandle.resolve(javac).getSimpleName().toString();

    if (LOG.isLoggable(Level.FINE) && getClass() == Property.class) {
        debugTooltip = String.format("<html><body><b>Field:</b> %s<br><b>Getter:</b> %s<br><b>Setter:</b> %s</body></html>", // NOI18N
                pp.getEstimatedField() == null
                        ? null
                        : ElementHeaders.getHeader(pp.getEstimatedField().resolve(javac), javac, ElementHeaders.NAME +
                                " : " + ElementHeaders.TYPE) + " :: " + // NOI18N
                                ((TypeElement) pp.getEstimatedField().resolve(javac).getEnclosingElement()).getQualifiedName(),
                printMethodHandleTip(getterHandle, javac),
                printMethodHandleTip(setterHandle, javac)
                );
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:BiFeature.java

示例2: handlerMethod

import javax.lang.model.element.ExecutableElement; //导入依赖的package包/类
/**
 * handler method annotations
 *
 * @param element
 */
private void handlerMethod(ExecutableElement element) {
    if (onMethodRegulaListener != null) {
        String msg = onMethodRegulaListener.onRegula(element);
        if (!("".equals(msg) || msg == null)) {
            throwExceptionWithMsg(msg, element);
            return;
        }
    }
    MethodEntity methodEntity = new MethodEntity(element, typeUtils, elementUtils);

    printNormalMsg(methodEntity.toString());

    String className = methodEntity.getClassSimpleName();
    if (classEntityMap.get(className) == null){
        classEntityMap.put(className,
                new ClassEntity(elementUtils, typeUtils,
                        (TypeElement) element.getEnclosingElement()));
    }

    ClassEntity classEntity = classEntityMap.get(className);
    classEntity.addMethodEntity(methodEntity);
}
 
开发者ID:simplezhli,项目名称:RxPay,代码行数:28,代码来源:EntityHandler.java

示例3: addMethodFqn

import javax.lang.model.element.ExecutableElement; //导入依赖的package包/类
public void addMethodFqn(Element el) {
    if (el.getKind() != ElementKind.METHOD) {
        return;
    }
    String fqn = info.getElementUtilities().getElementName(el, true).toString();
    List<Element> els = fqn2Methods.get(fqn);
    if (els == null) {
        els = new ArrayList<>(2);
        fqn2Methods.put(fqn, els);
    }
    els.add(el);
    String simpleName = ((ExecutableElement)el).getSimpleName().toString();
    Set<String> col = possibleMethodFQNs.get(simpleName);
    if (col == null) {
        col = new HashSet<>(3);
        possibleMethodFQNs.put(simpleName, col);
    }
    col.add(fqn);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ComputeImports.java

示例4: getMethodToParams

import javax.lang.model.element.ExecutableElement; //导入依赖的package包/类
@TargetApi(24)
private Map<ExecutableElement, List<MethodParam>> getMethodToParams(List<ExecutableElement> methods) {
    return methods.stream()
            .collect(Collectors.toMap(
                    method -> method,
                    method -> {
                        AtomicInteger index = new AtomicInteger(0);
                        return method.getParameters()
                                .stream()
                                .map(varElm -> {
                                    String paramName = String.format(Locale.US, "arg%d", index.incrementAndGet());
                                    TypeName typeName = TypeName.get(varElm.asType());
                                    return MethodParam.of(paramName, typeName, varElm);
                                })
                                .collect(Collectors.toList());
                    }
            ));
}
 
开发者ID:srym,项目名称:vulture,代码行数:19,代码来源:VultureProcessor.java

示例5: testConstructorSignatureFromElement

import javax.lang.model.element.ExecutableElement; //导入依赖的package包/类
public void testConstructorSignatureFromElement () throws Exception {	
InputStream in = this.prepareData(TEST_CLASS);
try {
    JavacTask jt = prepareJavac ();
    Elements elements = jt.getElements();
    TypeElement be = elements.getTypeElement(TEST_CLASS);
    ClassFile cf = new ClassFile (in, true);
    String className = cf.getName().getInternalName().replace('/','.'); //NOI18N
    List<? extends Element> members = be.getEnclosedElements();
    for (Element e : members) {
	if (e.getKind() == ElementKind.CONSTRUCTOR) {
	    String[] msig = ClassFileUtil.createExecutableDescriptor((ExecutableElement) e);
	    assertEquals (className,msig[0]);
	    assertEquals (e.getSimpleName().toString(),msig[1]);
	    Method m = cf.getMethod (e.getSimpleName().toString(),msig[2]);
	    assertNotNull (m);
	}
    }
} finally {
    in.close ();
}
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:CompromiseSATest.java

示例6: tryToUseSourceAsAWorkaround

import javax.lang.model.element.ExecutableElement; //导入依赖的package包/类
private boolean tryToUseSourceAsAWorkaround() {
  if (element.getKind() != ElementKind.METHOD) {
    // we don't bother with non-method attributes
    // (like factory builder, where attributes are parameters)
    return false;
  }

  CharSequence returnTypeString = SourceExtraction.getReturnTypeString((ExecutableElement) element);
  if (returnTypeString.length() == 0) {
    // no source could be extracted for some reason, workaround will not work
    return false;
  }

  Entry<String, List<String>> extractedTypes = SourceTypes.extract(returnTypeString);

  // forces source imports based resolution,
  // we should not rely that types would be fully qualified
  Entry<String, List<String>> resolvedTypes = resolveTypes(extractedTypes);

  this.rawTypeName = resolvedTypes.getKey();
  this.workaroundTypeParameters = resolvedTypes.getValue();
  this.workaroundTypeString = SourceTypes.stringify(resolvedTypes);

  // workaround may have successed, need to continue with whatever we have
  return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:TypeStringProvider.java

示例7: generateClass

import javax.lang.model.element.ExecutableElement; //导入依赖的package包/类
@Override
public String generateClass(Context context, String className, String classToExtend, boolean isFinal) {
    String packageName = context.packageName();
    Name superName = context.autoValueClass().getSimpleName();
    Map<String, ExecutableElement> properties = context.properties();
    TypeName parametrizedType = getParametrizedType(context);

    TypeName variantName = parametrizedType == null ? TypeName.get(Object.class) : parametrizedType;
    TypeSpec subclass = TypeSpec.classBuilder(className)
            .addModifiers(isFinal ? Modifier.FINAL : Modifier.ABSTRACT)
            .superclass(ClassName.get(packageName, classToExtend))
            .addMethod(generateConstructor(properties))
            .addMethod(generateVariantOf(superName, variantName))
            .addMethod(generateVariantOfInGroup(superName, variantName))
            .addMethod(generateVariantOrEqual(superName, variantName))
            .addMethod(generateVariantOrEqualInGroup(superName, variantName))
            .addMethod(generateGroupFieldsEqual(TypeName.get(context.autoValueClass().asType()), properties))
            .build();

    JavaFile javaFile = JavaFile.builder(packageName, subclass).build();
    return javaFile.toString();
}
 
开发者ID:ccheptea,项目名称:auto-value-variant,代码行数:23,代码来源:AutoValueVariantExtension.java

示例8: addExceptions

import javax.lang.model.element.ExecutableElement; //导入依赖的package包/类
/**
 * Add exceptions for the executable member.
 *
 * @param member the member to write exceptions for.
 * @param htmltree the content tree to which the exceptions information will be added.
 */
protected void addExceptions(ExecutableElement member, Content htmltree, int indentSize) {
    List<? extends TypeMirror> exceptions = member.getThrownTypes();
    if (!exceptions.isEmpty()) {
        CharSequence indent = makeSpace(indentSize + 1 - 7);
        htmltree.addContent(DocletConstants.NL);
        htmltree.addContent(indent);
        htmltree.addContent("throws ");
        indent = makeSpace(indentSize + 1);
        Content link = writer.getLink(new LinkInfoImpl(configuration, MEMBER, exceptions.get(0)));
        htmltree.addContent(link);
        for(int i = 1; i < exceptions.size(); i++) {
            htmltree.addContent(",");
            htmltree.addContent(DocletConstants.NL);
            htmltree.addContent(indent);
            Content exceptionLink = writer.getLink(new LinkInfoImpl(configuration, MEMBER,
                    exceptions.get(i)));
            htmltree.addContent(exceptionLink);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:AbstractExecutableMemberWriter.java

示例9: computeReturn

import javax.lang.model.element.ExecutableElement; //导入依赖的package包/类
private static List<? extends TypeMirror> computeReturn(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    ReturnTree rt = (ReturnTree) parent.getLeaf();
    
    if (rt.getExpression() == error) {
        TreePath method = findMethod(parent);
        
        if (method == null) {
            return null;
        }
        
        Element el = info.getTrees().getElement(method);
        
        if (el == null || el.getKind() != ElementKind.METHOD) {
            return null;
        }
        
        types.add(ElementKind.PARAMETER);
        types.add(ElementKind.LOCAL_VARIABLE);
        types.add(ElementKind.FIELD);
        
        return Collections.singletonList(((ExecutableElement) el).getReturnType());
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:CreateElementUtilities.java

示例10: findMethod

import javax.lang.model.element.ExecutableElement; //导入依赖的package包/类
@NbBundle.Messages("JavaUtils.title.method.searching=Searching Method")
public static ElementHandle<ExecutableElement> findMethod(FileObject fileObject, final String classBinName,
        final String methodName, int argCount, Public publicFlag, Static staticFlag) {
    JavaSource js = JavaUtils.getJavaSource(fileObject);
    if (js != null) {
        MethodFinder methodFinder = new MethodFinder(js, classBinName, methodName, argCount, publicFlag, staticFlag);
        methodFinder.runAsUserTask();
        if (methodFinder.getMethodHandle() == null && SourceUtils.isScanInProgress()) {
            if (!ScanDialog.runWhenScanFinished(methodFinder, Bundle.JavaUtils_title_method_searching())) {
                return methodFinder.getMethodHandle();
            } else {
                return null;
            }
        } else {
            return methodFinder.getMethodHandle();
        }
    }

    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:JavaUtils.java

示例11: isPolymorphicSignature

import javax.lang.model.element.ExecutableElement; //导入依赖的package包/类
private static boolean isPolymorphicSignature(CompilationInfo info, TreePath path) {
    TypeElement polymorphicEl=  info.getElements().getTypeElement("java.lang.invoke.MethodHandle.PolymorphicSignature"); // NOI18N
    if (polymorphicEl == null) {
        // unsuitable platform
        return false;
    }
    TypeMirror polyType = polymorphicEl.asType();
    Element target = info.getTrees().getElement(path);
    if (target == null || target.getKind() != ElementKind.METHOD) {
        return false;
    }
    if (target.getEnclosingElement() == null || !target.getEnclosingElement().getKind().isClass()) {
        return false;
    }
    ExecutableElement ee = (ExecutableElement)target;
    TypeElement parent = (TypeElement)target.getEnclosingElement();
    if (!parent.getQualifiedName().toString().startsWith("java.lang.invoke.")) { // NOI18N
        return false;
    }
    for (AnnotationMirror am : ee.getAnnotationMirrors()) {
        if (info.getTypes().isSameType(polyType, am.getAnnotationType())) {
            return true;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:TooStrongCast.java

示例12: getLocalAndInheritedMethods

import javax.lang.model.element.ExecutableElement; //导入依赖的package包/类
private static void getLocalAndInheritedMethods(
        PackageElement pkg, TypeElement type, SetMultimap<String, ExecutableElement> methods) {

    for (TypeMirror superInterface : type.getInterfaces()) {
        getLocalAndInheritedMethods(pkg, MoreTypes.asTypeElement(superInterface), methods);
    }
    if (type.getSuperclass().getKind() != TypeKind.NONE) {
        // Visit the superclass after superinterfaces so we will always see the implementation of a
        // method after any interfaces that declared it.
        getLocalAndInheritedMethods(pkg, MoreTypes.asTypeElement(type.getSuperclass()), methods);
    }
    for (ExecutableElement method : ElementFilter.methodsIn(type.getEnclosedElements())) {
        if (!method.getModifiers().contains(Modifier.STATIC)
                && methodVisibleFromPackage(method, pkg)) {
            methods.put(method.getSimpleName().toString(), method);
        }
    }
}
 
开发者ID:foodora,项目名称:android-auto-mapper,代码行数:19,代码来源:MoreElements.java

示例13: BundlerClassInfo

import javax.lang.model.element.ExecutableElement; //导入依赖的package包/类
public BundlerClassInfo(TypeElement te) {
    typeElement = te;
    className = ClassName.get(typeElement);

    for (Element e : te.getEnclosedElements()) {
        if (e.getKind() == ElementKind.FIELD) {
            VariableElement ve = (VariableElement) e;
            fields.add(ve);
        }

        if (e.getKind() == ElementKind.METHOD) {
            ExecutableElement ee = (ExecutableElement) e;
            methods.add(ee);
        }
    }
}
 
开发者ID:google,项目名称:easybundler,代码行数:17,代码来源:BundlerClassInfo.java

示例14: jniMethodName

import javax.lang.model.element.ExecutableElement; //导入依赖的package包/类
protected final String jniMethodName(ExecutableElement method, String cname,
                                     boolean longName)
            throws TypeSignature.SignatureException {
    String res = "Java_" + cname + "_" + method.getSimpleName();

    if (longName) {
        TypeMirror mType =  types.erasure(method.getReturnType());
        List<? extends VariableElement> params = method.getParameters();
        List<TypeMirror> argTypes = new ArrayList<>();
        for (VariableElement param: params) {
            argTypes.add(types.erasure(param.asType()));
        }

        res = res + "__";
        for (TypeMirror t: argTypes) {
            String tname = t.toString();
            TypeSignature newTypeSig = new TypeSignature(elems);
            String sig = newTypeSig.getTypeSignature(tname);
            res = res + nameToIdentifier(sig);
        }
    }
    return res;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:LLNI.java

示例15: generateRequestManagerRequestBuilderMethodOverride

import javax.lang.model.element.ExecutableElement; //导入依赖的package包/类
/**
 * Generates overrides of existing RequestManager methods so that they return our generated
 * RequestBuilder subtype.
 */
private MethodSpec generateRequestManagerRequestBuilderMethodOverride(
    ExecutableElement methodToOverride) {
   // We've already verified that this method returns a RequestBuilder and RequestBuilders have
  // exactly one type argument, so this is safe unless those assumptions change.
  TypeMirror typeArgument =
      ((DeclaredType) methodToOverride.getReturnType()).getTypeArguments().get(0);

  ParameterizedTypeName generatedRequestBuilderOfType =
      ParameterizedTypeName.get(generatedRequestBuilderClassName, ClassName.get(typeArgument));

  MethodSpec.Builder builder = ProcessorUtil.overriding(methodToOverride)
      .returns(generatedRequestBuilderOfType)
      .addCode(
          ProcessorUtil.generateCastingSuperCall(
              generatedRequestBuilderOfType, methodToOverride));

  for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) {
    builder.addAnnotation(AnnotationSpec.get(mirror));
  }
  return builder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:RequestManagerGenerator.java


注:本文中的javax.lang.model.element.ExecutableElement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。