Java Code Examples for javax.lang.model.type.TypeKind#VOID

The following examples show how to use javax.lang.model.type.TypeKind#VOID . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RetroFacebookProcessor.java    From RetroFacebook with Apache License 2.0 6 votes vote down vote up
private ImmutableSet<ExecutableElement> methodsToImplement(List<ExecutableElement> methods) {
  ImmutableSet.Builder<ExecutableElement> toImplement = ImmutableSet.builder();
  boolean errors = false;
  for (ExecutableElement method : methods) {
    if (method.getModifiers().contains(Modifier.ABSTRACT)
        && objectMethodToOverride(method) == ObjectMethodToOverride.NONE) {
      if (method.getParameters().isEmpty() && method.getReturnType().getKind() != TypeKind.VOID) {
        if (isReferenceArrayType(method.getReturnType())) {
          errorReporter.reportError("An @RetroFacebook class cannot define an array-valued property"
              + " unless it is a primitive array", method);
          errors = true;
        }
        toImplement.add(method);
      } else {
        toImplement.add(method);
      }
    }
  }
  if (errors) {
    throw new AbortProcessingException();
  }
  return toImplement.build();
}
 
Example 2
Source File: ElementUtil.java    From j2objc with Apache License 2.0 6 votes vote down vote up
private static boolean hasNullabilityAnnotation(Element element, Pattern pattern) {
  // Ignore nullability annotation on primitive or void return types.
  if (isMethod(element)) {
    TypeKind kind = ((ExecutableElement) element).getReturnType().getKind();
    if (kind.isPrimitive() || kind == TypeKind.VOID) {
      return false;
    }
  }
  if (isVariable(element) && element.asType().getKind().isPrimitive()) {
    return false;
  }
  // The two if statements cover type annotations.
  if (isMethod(element)
      && hasNamedAnnotation(((ExecutableElement) element).getReturnType(), pattern)) {
    return true;
  }
  if (isVariable(element) && hasNamedAnnotation(element.asType(), pattern)) {
    return true;
  }
  // This covers declaration annotations.
  return hasNamedAnnotation(element, pattern);
}
 
Example 3
Source File: RetroFacebookProcessor.java    From RetroFacebook with Apache License 2.0 6 votes vote down vote up
private ImmutableSet<ExecutableElement> methodsToImplement(List<ExecutableElement> methods) {
  ImmutableSet.Builder<ExecutableElement> toImplement = ImmutableSet.builder();
  boolean errors = false;
  for (ExecutableElement method : methods) {
    if (method.getModifiers().contains(Modifier.ABSTRACT)
        && objectMethodToOverride(method) == ObjectMethodToOverride.NONE) {
      if (method.getParameters().isEmpty() && method.getReturnType().getKind() != TypeKind.VOID) {
        if (isReferenceArrayType(method.getReturnType())) {
          errorReporter.reportError("An @RetroFacebook class cannot define an array-valued property"
              + " unless it is a primitive array", method);
          errors = true;
        }
        toImplement.add(method);
      } else {
        toImplement.add(method);
      }
    }
  }
  if (errors) {
    throw new AbortProcessingException();
  }
  return toImplement.build();
}
 
Example 4
Source File: GetterFactory.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
private static Optional<String> inferName(ExecutableElement element) {
  Encodable.Field annotation = element.getAnnotation(Encodable.Field.class);
  if (annotation != null && !annotation.name().isEmpty()) {
    return Optional.of(annotation.name());
  }

  String methodName = element.getSimpleName().toString();
  ExecutableType method = (ExecutableType) element.asType();

  if (methodName.startsWith("is")
      && methodName.length() != 2
      && method.getReturnType().getKind() == TypeKind.BOOLEAN) {
    return Optional.of(Character.toLowerCase(methodName.charAt(2)) + methodName.substring(3));
  }

  if (methodName.startsWith("get")
      && methodName.length() != 3
      && method.getReturnType().getKind() != TypeKind.VOID) {
    return Optional.of(Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4));
  }
  return Optional.empty();
}
 
Example 5
Source File: TypeTag.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public TypeKind getPrimitiveTypeKind() {
    switch (this) {
    case BOOLEAN:
        return TypeKind.BOOLEAN;
    case BYTE:
        return TypeKind.BYTE;
    case SHORT:
        return TypeKind.SHORT;
    case INT:
        return TypeKind.INT;
    case LONG:
        return TypeKind.LONG;
    case CHAR:
        return TypeKind.CHAR;
    case FLOAT:
        return TypeKind.FLOAT;
    case DOUBLE:
        return TypeKind.DOUBLE;
    case VOID:
        return TypeKind.VOID;
    default:
        throw new AssertionError("unknown primitive type " + this);
    }
}
 
Example 6
Source File: EntityType.java    From requery with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<TypeMirror> builderType() {
    Optional<Entity> entityAnnotation = annotationOf(Entity.class);
    if (entityAnnotation.isPresent()) {
        Entity entity = entityAnnotation.get();
        Elements elements = processingEnvironment.getElementUtils();
        TypeMirror mirror = null;
        try {
            Class<?> builderClass = entity.builder(); // easiest way to get the class TypeMirror
            if (builderClass != void.class) {
                mirror = elements.getTypeElement(builderClass.getName()).asType();
            }
        } catch (MirroredTypeException typeException) {
            mirror = typeException.getTypeMirror();
        }
        if (mirror != null && mirror.getKind() != TypeKind.VOID) {
            return Optional.of(mirror);
        }
    }
    if (builderFactoryMethod().isPresent()) {
        return Optional.of(builderFactoryMethod().get().getReturnType());
    }
    return ElementFilter.typesIn(element().getEnclosedElements()).stream()
            .filter(element -> element.getSimpleName().toString().contains("Builder"))
            .map(Element::asType)
            .filter(Objects::nonNull)
            .filter(type -> type.getKind() != TypeKind.VOID)
            .findFirst();
}
 
Example 7
Source File: NullAway.java    From NullAway with MIT License 5 votes vote down vote up
@Override
public Description matchLambdaExpression(LambdaExpressionTree tree, VisitorState state) {
  if (!matchWithinClass) {
    return Description.NO_MATCH;
  }
  Symbol.MethodSymbol funcInterfaceMethod =
      NullabilityUtil.getFunctionalInterfaceMethod(tree, state.getTypes());
  // we need to update environment mapping before running the handler, as some handlers
  // (like Rx nullability) run dataflow analysis
  updateEnvironmentMapping(tree, state);
  handler.onMatchLambdaExpression(this, tree, state, funcInterfaceMethod);
  if (NullabilityUtil.isUnannotated(funcInterfaceMethod, config)) {
    return Description.NO_MATCH;
  }
  Description description =
      checkParamOverriding(
          tree.getParameters().stream().map(ASTHelpers::getSymbol).collect(Collectors.toList()),
          funcInterfaceMethod,
          tree,
          null,
          state);
  if (description != Description.NO_MATCH) {
    return description;
  }
  // if the body has a return statement, that gets checked in matchReturn().  We need this code
  // for lambdas with expression bodies
  if (tree.getBodyKind() == LambdaExpressionTree.BodyKind.EXPRESSION
      && funcInterfaceMethod.getReturnType().getKind() != TypeKind.VOID) {
    ExpressionTree resExpr = (ExpressionTree) tree.getBody();
    return checkReturnExpression(tree, resExpr, funcInterfaceMethod, state);
  }
  return Description.NO_MATCH;
}
 
Example 8
Source File: AbstractTestGenerator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a simple implementation of an abstract method declared
 * in a supertype.
 *
 * @param abstractMethod  the method whose implementation is to be generated
 */
private static MethodTree generateAbstractMethodImpl(
                                        ExecutableElement abstractMethod,
                                        WorkingCopy workingCopy) {
    final TreeMaker maker = workingCopy.getTreeMaker();

    TypeMirror returnType = abstractMethod.getReturnType();
    List<? extends StatementTree> content;
    if (returnType.getKind() == TypeKind.VOID) {
        content = Collections.<StatementTree>emptyList();
    } else {
        content = Collections.singletonList(
                        maker.Return(getDefaultValue(maker, returnType)));
    }
    BlockTree body = maker.Block(content, false);

    return maker.Method(
            maker.Modifiers(Collections.singleton(PUBLIC)),
            abstractMethod.getSimpleName(),
            maker.Type(returnType),
            makeTypeParamsCopy(abstractMethod.getTypeParameters(), maker),
            makeParamsCopy(abstractMethod.getParameters(), maker),
            makeDeclaredTypesCopy((List<? extends DeclaredType>)
                                          abstractMethod.getThrownTypes(),
                                  maker),
            body,
            null);
}
 
Example 9
Source File: Analyzer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
@NbBundle.Messages({"WRONG_RETURN_DESC=@return tag cannot be used in method with void return type.",
                    "WRONG_CONSTRUCTOR_RETURN_DESC=Illegal @return tag.",
                    "DUPLICATE_RETURN_DESC=Duplicate @return tag."})
public Void visitReturn(ReturnTree node, List<ErrorDescription> errors) {
    boolean oldInheritDoc = foundInheritDoc;
    DocTreePath currentDocPath = getCurrentPath();
    DocTreePathHandle dtph = DocTreePathHandle.create(currentDocPath, javac);
    if(dtph == null) {
        return null;
    }
    DocSourcePositions sp = (DocSourcePositions) javac.getTrees().getSourcePositions();
    int start = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), node);
    int end = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), node);
    if(returnType == null) {
        errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, WRONG_CONSTRUCTOR_RETURN_DESC(),
                new RemoveTagFix(dtph, "@return").toEditorFix()));
    } else if (returnType.getKind() == TypeKind.VOID) {
        errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, WRONG_RETURN_DESC(),
                new RemoveTagFix(dtph, "@return").toEditorFix()));
    } else if(returnTypeFound) {
        errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, DUPLICATE_RETURN_DESC(),
                new RemoveTagFix(dtph, "@return").toEditorFix()));
    } else {
        returnTypeFound = true;
    }
    super.visitReturn(node, errors);
    foundInheritDoc = oldInheritDoc;
    return null;
}
 
Example 10
Source File: MethodModelSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Tree getTypeTree(WorkingCopy workingCopy, String typeName) {
    TreeMaker make = workingCopy.getTreeMaker();
    TypeKind primitiveTypeKind = null;
    if ("boolean".equals(typeName)) {           // NOI18N
        primitiveTypeKind = TypeKind.BOOLEAN;
    } else if ("byte".equals(typeName)) {       // NOI18N
        primitiveTypeKind = TypeKind.BYTE;
    } else if ("short".equals(typeName)) {      // NOI18N
        primitiveTypeKind = TypeKind.SHORT;
    } else if ("int".equals(typeName)) {        // NOI18N
        primitiveTypeKind = TypeKind.INT;
    } else if ("long".equals(typeName)) {       // NOI18N
        primitiveTypeKind = TypeKind.LONG;
    } else if ("char".equals(typeName)) {       // NOI18N
        primitiveTypeKind = TypeKind.CHAR;
    } else if ("float".equals(typeName)) {      // NOI18N
        primitiveTypeKind = TypeKind.FLOAT;
    } else if ("double".equals(typeName)) {     // NOI18N
        primitiveTypeKind = TypeKind.DOUBLE;
    } else if ("void".equals(typeName)) {     // NOI18N
        primitiveTypeKind = TypeKind.VOID;
    }
    if (primitiveTypeKind != null) {
        return make.PrimitiveType(primitiveTypeKind);
    } else {
        return createQualIdent(workingCopy, typeName);
    }
}
 
Example 11
Source File: MoreTypes.java    From doma with Apache License 2.0 5 votes vote down vote up
public boolean isAssignableWithErasure(TypeMirror lhs, TypeMirror rhs) {
  assertNotNull(lhs, rhs);
  if (lhs.getKind() == TypeKind.NONE || rhs.getKind() == TypeKind.NONE) {
    return false;
  }
  if (lhs.getKind() == TypeKind.NULL) {
    return rhs.getKind() == TypeKind.NULL;
  }
  if (rhs.getKind() == TypeKind.NULL) {
    return lhs.getKind() == TypeKind.NULL;
  }
  if (lhs.getKind() == TypeKind.VOID) {
    return rhs.getKind() == TypeKind.VOID;
  }
  if (rhs.getKind() == TypeKind.VOID) {
    return lhs.getKind() == TypeKind.VOID;
  }
  TypeMirror t1 = typeUtils.erasure(lhs);
  TypeMirror t2 = typeUtils.erasure(rhs);
  if (typeUtils.isSameType(t1, t2) || t1.equals(t2)) {
    return true;
  }
  for (TypeMirror supertype : typeUtils.directSupertypes(t1)) {
    if (isAssignableWithErasure(supertype, t2)) {
      return true;
    }
  }
  return false;
}
 
Example 12
Source File: SqlProcessorQueryMetaFactory.java    From doma with Apache License 2.0 5 votes vote down vote up
private boolean isConvertibleReturnType(QueryReturnMeta returnMeta, CtType resultCtType) {
  if (ctx.getMoreTypes().isSameTypeWithErasure(returnMeta.getType(), resultCtType.getType())) {
    return true;
  }
  if (returnMeta.getType().getKind() == TypeKind.VOID) {
    return ctx.getMoreTypes().isSameTypeWithErasure(resultCtType.getType(), Void.class);
  }
  return false;
}
 
Example 13
Source File: JVMNames.java    From annotation-tools with MIT License 5 votes vote down vote up
/**
 * Create a JVML string for a type.
 * Uses {@link Signatures#binaryNameToFieldDescriptor(String)}
 *
 * Array strings are built by recursively converting the component type.
 *
 * @param type the Type to convert to JVML
 * @return the JVML representation of type
 */
@SuppressWarnings("signature") // com.sun.tools.javac.code is not yet annotated
public static String typeToJvmlString(Type type) {
    if (type.getKind() == TypeKind.ARRAY) {
        return "[" + typeToJvmlString((Type) ((ArrayType) type).getComponentType());
    } else if (type.getKind() == TypeKind.INTERSECTION) {
        // replace w/erasure (== erasure of 1st conjunct)
        return typeToJvmlString(type.tsym.erasure_field);
    } else if (type.getKind() == TypeKind.VOID) {
        return "V";  // special case since UtilPlume doesn't handle void
    } else {
        return Signatures.binaryNameToFieldDescriptor(type.tsym.flatName().toString());
    }
}
 
Example 14
Source File: ConfiguredObjectFactoryGenerator.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
private void processDoOnConfigMethod(final PrintWriter pw, final String className, final ExecutableElement methodElement, final AnnotationMirror annotationMirror)
{
    pw.println("    @Override");
    pw.print("    public " + methodElement.getReturnType() + " " + methodElement.getSimpleName().toString() + "(");
    boolean first = true;
    for(VariableElement param : methodElement.getParameters())
    {
        if(first)
        {
            first = false;
        }
        else
        {
            pw.print(", ");
        }
        pw.print("final ");
        pw.print(param.asType());
        pw.print(" ");

        pw.print(getParamName(param));
    }
    pw.println(")");
    final List<? extends TypeMirror> thrownTypes = methodElement.getThrownTypes();
    if (!thrownTypes.isEmpty())
    {
        pw.println(thrownTypes.stream().map(TypeMirror::toString).collect(Collectors.joining(" , ", "    throws ", "")));
    }
    pw.println("    {");


    final String parameterList = getParameterList(methodElement);

    final String callToSuper = "super." + methodElement.getSimpleName().toString() + parameterList;

    pw.print("        ");
    if (methodElement.getReturnType().getKind() != TypeKind.VOID)
    {
        pw.print("return ");
    }
    pw.println(wrapByDoOnConfigThread(callToSuper, className, methodElement));


    pw.println("    }");
    pw.println();
}
 
Example 15
Source File: PropDefaultsExtractor.java    From litho with Apache License 2.0 4 votes vote down vote up
/**
 * This attempts to extract a prop-default from a <em>method</em>. This is only necessary for
 * Kotlin KAPT generated code, which currently does a rather strange thing where it generates a
 * method <code>void field_name$annotations()</code> for every <code>field_name</code> that has
 * all annotations for said field.
 *
 * <p>So, if we find a method that looks like this, and it contains a <code>PropDefault</code>
 * annotation, we will try to find a matching field of this name and add use it as basis for our
 * prop-default.
 */
private static ImmutableList<PropDefaultModel> extractFromMethod(Element enclosedElement) {
  if (enclosedElement.getKind() != ElementKind.METHOD) {
    return ImmutableList.of();
  }

  final ExecutableElement methodElement = (ExecutableElement) enclosedElement;

  final Annotation propDefaultAnnotation = methodElement.getAnnotation(PropDefault.class);
  if (propDefaultAnnotation == null) {
    return ImmutableList.of();
  }

  final String methodName = methodElement.getSimpleName().toString();

  boolean isPropDefaultWithoutGet =
      methodName.endsWith("$annotations")
          && methodElement.getReturnType().getKind() == TypeKind.VOID;

  final String baseName;

  /*
   * In case an [@PropDefault] annotated variable does not include `get` on the Kotlin
   * annotation, we fallback to the previous method of identifying `PropDefault` values.
   * Note here that this method is deprecated and might be removed from KAPT some time in
   * future.
   *
   * If a user annotates that variable with `@get:PropDefault` we identify the
   * `PropDefault` values through the accompanying `get` method of that variable.
   * */
  if (isPropDefaultWithoutGet) {
    baseName = methodName.subSequence(0, methodName.indexOf('$')).toString();
  } else {
    baseName =
        methodName.replaceFirst("get", "").substring(0, 1).toLowerCase()
            + methodName.replaceFirst("get", "").substring(1);
  }

  final Optional<? extends Element> element =
      enclosedElement.getEnclosingElement().getEnclosedElements().stream()
          .filter(e -> e.getSimpleName().toString().equals(baseName))
          .findFirst();

  final ResType propDefaultResType = ((PropDefault) propDefaultAnnotation).resType();
  final int propDefaultResId = ((PropDefault) propDefaultAnnotation).resId();

  return element
      .map(
          e ->
              ImmutableList.of(
                  new PropDefaultModel(
                      TypeName.get(e.asType()),
                      baseName,
                      ImmutableList.copyOf(new ArrayList<>(methodElement.getModifiers())),
                      methodElement,
                      propDefaultResType,
                      propDefaultResId)))
      .orElseGet(ImmutableList::of);
}
 
Example 16
Source File: IntroduceMethodFix.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Resolves the handles, returns false if some handle does not resolve.
 */
private boolean resolveAndInitialize() {
    firstStatement = handle.resolve(copy);
    returnType = IntroduceMethodFix.this.returnType.resolve(copy);
    if (firstStatement == null || returnType == null) {
        return false;
    }
    parameters = IntroduceHint.resolveVariables(copy, IntroduceMethodFix.this.parameters);
    if (IntroduceMethodFix.this.returnAssignTo != null) {
        outcomeVariable = (VariableElement) IntroduceMethodFix.this.returnAssignTo.resolveElement(copy);
        if (outcomeVariable == null) {
            return false;
        }
    }
    if (exits != null && !exits.isEmpty()) {
        branchExit = exits.iterator().next().resolve(copy);
        if (branchExit == null) {
            return false;
        }
        resolvedExits = new ArrayList<TreePath>(exits.size());
        for (TreePathHandle h : exits) {
            TreePath resolved = h.resolve(copy);
            if (resolved == null) {
                return false;
            }
            if (resolvedExits.isEmpty()) {
                branchExit = resolved;
            }
            resolvedExits.add(resolved);
        }
        
        returnSingleValue = exitsFromAllBranches && branchExit.getLeaf().getKind() == Tree.Kind.RETURN && outcomeVariable == null && returnType.getKind() != TypeKind.VOID;
    }
    // initialization
    make = copy.getTreeMaker();
    returnTypeTree = make.Type(returnType);
    statementPaths = Utilities.getStatementPaths(firstStatement);
    statements = IntroduceHint.getStatements(firstStatement);
    GeneratorUtilities.get(copy).importComments(firstStatement.getParentPath().getLeaf(), copy.getCompilationUnit());
    return true;
}
 
Example 17
Source File: DaoImplQueryMethodGenerator.java    From doma with Apache License 2.0 4 votes vote down vote up
@Override
public Void visitSqlFileSelectQueryMeta(final SqlFileSelectQueryMeta m) {
  printEnteringStatements(m);
  printPrerequisiteStatements(m);

  iprint(
      "%1$s __query = __support.getQueryImplementors().create%2$s(%3$s);%n",
      m.getQueryClass().getName(), m.getQueryClass().getSimpleName(), methodName);
  iprint("__query.setMethod(%1$s);%n", methodName);
  iprint("__query.setConfig(__support.getConfig());%n");
  iprint("__query.setSqlFilePath(\"%1$s\");%n", m.getPath());
  if (m.getSelectOptionsCtType() != null) {
    iprint("__query.setOptions(%1$s);%n", m.getSelectOptionsParameterName());
  }
  if (m.getEntityCtType() != null) {
    iprint("__query.setEntityType(%1$s);%n", m.getEntityCtType().getTypeCode());
  }

  printAddParameterStatements(m.getParameterMetas());

  iprint("__query.setCallerClassName(\"%1$s\");%n", className);
  iprint("__query.setCallerMethodName(\"%1$s\");%n", m.getName());
  iprint("__query.setResultEnsured(%1$s);%n", m.getEnsureResult());
  iprint("__query.setResultMappingEnsured(%1$s);%n", m.getEnsureResultMapping());
  if (m.getSelectStrategyType() == SelectType.RETURN) {
    iprint("__query.setFetchType(%1$s.%2$s);%n", FetchType.class, FetchType.LAZY);
  } else {
    iprint("__query.setFetchType(%1$s.%2$s);%n", FetchType.class, m.getFetchType());
  }
  iprint("__query.setQueryTimeout(%1$s);%n", m.getQueryTimeout());
  iprint("__query.setMaxRows(%1$s);%n", m.getMaxRows());
  iprint("__query.setFetchSize(%1$s);%n", m.getFetchSize());
  iprint("__query.setSqlLogType(%1$s.%2$s);%n", m.getSqlLogType().getClass(), m.getSqlLogType());
  if (m.isResultStream()) {
    iprint("__query.setResultStream(true);%n");
  }
  iprint("__query.prepare();%n");

  QueryReturnMeta returnMeta = m.getReturnMeta();

  if (m.getSelectStrategyType() == SelectType.RETURN) {
    CtType returnCtType = returnMeta.getCtType();
    returnCtType.accept(new SqlFileSelectQueryReturnCtTypeVisitor(m), false);
    iprint("%1$s __result = __command.execute();%n", returnMeta.getType());
    iprint("__query.complete();%n");
    iprint("__support.exiting(\"%1$s\", \"%2$s\", __result);%n", className, m.getName());
    iprint("return __result;%n");
  } else {
    if (m.getSelectStrategyType() == SelectType.STREAM) {
      FunctionCtType functionCtType = m.getFunctionCtType();
      functionCtType
          .getTargetCtType()
          .accept(new SqlFileSelectQueryFunctionCtTypeVisitor(m), null);
    } else if (m.getSelectStrategyType() == SelectType.COLLECT) {
      CollectorCtType collectorCtType = m.getCollectorCtType();
      collectorCtType
          .getTargetCtType()
          .accept(new SqlFileSelectQueryCollectorCtTypeVisitor(m), false);
    }
    if (returnMeta.getType().getKind() == TypeKind.VOID) {
      iprint("__command.execute();%n");
      iprint("__query.complete();%n");
      iprint("__support.exiting(\"%1$s\", \"%2$s\", null);%n", className, m.getName());
    } else {
      iprint("%1$s __result = __command.execute();%n", returnMeta.getType());
      iprint("__query.complete();%n");
      iprint("__support.exiting(\"%1$s\", \"%2$s\", __result);%n", className, m.getName());
      iprint("return __result;%n");
    }
  }

  printThrowingStatements(m);
  return null;
}
 
Example 18
Source File: JavaEnvironment.java    From j2cl with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a type descriptor for the given TypeMirror, taking into account nullability.
 *
 * @param typeMirror the type provided by javac, used to create the type descriptor.
 * @param elementAnnotations the annotations on the element
 */
private TypeDescriptor createTypeDescriptorWithNullability(
    TypeMirror typeMirror, List<? extends AnnotationMirror> elementAnnotations) {
  if (typeMirror == null || typeMirror.getKind() == TypeKind.NONE) {
    return null;
  }

  if (typeMirror.getKind().isPrimitive() || typeMirror.getKind() == TypeKind.VOID) {
    return PrimitiveTypes.get(asElement(typeMirror).getSimpleName().toString());
  }

  if (typeMirror.getKind() == TypeKind.INTERSECTION) {
    return createIntersectionType((IntersectionClassType) typeMirror);
  }

  if (typeMirror.getKind() == TypeKind.UNION) {
    return createUnionType((UnionClassType) typeMirror);
  }

  if (typeMirror.getKind() == TypeKind.NULL) {
    return TypeDescriptors.get().javaLangObject;
  }

  if (typeMirror.getKind() == TypeKind.TYPEVAR) {
    return createTypeVariable((javax.lang.model.type.TypeVariable) typeMirror);
  }

  if (typeMirror.getKind() == TypeKind.WILDCARD) {
    return createWildcardTypeVariable(
        ((javax.lang.model.type.WildcardType) typeMirror).getExtendsBound());
  }

  boolean isNullable = isNullable(typeMirror, elementAnnotations);
  if (typeMirror.getKind() == TypeKind.ARRAY) {
    ArrayType arrayType = (ArrayType) typeMirror;
    TypeDescriptor componentTypeDescriptor = createTypeDescriptor(arrayType.getComponentType());
    return ArrayTypeDescriptor.newBuilder()
        .setComponentTypeDescriptor(componentTypeDescriptor)
        .setNullable(isNullable)
        .build();
  }

  return withNullability(createDeclaredType((ClassType) typeMirror), isNullable);
}
 
Example 19
Source File: GeneratedNodeIntrinsicPlugin.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void extraImports(Set<String> imports) {
    if (intrinsicMethod.getReturnType().getKind() != TypeKind.VOID) {
        imports.add("jdk.vm.ci.meta.JavaKind");
    }
}
 
Example 20
Source File: TurbineTypeMirror.java    From turbine with Apache License 2.0 4 votes vote down vote up
@Override
public TypeKind getKind() {
  return TypeKind.VOID;
}