/** * Create a <code>FieldMetadata</code> from a {@link Type} instance. * * @param type - The {@link Type} * @return the specific type of <code>FieldMetadata</code> */ protected FieldMetadata createParameterizedFieldMetadataFrom( Type type ) { FieldMetadata parameterizedTypeFieldMetadata = null; if (type.isSimpleType()) { SimpleType simpleType = (SimpleType)type; parameterizedTypeFieldMetadata = FieldMetadata.parametrizedType(JavaMetadataUtil.getName(simpleType.getName())); } // TODO also process QualifiedType return parameterizedTypeFieldMetadata; }
/** * Create a <code>FieldMetadata</code> from a {@link Type} instance. * * @param type - The {@link Type} * @return the specific type of <code>FieldMetadata</code> */ protected FieldMetadata createParameterizedFieldMetadataFrom( Type type ) { FieldMetadata parameterizedTypeFieldMetadata = null; if (type.isSimpleType()) { SimpleType simpleType = (SimpleType)type; parameterizedTypeFieldMetadata = FieldMetadata.parametrizedType(JavaMetadataUtil.getName(simpleType.getName())); } // TODO also process QualifiedType return parameterizedTypeFieldMetadata; }
public static String getParameterizedType(final Type type) { if (!(type instanceof ParameterizedType)) { return null; } final ParameterizedType parameterizedType = (ParameterizedType) type; final Type myType = parameterizedType.getType(); @SuppressWarnings("rawtypes") final List myArguments = parameterizedType.typeArguments(); if (myArguments != null && myArguments.size() == 1 && myType != null && myType.isSimpleType() && ((SimpleType) myType).getName().getFullyQualifiedName().equals("List")) { final Object o = myArguments.get(0); if (o instanceof SimpleType) { final SimpleType paramClazz = (SimpleType) o; return paramClazz.getName().getFullyQualifiedName(); } } return null; }
public static String getExtendsClass(final Path path) { final CompilationUnit unit = getCompilationUnit(path); final TypeDeclaration classType = (TypeDeclaration) unit.types().get(0); final Type superclassType = classType.getSuperclassType(); if (superclassType == null) { return null; } if (superclassType.isSimpleType()) { return ((SimpleType) superclassType).getName().getFullyQualifiedName(); } // TODO add complex (wildcard etc types) return null; }
public static String getReturnType(final Type type) { if (type == null) { log.warn("Cannot extract return type from null type"); return null; } if (type.isSimpleType()) { final SimpleType simpleType = (SimpleType) type; return simpleType.getName().getFullyQualifiedName(); } else if (type.isArrayType()) { ArrayType arrayType = (ArrayType) type; return arrayType.toString(); } else if (JavaSourceUtils.getParameterizedType(type) != null) { return JavaSourceUtils.getParameterizedType(type); } log.warn("Couldn't extract return type for: {}", type); return null; }
public EssentialsGeneratedMethod(final MethodDeclaration methodDeclaration, final String methodName, final String internalName) { this.methodDeclaration = methodDeclaration; this.methodName = methodName; this.internalName = internalName; final Type type = methodDeclaration.getReturnType2(); this.returnType = type; if (type != null) { if (type.isParameterizedType()) { final ParameterizedType parameterizedType = (ParameterizedType) type; final Type myType = parameterizedType.getType(); if (myType != null && myType.isSimpleType() && ((SimpleType) myType).getName().getFullyQualifiedName().equals("List")) { this.multiType = true; } } else if (type.isArrayType()) { this.multiType = true; } } }
final String methodName = node.getName().getFullyQualifiedName(); final Type type = node.getReturnType2(); if (type.isSimpleType()) { final SimpleType simpleType = (SimpleType) type; final String returnTypeName = simpleType.getName().getFullyQualifiedName();
if (type.isSimpleType()) { FieldMetadata simpleTypeFieldMetadata = processVariableDeclaration(singleVariableDeclaration, type); methodMetadata.getParameters().add(simpleTypeFieldMetadata);
if (returnType2.isSimpleType()) { final SimpleType simpleType = (SimpleType) returnType2; if (!simpleType.getName().getFullyQualifiedName().equals(returnType)) {
/** * 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()))); } }
return primitiveType.getPrimitiveTypeCode().toString(); if (type.isSimpleType()) { SimpleType simpleType = (SimpleType)type; return JavaMetadataUtil.getName(simpleType.getName()); if (elementType.isSimpleType()) { return JavaMetadataUtil.getName(((SimpleType)elementType).getName());
return primitiveType.getPrimitiveTypeCode().toString(); if (type.isSimpleType()) { SimpleType simpleType = (SimpleType)type; return JavaMetadataUtil.getName(simpleType.getName()); if (elementType.isSimpleType()) { return JavaMetadataUtil.getName(((SimpleType)elementType).getName());
/** * All types should be ensured first via this method. We first check to see if * the binding is resolvable (not null) If it is not null we ensure the type * from the binding (the happy case) If the type is null we recover what we know * (for example, the name of a simple type) In the worst case we return the * {@link #unknownType()} */ private Type ensureTypeFromDomType(org.eclipse.jdt.core.dom.Type domType) { ITypeBinding binding = domType.resolveBinding(); if (binding != null) return ensureTypeFromTypeBinding(binding); if (domType.isSimpleType()) return ensureTypeNamedInUnknownNamespace(((SimpleType) domType).getName().toString()); if (domType.isParameterizedType()) return ensureTypeNamedInUnknownNamespace( ((org.eclipse.jdt.core.dom.ParameterizedType) domType).getType().toString()); return unknownType(); }
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 void updateType(CompilationUnit cu, Type oldType, CompilationUnitChange unitChange, ASTRewrite unitRewriter, String typeName) { String oldName= fSelectionTypeBinding.getName(); String description= Messages.format(RefactoringCoreMessages.ChangeTypeRefactoring_typeChange, new String[] {oldName, typeName}); TextEditGroup gd= new TextEditGroup(description); AST ast= cu.getAST(); ASTNode nodeToReplace= oldType; if (fSelectionTypeBinding.isParameterizedType() && !fSelectionTypeBinding.isRawType()){ if (oldType.isSimpleType()){ nodeToReplace= oldType.getParent(); } } //TODO handle types other than simple & parameterized (e.g., arrays) Assert.isTrue(fSelectedType.isClass() || fSelectedType.isInterface()); Type newType= null; if (!fSelectedType.isParameterizedType()){ newType= ast.newSimpleType(ASTNodeFactory.newName(ast, typeName)); } else { newType= createParameterizedType(ast, fSelectedType); } unitRewriter.replace(nodeToReplace, newType, gd); unitChange.addTextEditGroup(gd); }
/** * 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; }
private void updateType(CompilationUnit cu, Type oldType, CompilationUnitChange unitChange, ASTRewrite unitRewriter, String typeName) { String oldName= fSelectionTypeBinding.getName(); String[] keys= { BasicElementLabels.getJavaElementName(oldName), BasicElementLabels.getJavaElementName(typeName)}; String description= Messages.format(RefactoringCoreMessages.ChangeTypeRefactoring_typeChange, keys); TextEditGroup gd= new TextEditGroup(description); AST ast= cu.getAST(); ASTNode nodeToReplace= oldType; if (fSelectionTypeBinding.isParameterizedType() && !fSelectionTypeBinding.isRawType()){ if (oldType.isSimpleType()){ nodeToReplace= oldType.getParent(); } } //TODO handle types other than simple & parameterized (e.g., arrays) Assert.isTrue(fSelectedType.isClass() || fSelectedType.isInterface()); Type newType= null; if (!fSelectedType.isParameterizedType()){ newType= ast.newSimpleType(ASTNodeFactory.newName(ast, typeName)); } else { newType= createParameterizedType(ast, fSelectedType); } unitRewriter.replace(nodeToReplace, newType, gd); unitChange.addTextEditGroup(gd); }
private void updateType(CompilationUnit cu, Type oldType, CompilationUnitChange unitChange, ASTRewrite unitRewriter, String typeName) { String oldName= fSelectionTypeBinding.getName(); String[] keys= { BasicElementLabels.getJavaElementName(oldName), BasicElementLabels.getJavaElementName(typeName)}; String description= Messages.format(RefactoringCoreMessages.ChangeTypeRefactoring_typeChange, keys); TextEditGroup gd= new TextEditGroup(description); AST ast= cu.getAST(); ASTNode nodeToReplace= oldType; if (fSelectionTypeBinding.isParameterizedType() && !fSelectionTypeBinding.isRawType()){ if (oldType.isSimpleType()){ nodeToReplace= oldType.getParent(); } } //TODO handle types other than simple & parameterized (e.g., arrays) Assert.isTrue(fSelectedType.isClass() || fSelectedType.isInterface()); Type newType= null; if (!fSelectedType.isParameterizedType()){ newType= ast.newSimpleType(ASTNodeFactory.newName(ast, typeName)); } else { newType= createParameterizedType(ast, fSelectedType); } unitRewriter.replace(nodeToReplace, newType, gd); unitChange.addTextEditGroup(gd); }