@Override public boolean isPrimitive() { if (type.isArrayType()) { return ((ArrayType) type).getElementType().isPrimitiveType(); } return type.isPrimitiveType(); }
@Override public boolean isPrimitive() { if (type.isArrayType()) { return ((ArrayType) type).getComponentType().isPrimitiveType(); } return type.isPrimitiveType(); }
private boolean isSupportedConstantType(Type type) { return type.isPrimitiveType() || type.resolveBinding().getQualifiedName().equals(String.class.getCanonicalName()); }
public boolean isBooleanType(final Expression expression) { if ((expression instanceof BooleanLiteral)) { return true; } if ((expression instanceof SimpleName)) { final Type declType = this._aSTFlattenerUtils.findDeclaredType(((SimpleName)expression)); if ((declType != null)) { boolean _matched = false; boolean _isPrimitiveType = declType.isPrimitiveType(); if (_isPrimitiveType) { _matched=true; PrimitiveType.Code _primitiveTypeCode = ((PrimitiveType) declType).getPrimitiveTypeCode(); return Objects.equal(_primitiveTypeCode, PrimitiveType.BOOLEAN); } } } return false; }
private static boolean isVoidArrayType(Type type){ if (! type.isArrayType()) return false; ArrayType arrayType= (ArrayType)type; if (! arrayType.getElementType().isPrimitiveType()) return false; PrimitiveType primitiveType= (PrimitiveType) arrayType.getElementType(); return (primitiveType.getPrimitiveTypeCode() == PrimitiveType.VOID); }
private static boolean isVoidArrayType(Type type){ if (! type.isArrayType()) return false; ArrayType arrayType= (ArrayType)type; if (! arrayType.getElementType().isPrimitiveType()) return false; PrimitiveType primitiveType= (PrimitiveType) arrayType.getElementType(); return (primitiveType.getPrimitiveTypeCode() == PrimitiveType.VOID); }
private static boolean isVoidArrayType(Type type){ if (! type.isArrayType()) return false; ArrayType arrayType= (ArrayType)type; if (! arrayType.getComponentType().isPrimitiveType()) return false; PrimitiveType primitiveType= (PrimitiveType)arrayType.getComponentType(); return (primitiveType.getPrimitiveTypeCode() == PrimitiveType.VOID); }
/** * Returns an expression that is assignable to the given type. <code>null</code> is * returned if the type is the 'void' type. * * @param ast The AST to create the expression for * @param type The type of the returned expression * @param extraDimensions Extra dimensions to the type * @return the Null-literal for reference types, a boolean-literal for a boolean type, a number * literal for primitive types or <code>null</code> if the type is void. */ public static Expression newDefaultExpression(AST ast, Type type, int extraDimensions) { if (extraDimensions == 0 && type.isPrimitiveType()) { PrimitiveType primitiveType= (PrimitiveType) type; if (primitiveType.getPrimitiveTypeCode() == PrimitiveType.BOOLEAN) { return ast.newBooleanLiteral(false); } else if (primitiveType.getPrimitiveTypeCode() == PrimitiveType.VOID) { return null; } else { return ast.newNumberLiteral("0"); //$NON-NLS-1$ } } return ast.newNullLiteral(); }
/** * Returns an expression that is assignable to the given type. <code>null</code> is * returned if the type is the 'void' type. * * @param ast The AST to create the expression for * @param type The type of the returned expression * @param extraDimensions Extra dimensions to the type * @return the Null-literal for reference types, a boolean-literal for a boolean type, a number * literal for primitive types or <code>null</code> if the type is void. */ public static Expression newDefaultExpression(AST ast, Type type, int extraDimensions) { if (extraDimensions == 0 && type.isPrimitiveType()) { PrimitiveType primitiveType= (PrimitiveType) type; if (primitiveType.getPrimitiveTypeCode() == PrimitiveType.BOOLEAN) { return ast.newBooleanLiteral(false); } else if (primitiveType.getPrimitiveTypeCode() == PrimitiveType.VOID) { return null; } else { return ast.newNumberLiteral("0"); //$NON-NLS-1$ } } return ast.newNullLiteral(); }
/** * Returns an expression that is assignable to the given type. <code>null</code> is * returned if the type is the 'void' type. * * @param ast The AST to create the expression for * @param type The type of the returned expression * @param extraDimensions Extra dimensions to the type * @return Returns the Null-literal for reference types, a boolen-literal for a boolean type, a number * literal for primitive types or <code>null</code> if the type is void. */ public static Expression newDefaultExpression(AST ast, Type type, int extraDimensions) { if (extraDimensions == 0 && type.isPrimitiveType()) { PrimitiveType primitiveType= (PrimitiveType) type; if (primitiveType.getPrimitiveTypeCode() == PrimitiveType.BOOLEAN) { return ast.newBooleanLiteral(false); } else if (primitiveType.getPrimitiveTypeCode() == PrimitiveType.VOID) { return null; } else { return ast.newNumberLiteral("0"); //$NON-NLS-1$ } } return ast.newNullLiteral(); }
/** * Process return type of a {@link MethodDeclaration}. * * @param methodDeclaration - the method declaration. * @param methodMetadata - the method meta data. */ protected void processReturnTypeOfMethodDeclaration( MethodDeclaration methodDeclaration, MethodMetadata methodMetadata ) { Type type = methodDeclaration.getReturnType2(); if (type.isPrimitiveType()) { methodMetadata.setReturnType(FieldMetadata.primitiveType(((PrimitiveType)type).getPrimitiveTypeCode().toString())); } if (type.isSimpleType()) { methodMetadata.setReturnType(FieldMetadata.simpleType(JavaMetadataUtil.getName(((SimpleType)type).getName()))); } }
/** * Process return type of a {@link MethodDeclaration}. * * @param methodDeclaration - the method declaration. * @param methodMetadata - the method meta data. */ protected void processReturnTypeOfMethodDeclaration( MethodDeclaration methodDeclaration, MethodMetadata methodMetadata ) { Type type = methodDeclaration.getReturnType2(); if (type.isPrimitiveType()) { methodMetadata.setReturnType(FieldMetadata.primitiveType(((PrimitiveType)type).getPrimitiveTypeCode().toString())); } if (type.isSimpleType()) { methodMetadata.setReturnType(FieldMetadata.simpleType(JavaMetadataUtil.getName(((SimpleType)type).getName()))); } }
if (type.isPrimitiveType()) { PrimitiveType primitiveType = (PrimitiveType)type; return primitiveType.getPrimitiveTypeCode().toString(); if (elementType.isPrimitiveType()) { return ((PrimitiveType)elementType).getPrimitiveTypeCode().toString();
if (type.isPrimitiveType()) { return processPrimitiveType(fieldDeclaration);
/** * If possible, use the type declaration, so we can return the type as it was declared. * Otherwise, let's use the type binding and output verbose fully qualified types. */ private Type createMapEntryType( SingleVariableDeclaration parameter, MethodInvocation getValueMi, TypeNameDecider typeNameDecider) { final String mapEntryType = typeNameDecider.useSimplestPossibleName("java.util.Map.Entry"); final ASTBuilder b = ctx.getASTBuilder(); final Type paramType = parameter.getType(); final Type mapKeyType; if (paramType.isPrimitiveType()) { // Use the type binding (not as precise as what is in the code) final ITypeBinding mapTypeBinding = getValueMi.getExpression().resolveTypeBinding(); final ITypeBinding keyTypeBinding = mapTypeBinding.getTypeArguments()[0]; mapKeyType = b.toType(keyTypeBinding, typeNameDecider); } else { // Use the type as defined in the code mapKeyType = b.move(paramType); } final Type mapValueType = b.copyType(getValueMi, typeNameDecider); return b.genericType(mapEntryType, mapKeyType, mapValueType); }
private static String dispatch(Type type) { if(null == type) { return ""; } if(type.isArrayType()) { return getArraySignature((ArrayType) type); } else if(type.isPrimitiveType()) { return getPrimitiveSignature((PrimitiveType) type); } else if(type.isSimpleType()) { return getTypeSignature((SimpleType) type); } else if(type.isQualifiedType()) { return getTypeSignature((QualifiedType) type); } else if(type.isParameterizedType()) { return getParameterizedSignature((ParameterizedType) type); } else if(type.isWildcardType()) { return getWildcardSignature((WildcardType) type); } return ""; } }
private boolean withThenReturnStmt(IfStatement node, ReturnStatement thenRs, ReturnStatement elseRs) { ReturnStatement newRs = getReturnStatement(node, thenRs.getExpression(), elseRs.getExpression()); if (newRs != null) { ctx.getRefactorings().replace(node, newRs); ctx.getRefactorings().remove(elseRs); return DO_NOT_VISIT_SUBTREE; } final MethodDeclaration md = getAncestor(node, MethodDeclaration.class); final Type returnType = md.getReturnType2(); if (returnType != null && returnType.isPrimitiveType()) { final PrimitiveType pt = (PrimitiveType) returnType; if (PrimitiveType.BOOLEAN.equals(pt.getPrimitiveTypeCode())) { final Boolean thenBool = getBooleanLiteral(thenRs.getExpression()); final Boolean elseBool = getBooleanLiteral(elseRs.getExpression()); newRs = getReturnStatement(node, thenBool, elseBool, thenRs.getExpression(), elseRs.getExpression()); if (newRs != null) { ctx.getRefactorings().replace(node, newRs); ctx.getRefactorings().remove(elseRs); return DO_NOT_VISIT_SUBTREE; } } } return VISIT_SUBTREE; }
/** * Process a {@link FieldDeclaration} to win information for an array type. * * @param fieldDeclaration - field declaration * @return an ArrayTypeFieldMetadata, that contains information about an array type. */ protected FieldMetadata processArrayTypeFrom( FieldDeclaration fieldDeclaration ) { ArrayType arrayType = (ArrayType)fieldDeclaration.getType(); FieldMetadata arrayTypeFieldMetadata = null; // the element type is never an array type Type type = arrayType.getElementType(); if (type.isPrimitiveType()) { PrimitiveType primitiveType = (PrimitiveType)type; arrayTypeFieldMetadata = FieldMetadata.arrayType(primitiveType.getPrimitiveTypeCode().toString()); processModifiersAndVariablesOfFieldDeclaration(fieldDeclaration, arrayTypeFieldMetadata); arrayTypeFieldMetadata.setName(getFieldName(fieldDeclaration)); return arrayTypeFieldMetadata; } // can't be an array type if (type.isSimpleType()) { SimpleType simpleType = (SimpleType)type; arrayTypeFieldMetadata = FieldMetadata.arrayType(JavaMetadataUtil.getName(simpleType.getName())); processModifiersAndVariablesOfFieldDeclaration(fieldDeclaration, arrayTypeFieldMetadata); arrayTypeFieldMetadata.setName(getFieldName(fieldDeclaration)); return arrayTypeFieldMetadata; } return null; }
/** * Process a {@link FieldDeclaration} to win information for an array type. * * @param fieldDeclaration - field declaration * @return an ArrayTypeFieldMetadata, that contains information about an array type. */ protected FieldMetadata processArrayTypeFrom( FieldDeclaration fieldDeclaration ) { ArrayType arrayType = (ArrayType)fieldDeclaration.getType(); FieldMetadata arrayTypeFieldMetadata = null; // the element type is never an array type Type type = arrayType.getElementType(); if (type.isPrimitiveType()) { PrimitiveType primitiveType = (PrimitiveType)type; arrayTypeFieldMetadata = FieldMetadata.arrayType(primitiveType.getPrimitiveTypeCode().toString()); processModifiersAndVariablesOfFieldDeclaration(fieldDeclaration, arrayTypeFieldMetadata); arrayTypeFieldMetadata.setName(getFieldName(fieldDeclaration)); return arrayTypeFieldMetadata; } // can't be an array type if (type.isSimpleType()) { SimpleType simpleType = (SimpleType)type; arrayTypeFieldMetadata = FieldMetadata.arrayType(JavaMetadataUtil.getName(simpleType.getName())); processModifiersAndVariablesOfFieldDeclaration(fieldDeclaration, arrayTypeFieldMetadata); arrayTypeFieldMetadata.setName(getFieldName(fieldDeclaration)); return arrayTypeFieldMetadata; } return null; }
@Override public boolean visit(FieldDeclaration node) { if (node.getType().isPrimitiveType() || hasType(node.getType().resolveBinding(), "java.lang.Byte") || hasType(node.getType().resolveBinding(), "java.lang.Character")