當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。