javax.lang.model.type.ArrayType Java Examples

The following examples show how to use javax.lang.model.type.ArrayType. 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: Constructor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private TypeDeclaration typeToTypeDeclaration(TypeMirror tMirror){
    int dimension = 0;
    TypeMirror aType =  tMirror;
    ITypeDeclaration[] generics = null;
    if(tMirror.getKind() == TypeKind.ARRAY){
        for(;aType.getKind() == TypeKind.ARRAY; aType =  ((ArrayType)tMirror).getComponentType()) {
            dimension++;
        }
    }
    if(aType.getKind() == TypeKind.DECLARED){
        DeclaredType dType = (DeclaredType) aType;
        List<? extends TypeMirror> parameters = dType.getTypeArguments();
        if( parameters!=null && parameters.size()>0){
            generics = new ITypeDeclaration[parameters.size()];
            int i=0;
            for(TypeMirror gType: parameters){
                generics[i] = typeToTypeDeclaration(gType);
                i++;
            }
        }
    }
    return new TypeDeclaration(owner, generics, dimension);
}
 
Example #2
Source File: PluginGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void appendSimpleTypeName(StringBuilder ret, TypeMirror type) {
    switch (type.getKind()) {
        case DECLARED:
            DeclaredType declared = (DeclaredType) type;
            TypeElement element = (TypeElement) declared.asElement();
            ret.append(element.getSimpleName());
            break;
        case TYPEVAR:
            appendSimpleTypeName(ret, ((TypeVariable) type).getUpperBound());
            break;
        case WILDCARD:
            appendSimpleTypeName(ret, ((WildcardType) type).getExtendsBound());
            break;
        case ARRAY:
            appendSimpleTypeName(ret, ((ArrayType) type).getComponentType());
            ret.append("Array");
            break;
        default:
            ret.append(type);
    }
}
 
Example #3
Source File: Environment.java    From sqlitemagic with Apache License 2.0 6 votes vote down vote up
public ExtendedTypeElement getSupportedSerializedTypeElement(TypeMirror typeMirror) {
  boolean isArrayElement = false;
  boolean isGenericElement = false;
  Dual<TypeElement, Boolean> typeElement = getTypeElement(typeMirror);
  if (typeElement == null) {
    if (typeMirror instanceof ArrayType) {
      ArrayType arrayType = (ArrayType) typeMirror;
      final TypeMirror arrayComponentType = arrayType.getComponentType();
      if (typeUtils.isSameType(arrayComponentType, Const.BYTE_TYPE)) {
        typeElement = getTypeElement(arrayComponentType);
        isArrayElement = true;
      } else {
        return ExtendedTypeElement.EMPTY;
      }
    } else {
      typeElement = Dual.create(getGenericTypeElement(typeMirror), false);
      isGenericElement = true;
    }
  }
  return new ExtendedTypeElement(typeElement, typeMirror, isArrayElement, isGenericElement);
}
 
Example #4
Source File: ConfigDoItemFinder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private String simpleTypeToString(TypeMirror typeMirror) {
    if (typeMirror.getKind().isPrimitive()) {
        return typeMirror.toString();
    } else if (typeMirror.getKind() == TypeKind.ARRAY) {
        return simpleTypeToString(((ArrayType) typeMirror).getComponentType());
    }

    final String knownGenericType = getKnownGenericType((DeclaredType) typeMirror);

    if (knownGenericType != null) {
        return knownGenericType;
    }

    List<? extends TypeMirror> typeArguments = ((DeclaredType) typeMirror).getTypeArguments();
    if (!typeArguments.isEmpty()) {
        return simpleTypeToString(typeArguments.get(0));
    }

    return typeMirror.toString();
}
 
Example #5
Source File: Marshallers.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public void addDeserializationCode(Context context)
    throws SerializationProcessingFailedException {
  Context repeated =
      context.with(
          ((ArrayType) context.type).getComponentType(), context.makeName("repeated"));
  String lengthName = context.makeName("length");
  context.builder.addStatement("int $L = codedIn.readInt32()", lengthName);

  String resultName = context.makeName("result");
  context.builder.addStatement(
      "$T[] $L = new $T[$L]",
      repeated.getTypeName(),
      resultName,
      repeated.getTypeName(),
      lengthName);
  String indexName = context.makeName("i");
  context.builder.beginControlFlow(
      "for (int $L = 0; $L < $L; ++$L)", indexName, indexName, lengthName, indexName);
  writeDeserializationCode(repeated);
  context.builder.addStatement("$L[$L] = $L", resultName, indexName, repeated.name);
  context.builder.endControlFlow();
  context.builder.addStatement("$L = $L", context.name, resultName);
}
 
Example #6
Source File: ApNavigator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public TypeMirror getComponentType(TypeMirror t) {
    if (isArray(t)) {
        ArrayType at = (ArrayType) t;
        return at.getComponentType();
    }

    throw new IllegalArgumentException();
}
 
Example #7
Source File: JniProcessor.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
TypeName toTypeName(TypeMirror t, boolean useJni) {
    if (t.getKind() == TypeKind.ARRAY) {
        return ArrayTypeName.of(toTypeName(((ArrayType) t).getComponentType(), useJni));
    }
    TypeName typeName = TypeName.get(t);
    if (useJni && shouldDowncastToObjectForJni(typeName)) {
        return TypeName.OBJECT;
    }
    return typeName;
}
 
Example #8
Source File: ApNavigator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public TypeMirror visitArray(ArrayType t, TypeElement typeElement) {
    // we are checking if t=T[] is assignable to sup.
    // the only case this is allowed is sup=Object,
    // and Object isn't parameterized.
    return null;
}
 
Example #9
Source File: MoreTypes.java    From auto with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean visitArray(ArrayType a, EqualVisitorParam p) {
  if (p.type.getKind().equals(ARRAY)) {
    ArrayType b = (ArrayType) p.type;
    return equal(a.getComponentType(), b.getComponentType(), p.visiting);
  }
  return false;
}
 
Example #10
Source File: JavaWsdlMapper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static String getTypeName(CompilationController controller, TypeMirror typeMirror) {
    TypeKind typeKind = typeMirror.getKind();
    switch (typeKind) {
        case BOOLEAN : return "boolean"; // NOI18N
        case BYTE : return "byte"; // NOI18N
        case CHAR : return "char"; // NOI18N
        case DOUBLE : return "double"; // NOI18N
        case FLOAT : return "float"; // NOI18N
        case INT : return "int"; // NOI18N
        case LONG : return "long"; // NOI18N
        case SHORT : return "short"; // NOI18N
        case VOID : return "void"; // NOI18N
        case ERROR :
        case DECLARED :
            if ( typeMirror instanceof DeclaredType ){
                Element element = controller.getTypes().asElement(typeMirror);
                return ((TypeElement) element).getSimpleName().toString();
            }
            else {
                break;
            }
        case ARRAY : 
            ArrayType arrayType = (ArrayType) typeMirror;
            Element componentTypeElement = controller.getTypes().asElement(arrayType.getComponentType());
            return ((TypeElement) componentTypeElement).getSimpleName().toString() + "[]";
        case EXECUTABLE :
        case NONE :
        case NULL :
        case OTHER :
        case PACKAGE :
        case TYPEVAR :
        case WILDCARD :
        default:break;
    }
    return null;
}
 
Example #11
Source File: MetadataWriter.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private Expression createContainerAnnotation(List<Annotation> annotations) {
  DeclaredType annotationType = annotations.get(0).getAnnotationMirror().getAnnotationType();
  ArrayType arrayType = typeUtil.getArrayType(annotationType);
  DeclaredType containerType = (DeclaredType) ElementUtil.getAnnotationValue(
      ElementUtil.getAnnotation(annotationType.asElement(), Repeatable.class), "value");
  TypeElement containerElement = (TypeElement) containerType.asElement();
  FunctionElement element = new FunctionElement(
      "create_" + nameTable.getFullName(containerElement), containerType, containerElement);
  FunctionInvocation invocation = new FunctionInvocation(element, containerType);
  element.addParameters(arrayType);
  List<Expression> array = annotations.stream().map(Annotation::getAnnotationMirror)
      .map(translationUtil::createAnnotation).collect(Collectors.toList());
  invocation.addArgument(translationUtil.createObjectArray(array, arrayType));
  return invocation;
}
 
Example #12
Source File: FxClassUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean isSimpleType(TypeMirror t, CompilationInfo ci) {
    if (isPrimitive(t)) {
        return true;
    }
    if (t.getKind() == TypeKind.DECLARED) {
        TypeElement tel = (TypeElement)ci.getTypes().asElement(t);
        if (findValueOf(tel, ci) != null) {
            return true;
        }

        // special hack, see BeanAdapter - Color and Paint class can be written as primitives:
        String qn = tel.getQualifiedName().toString();
        if (FX_COLOR_CLASS.equals(qn) || FX_PAINT_CLASS.equals(qn) || JL_STRING_CLASS.equals(qn)) {
            return true;
        }
    }
    
    // arrays
    if (t.getKind() == TypeKind.ARRAY) {
        TypeMirror component = ((ArrayType)t).getComponentType();
        if (component.getKind() == TypeKind.ARRAY) {
            // no support for 2-dim arrays
            return false;
        }
        return isSimpleType(component, ci);
    }
    return false;
}
 
Example #13
Source File: Names.java    From featured with Apache License 2.0 5 votes vote down vote up
public TypeName getTypeNameByKind(VariableElement param) {
    switch (param.asType().getKind()) {

        case BOOLEAN:
            return TypeName.BOOLEAN;
        case BYTE:
            return TypeName.BYTE;
        case CHAR:
            return TypeName.CHAR;
        case DOUBLE:
            return TypeName.DOUBLE;
        case FLOAT:
            return TypeName.FLOAT;
        case INT:
            return TypeName.INT;
        case LONG:
            return TypeName.LONG;
        case SHORT:
            return TypeName.SHORT;

        case DECLARED:
            TypeMirror type = param.asType();
            TypeName typeName = ClassName.get(type);
            typeName = applyAnnotations(typeName, param);
            return typeName;

        case ARRAY:
            ArrayType arrayType = (ArrayType) param.asType();
            TypeName arrayTypeName = ArrayTypeName.get(arrayType);
            arrayTypeName = applyAnnotations(arrayTypeName, param);
            return arrayTypeName;

        default:
            throw new IllegalStateException("unsupported kind: " + param.asType().getKind());
    }
}
 
Example #14
Source File: TypeResolverTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrimitiveArrayTypeResolves() throws IOException {
  compile("abstract class Foo extends java.util.ArrayList<int[]> { }");

  TypeElement fooElement = elements.getTypeElement("Foo");
  TypeElement listElement = elements.getTypeElement("java.util.ArrayList");
  TypeMirror intType = types.getPrimitiveType(TypeKind.INT);
  ArrayType intArrayType = types.getArrayType(intType);

  DeclaredType expectedSuperclass = types.getDeclaredType(listElement, intArrayType);

  assertSameType(expectedSuperclass, fooElement.getSuperclass());
}
 
Example #15
Source File: TypeMonikerFactory.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static TypeMoniker getTypeMoniker(TypeMirror typeMirror) {
    if (typeMirror == null)
        throw new NullPointerException();

    if (typeMirror.getKind().isPrimitive())
        return new PrimitiveTypeMoniker((PrimitiveType) typeMirror);
    else if (typeMirror.getKind().equals(TypeKind.ARRAY))
        return new ArrayTypeMoniker((ArrayType) typeMirror);
    else if (typeMirror.getKind().equals(TypeKind.DECLARED))
        return new DeclaredTypeMoniker((DeclaredType) typeMirror);
    return getTypeMoniker(typeMirror.toString());
}
 
Example #16
Source File: ElementUtilitiesEx.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String getRealTypeName(TypeMirror type, CompilationInfo ci) {
    final TypeMirror et = ci.getTypes().erasure(type);
    if (et.getKind() == TypeKind.DECLARED) {
        return ElementUtilities.getBinaryName((TypeElement)((DeclaredType)et).asElement());
    }
    if (et.getKind() == TypeKind.ARRAY) {
        return getRealTypeName(((ArrayType)et).getComponentType(), ci) + "[]";  // NOI18N
    }
    return et.toString();
}
 
Example #17
Source File: MoreTypes.java    From auto with Apache License 2.0 5 votes vote down vote up
@Override
public Integer visitArray(ArrayType t, Set<Element> visiting) {
  int result = hashKind(HASH_SEED, t);
  result *= HASH_MULTIPLIER;
  result += t.getComponentType().accept(this, visiting);
  return result;
}
 
Example #18
Source File: ArrayRewriter.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private MethodInvocation newMultiDimensionArrayInvocation(
    ArrayType arrayType, List<Expression> dimensions, boolean retainedResult) {
  assert dimensions.size() > 1;
  TypeMirror componentType = arrayType;
  for (int i = 0; i < dimensions.size(); i++) {
    assert TypeUtil.isArray(componentType);
    componentType = ((ArrayType) componentType).getComponentType();
  }
  TypeElement iosArrayElement = typeUtil.getIosArray(componentType);

  ExecutableElement methodElement =
      getMultiDimensionMethod(componentType, iosArrayElement, retainedResult);
  MethodInvocation invocation = new MethodInvocation(
      new ExecutablePair(methodElement), arrayType, new SimpleName(iosArrayElement));

  // Add the dimension count argument.
  invocation.addArgument(NumberLiteral.newIntLiteral(dimensions.size(), typeUtil));

  // Create the dimensions array.
  ArrayInitializer dimensionsArg = new ArrayInitializer(typeUtil.getArrayType(typeUtil.getInt()));
  for (Expression e : dimensions) {
    dimensionsArg.addExpression(e.copy());
  }
  invocation.addArgument(dimensionsArg);

  if (!componentType.getKind().isPrimitive()) {
    invocation.addArgument(new TypeLiteral(componentType, typeUtil));
  }

  return invocation;
}
 
Example #19
Source File: QueryReturnMeta.java    From doma with Apache License 2.0 5 votes vote down vote up
public boolean isPrimitiveIntArray() {
  return ctType
      .getType()
      .accept(
          new TypeKindVisitor8<Boolean, Void>(false) {

            @Override
            public Boolean visitArray(ArrayType t, Void p) {
              return t.getComponentType().getKind() == TypeKind.INT;
            }
          },
          null);
}
 
Example #20
Source File: ElementNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String createHtmlHeader(boolean deprecated, ExecutableElement e) {
    StringBuilder sb = new StringBuilder();
    sb.append("<html>");
    if (deprecated) sb.append("<s>");
    if (e.getKind() == ElementKind.CONSTRUCTOR) {
        sb.append(e.getEnclosingElement().getSimpleName());
    } else {
        sb.append(e.getSimpleName());
    }
    if (deprecated) sb.append("</s>");
    sb.append("("); // NOI18N
    for(Iterator<? extends VariableElement> it = e.getParameters().iterator(); it.hasNext(); ) {
        VariableElement param = it.next();
        if (!it.hasNext() && e.isVarArgs() && param.asType().getKind() == TypeKind.ARRAY) {
            sb.append(translateToHTML(print(((ArrayType) param.asType()).getComponentType())));
            sb.append("...");
        } else {
            sb.append(translateToHTML(print(param.asType())));
        }
        sb.append(" "); // NOI18N
        sb.append(param.getSimpleName());
        if (it.hasNext()) {
            sb.append(", "); // NOI18N
        }
    }
    sb.append(")"); // NOI18N
    if ( e.getKind() != ElementKind.CONSTRUCTOR ) {
        TypeMirror rt = e.getReturnType();
        if ( rt.getKind() != TypeKind.VOID ) {
            sb.append(" : "); // NOI18N
            sb.append(translateToHTML(print(e.getReturnType())));
        }
    }
    return sb.toString();
}
 
Example #21
Source File: JavadocHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void appendType(FragmentBuilder fb, TypeMirror type, boolean varArg) {
    switch (type.getKind()) {
    case ARRAY:
        appendType(fb, ((ArrayType) type).getComponentType(), false);
        fb.append(varArg ? "..." : "[]"); // NOI18N
        break;
    case DECLARED:
        fb.append(((TypeElement) ((DeclaredType) type).asElement()).getQualifiedName());
        break;
    default:
        fb.append(type.toString());
    }
}
 
Example #22
Source File: Bundler.java    From easybundler with Apache License 2.0 5 votes vote down vote up
/**
 * See {@link #matchesArrayClass(VariableElement, Class, MatchPolicy)}.
 */
private boolean matchesArrayClass(VariableElement field, String className, MatchPolicy policy) {
    // Check if the field is an array
    if (field.asType().getKind() != TypeKind.ARRAY) {
        return false;
    }

    // Get the type of array it is
    TypeMirror componentType = ((ArrayType) field.asType()).getComponentType();

    // Perform check
    TypeElement target = getTypeElementForClass(className);
    return target != null && typesMatch(componentType, target.asType(), policy);
}
 
Example #23
Source File: MoreTypes.java    From auto-parcel with Apache License 2.0 5 votes vote down vote up
@Override
public Integer visitArray(ArrayType t, Set<Element> visiting) {
    int result = hashKind(HASH_SEED, t);
    result *= HASH_MULTIPLIER;
    result += t.getComponentType().accept(this, visiting);
    return result;
}
 
Example #24
Source File: ArrayRewriter.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Override
public void endVisit(InstanceofExpression node) {
  TypeMirror type = node.getRightOperand().getTypeMirror();
  if (!TypeUtil.isArray(type) || ((ArrayType) type).getComponentType().getKind().isPrimitive()) {
    return;
  }
  GeneratedExecutableElement element = GeneratedExecutableElement.newMethodWithSelector(
      "isInstance", typeUtil.getBoolean(), TypeUtil.IOS_CLASS);
  element.addParameter(
      GeneratedVariableElement.newParameter("object", TypeUtil.ID_TYPE, element));
  MethodInvocation invocation =
      new MethodInvocation(new ExecutablePair(element), new TypeLiteral(type, typeUtil));
  invocation.addArgument(TreeUtil.remove(node.getLeftOperand()));
  node.replaceWith(invocation);
}
 
Example #25
Source File: CreateElementUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param info context {@link CompilationInfo}
 * @param iterable tested {@link TreePath}
 * @return generic type of an {@link Iterable} or {@link ArrayType} at a TreePath
 */
public static TypeMirror getIterableGenericType(CompilationInfo info, TreePath iterable) {
    TypeElement iterableElement = info.getElements().getTypeElement("java.lang.Iterable"); //NOI18N
    if (iterableElement == null) {
        return null;
    }
    TypeMirror iterableType = info.getTrees().getTypeMirror(iterable);
    if (iterableType == null) {
        return null;
    }
    TypeMirror designedType = null;
    if (iterableType.getKind() == TypeKind.DECLARED) {
        DeclaredType declaredType = (DeclaredType) iterableType;
        if (!info.getTypes().isSubtype(info.getTypes().erasure(declaredType), info.getTypes().erasure(iterableElement.asType()))) {
            return null;
        }
        ExecutableElement iteratorMethod = (ExecutableElement) iterableElement.getEnclosedElements().get(0);
        ExecutableType iteratorMethodType = (ExecutableType) info.getTypes().asMemberOf(declaredType, iteratorMethod);
        List<? extends TypeMirror> typeArguments = ((DeclaredType) iteratorMethodType.getReturnType()).getTypeArguments();
        if (!typeArguments.isEmpty()) {
            designedType = typeArguments.get(0);
        } else {
            TypeElement jlObject = info.getElements().getTypeElement("java.lang.Object");

            if (jlObject != null) {
                designedType = jlObject.asType();
            }
        }
    } else if (iterableType.getKind() == TypeKind.ARRAY) {
        designedType = ((ArrayType) iterableType).getComponentType();
    }
    if (designedType == null) {
        return null;
    }
    return JavaPluginUtils.resolveCapturedType(info, designedType);
}
 
Example #26
Source File: AutoValueOrOneOfProcessor.java    From auto with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that the return type of the given property method is allowed. Currently, this means that
 * it cannot be an array, unless it is a primitive array.
 */
final void checkReturnType(TypeElement autoValueClass, ExecutableElement getter) {
  TypeMirror type = getter.getReturnType();
  if (type.getKind() == TypeKind.ARRAY) {
    TypeMirror componentType = ((ArrayType) type).getComponentType();
    if (componentType.getKind().isPrimitive()) {
      warnAboutPrimitiveArrays(autoValueClass, getter);
    } else {
      errorReporter.reportError(
          getter,
          "An @%s class cannot define an array-valued property unless it is a primitive array",
          simpleAnnotationName);
    }
  }
}
 
Example #27
Source File: CompletionTestBase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public CI createArrayItem(CompilationInfo info, ArrayType type, int substitutionOffset, ReferencesCount referencesCount, Elements elements) {
    int dim = 0;
    TypeMirror tm = type;
    while(tm.getKind() == TypeKind.ARRAY) {
        tm = ((ArrayType)tm).getComponentType();
        dim++;
    }
    if (tm.getKind().isPrimitive()) {
        String kwd = tm.toString();
        StringBuilder sb = new StringBuilder(kwd);
        for(int i = 0; i < dim; i++) {
            sb.append("[]"); //NOI18N
        }
        return new CI(sb.toString(), 670 - SMART_TYPE, kwd);
    }
    if (tm.getKind() == TypeKind.DECLARED || tm.getKind() == TypeKind.ERROR) {
        DeclaredType dt = (DeclaredType)tm;
        TypeElement elem = (TypeElement)dt.asElement();
        String simpleName = elem.getSimpleName().toString();
        String fqn = elem.getQualifiedName().toString();
        int weight = 50;
        if (fqn.startsWith("java.lang") || fqn.startsWith("java.util")) { // NOI18N
            weight -= 10;
        } else if (fqn.startsWith("org.omg") || fqn.startsWith("org.apache")) { // NOI18N
            weight += 10;
        } else if (fqn.startsWith("com.sun") || fqn.startsWith("com.ibm") || fqn.startsWith("com.apple")) { // NOI18N
            weight += 20;
        } else if (fqn.startsWith("sun") || fqn.startsWith("sunw") || fqn.startsWith("netscape")) { // NOI18N
            weight += 30;
        }
        return new CI(simpleName, 800 - SMART_TYPE, referencesCount != null ? simpleName + '#' + weight + '#' + info.getElementUtilities().getElementName(elem.getEnclosingElement(), true) : simpleName);
    }
    throw new IllegalArgumentException("array element kind=" + tm.getKind());
}
 
Example #28
Source File: ArrayRewriter.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private MethodInvocation newInitializedArrayInvocation(
    ArrayType arrayType, List<Expression> elements, boolean retainedResult) {
  TypeMirror componentType = arrayType.getComponentType();
  TypeElement iosArrayElement = typeUtil.getIosArray(componentType);

  GeneratedExecutableElement methodElement = GeneratedExecutableElement.newMethodWithSelector(
      getInitializeSelector(componentType, retainedResult), iosArrayElement.asType(),
      iosArrayElement)
      .addModifiers(Modifier.PUBLIC, Modifier.STATIC);
  methodElement.addParameter(GeneratedVariableElement.newParameter(
      "values", new PointerType(componentType), methodElement));
  methodElement.addParameter(GeneratedVariableElement.newParameter(
      "count", typeUtil.getInt(), methodElement));
  if (!componentType.getKind().isPrimitive()) {
    methodElement.addParameter(GeneratedVariableElement.newParameter(
        "type", TypeUtil.IOS_CLASS.asType(), methodElement));
  }
  MethodInvocation invocation = new MethodInvocation(
      new ExecutablePair(methodElement), arrayType, new SimpleName(iosArrayElement));

  // Create the array initializer and add it as the first parameter.
  ArrayInitializer arrayInit = new ArrayInitializer(arrayType);
  for (Expression element : elements) {
    arrayInit.addExpression(element.copy());
  }
  invocation.addArgument(arrayInit);

  // Add the array size parameter.
  invocation.addArgument(
      NumberLiteral.newIntLiteral(arrayInit.getExpressions().size(), typeUtil));

  // Add the type argument for object arrays.
  if (!componentType.getKind().isPrimitive()) {
    invocation.addArgument(new TypeLiteral(componentType, typeUtil));
  }

  return invocation;
}
 
Example #29
Source File: ReturnTypeChanged.java    From revapi with Apache License 2.0 5 votes vote down vote up
private static boolean isPrimitiveOrVoid(TypeMirror type) {
    TypeKind kind = type.getKind();
    switch (kind) {
        case VOID:
            return true;
        case ARRAY:
            return isPrimitiveOrVoid(((ArrayType) type).getComponentType());
        default:
            return kind.isPrimitive();
    }
}
 
Example #30
Source File: Utilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public StringBuilder visitArray(ArrayType t, Boolean p) {
    boolean isVarArg = varArg;
    varArg = false;
    visit(t.getComponentType(), p);
    return DEFAULT_VALUE.append(isVarArg ? "..." : "[]"); //NOI18N
}