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


Java ExecutableElement.getThrownTypes方法代码示例

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


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

示例1: isThrowing

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
public static boolean isThrowing( CompilationInfo ci, ExecutableElement method, String name) {
    
    TypeElement ex = ci.getElements().getTypeElement(name);
    if ( ex == null ) {
        return false;
    }
    TypeMirror eType = ex.asType();

    for (TypeMirror t : method.getThrownTypes() ) {
        if ( ci.getTypes().isSubtype(t, eType) ) {
            return true;
        }
    }
    
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:BeanUtils.java

示例2: 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();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:PubapiVisitor.java

示例3: generateExceptionBeans

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private boolean generateExceptionBeans(ExecutableElement method) {
    String beanPackage = packageName + PD_JAXWS_PACKAGE_PD.getValue();
    if (packageName.length() == 0)
        beanPackage = JAXWS_PACKAGE_PD.getValue();
    boolean beanGenerated = false;
    for (TypeMirror thrownType : method.getThrownTypes()) {
        TypeElement typeDecl = (TypeElement) ((DeclaredType) thrownType).asElement();
        if (typeDecl == null) {
            builder.processError(WebserviceapMessages.WEBSERVICEAP_COULD_NOT_FIND_TYPEDECL(
                    thrownType.toString(), context.getRound()));
            return false;
        }
        boolean tmp = generateExceptionBean(typeDecl, beanPackage);
        beanGenerated = beanGenerated || tmp;
    }
    return beanGenerated;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:WebServiceWrapperGenerator.java

示例4: 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

示例5: 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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:ProcessorUtil.java

示例6: getExceptionsThrown

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
public static List<String> getExceptionsThrown(WorkingCopy workingCopy, String fqClass, String methodName, List<String> formalParamFqTypes) {
    if (formalParamFqTypes == null) {
        formalParamFqTypes = Collections.<String>emptyList();
    }
    ExecutableElement desiredMethodElement = null;
    TypeElement suppliedTypeElement = workingCopy.getElements().getTypeElement(fqClass);
    TypeElement typeElement = suppliedTypeElement;
    whileloop:
    while (typeElement != null) {
        for (ExecutableElement methodElement : ElementFilter.methodsIn(typeElement.getEnclosedElements())) {
            if (methodElement.getSimpleName().contentEquals(methodName)) {
                List<? extends VariableElement> formalParamElements = methodElement.getParameters();
                //for now, just check sizes
                if (formalParamElements.size() == formalParamFqTypes.size()) {
                    desiredMethodElement = methodElement;
                    break whileloop;
                }
            }
        }
        typeElement = getSuperclassTypeElement(typeElement);
    }
    if (desiredMethodElement == null) {
        throw new IllegalArgumentException("Could not find " + methodName + " in " + fqClass);
    }
    List<String> result = new ArrayList<String>();
    List<? extends TypeMirror> thrownTypes = desiredMethodElement.getThrownTypes();
    for (TypeMirror thrownType : thrownTypes) {
        if (thrownType.getKind() == TypeKind.DECLARED) {
            DeclaredType thrownDeclaredType = (DeclaredType)thrownType;
            TypeElement thrownElement = (TypeElement)thrownDeclaredType.asElement();
            String thrownFqClass = thrownElement.getQualifiedName().toString();
            result.add(thrownFqClass);
        }
        else {
            result.add(null);
        }
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:JpaControllerUtil.java

示例7: throwsNonRuntimeExceptions

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
 */
private static boolean throwsNonRuntimeExceptions(CompilationInfo compInfo,
                                                  ExecutableElement method) {
    List<? extends TypeMirror> thrownTypes = method.getThrownTypes();
    if (thrownTypes.isEmpty()) {
        return false;
    }

    String runtimeExcName = "java.lang.RuntimeException";           //NOI18N
    TypeElement runtimeExcElement = compInfo.getElements()
                                    .getTypeElement(runtimeExcName);
    if (runtimeExcElement == null) {
        Logger.getLogger("testng").log(                              //NOI18N
                Level.WARNING,
                "Could not find TypeElement for "                   //NOI18N
                        + runtimeExcName);
        return true;
    }

    Types types = compInfo.getTypes();
    TypeMirror runtimeExcType = runtimeExcElement.asType();
    for (TypeMirror exceptionType : thrownTypes) {
        if (!types.isSubtype(exceptionType, runtimeExcType)) {
            return true;
        }
    }

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

示例8: throwsNonRuntimeExceptions

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
 */
private static boolean throwsNonRuntimeExceptions(CompilationInfo compInfo,
                                                  ExecutableElement method) {
    List<? extends TypeMirror> thrownTypes = method.getThrownTypes();
    if (thrownTypes.isEmpty()) {
        return false;
    }

    String runtimeExcName = "java.lang.RuntimeException";           //NOI18N
    TypeElement runtimeExcElement = compInfo.getElements()
                                    .getTypeElement(runtimeExcName);
    if (runtimeExcElement == null) {
        Logger.getLogger("junit").log(                              //NOI18N
                Level.WARNING,
                "Could not find TypeElement for "                   //NOI18N
                        + runtimeExcName);
        return true;
    }

    Types types = compInfo.getTypes();
    TypeMirror runtimeExcType = runtimeExcElement.asType();
    for (TypeMirror exceptionType : thrownTypes) {
        if (!types.isSubtype(exceptionType, runtimeExcType)) {
            return true;
        }
    }

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

示例9: visitMethod

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
 * Method adds dependencies on its return type, and parameter types
 */
@Override
public Object visitMethod(MethodTree node, Object p) {
    ExecutableElement e = (ExecutableElement) info.getTrees().getElement(getCurrentPath());
    addDependency(e.getReturnType());
    // parameters will be captured by visit(VariableTree).
    for (TypeMirror tm : e.getThrownTypes()) {
        addDependency(tm);
    }
    return super.visitMethod(node, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:DependencyCollector.java

示例10: recordResumeOnExceptionHandler

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private void recordResumeOnExceptionHandler(ExecutableElement invoked) {
    for (TypeMirror tt : invoked.getThrownTypes()) {
        recordResumeOnExceptionHandler(tt);
    }

    recordResumeOnExceptionHandler("java.lang.RuntimeException");
    recordResumeOnExceptionHandler("java.lang.Error");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:NPECheck.java

示例11: recordResumeOnExceptionHandler

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private void recordResumeOnExceptionHandler(ExecutableElement invoked) {
            for (TypeMirror tt : invoked.getThrownTypes()) {
                recordResumeOnExceptionHandler(tt);
            }

//            recordResumeOnExceptionHandler(runtimeExceptionType);
//            recordResumeOnExceptionHandler(errorType);
        }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:Flow.java

示例12: createFinallyCloseBlockStatement

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private StatementTree createFinallyCloseBlockStatement(VariableTree origDeclaration) {
    Trees trees = info.getTrees();
    TypeMirror tm = trees.getTypeMirror(statement);
    ElementUtilities elUtils = info.getElementUtilities();
    Iterable iterable = elUtils.getMembers(tm, new ElementAcceptor() {
        public boolean accept(Element e, TypeMirror type) {
            return e.getKind() == ElementKind.METHOD && "close".equals(e.getSimpleName().toString()); // NOI18N
        }
    });
    boolean throwsIO = false;
    for (Iterator iter = iterable.iterator(); iter.hasNext(); ) {
        ExecutableElement elem = (ExecutableElement) iter.next();
        if (!elem.getParameters().isEmpty()) {
            continue;
        } else {
             for (TypeMirror typeMirror : elem.getThrownTypes()) {
                 if ("java.io.IOException".equals(typeMirror.toString())) { // NOI18N
                     throwsIO = true;
                     break;
                 }
             }
        }
    }
    
    CharSequence name = origDeclaration.getName();
    StatementTree close = make.ExpressionStatement(make.MethodInvocation(Collections.<ExpressionTree>emptyList(), make.MemberSelect(make.Identifier(name), "close"), Collections.<ExpressionTree>emptyList()));
    StatementTree result = close;
    if (throwsIO) {
        result = make.Try(make.Block(Collections.singletonList(close), false), Collections.singletonList(createCatch(info, make, statement, inferName(info, statement), info.getElements().getTypeElement("java.io.IOException").asType())), null);
        }
    
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:MagicSurroundWithTryCatchFix.java

示例13: printThrows

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private void printThrows(ExecutableElement e) {
    List<? extends TypeMirror> thrownTypes = e.getThrownTypes();
    final int size = thrownTypes.size();
    if (size != 0) {
        writer.print(" throws");

        int i = 1;
        for(TypeMirror thrownType: thrownTypes) {
            if (i == 1)
                writer.print(" ");

            if (i == 2)
                indentation++;

            if (i >= 2)
                indent();

            writer.print(thrownType);

            if (i != size)
                writer.println(", ");

            i++;
        }

        if (size >= 2)
            indentation--;
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:30,代码来源:PrintingProcessor.java

示例14: isValidOneWayMethod

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
protected boolean isValidOneWayMethod(ExecutableElement method, TypeElement typeElement) {
    boolean valid = true;
    if (!(method.getReturnType().accept(NO_TYPE_VISITOR, null))) {
        // this is an error, cannot be OneWay and have a return type
        builder.processError(WebserviceapMessages.WEBSERVICEAP_ONEWAY_OPERATION_CANNOT_HAVE_RETURN_TYPE(typeElement.getQualifiedName(), method.toString()), method);
        valid = false;
    }
    VariableElement outParam = getOutParameter(method);
    if (outParam != null) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_ONEWAY_AND_OUT(typeElement.getQualifiedName(), method.toString()), outParam);
        valid = false;
    }
    if (!isDocLitWrapped() && soapStyle.equals(SOAPStyle.DOCUMENT)) {
        int inCnt = getModeParameterCount(method, WebParam.Mode.IN);
        if (inCnt != 1) {
            builder.processError(WebserviceapMessages.WEBSERVICEAP_ONEWAY_AND_NOT_ONE_IN(typeElement.getQualifiedName(), method.toString()), method);
            valid = false;
        }
    }
    for (TypeMirror thrownType : method.getThrownTypes()) {
        TypeElement thrownElement = (TypeElement) ((DeclaredType) thrownType).asElement();
        if (builder.isServiceException(thrownType)) {
            builder.processError(WebserviceapMessages.WEBSERVICEAP_ONEWAY_OPERATION_CANNOT_DECLARE_EXCEPTIONS(
                    typeElement.getQualifiedName(), method.toString(), thrownElement.getQualifiedName()), method);
            valid = false;
        }
    }
    return valid;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:WebServiceVisitor.java

示例15: MethodEntity

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
public MethodEntity(ExecutableElement methodElement, Types typeMirror, Elements elementUtils) {
    this.methodElement = methodElement;
    this.returnType = methodElement.getReturnType().toString();
    this.parameterElements = methodElement.getParameters();
    this.isVarArgs = methodElement.isVarArgs();
    this.methodName = methodElement.getSimpleName().toString();
    this.exceptionTypes = methodElement.getThrownTypes();
    this.typeParameterElements = methodElement.getTypeParameters();
    this.classSimpleName = methodElement.getEnclosingElement().getSimpleName().toString();
    this.classQualifiedName = ((TypeElement) methodElement.getEnclosingElement()).getQualifiedName().toString();
    this.packageName = elementUtils.getPackageOf(methodElement).getQualifiedName().toString();
}
 
开发者ID:simplezhli,项目名称:RxPay,代码行数:13,代码来源:MethodEntity.java


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