Java Code Examples for org.eclipse.jdt.core.dom.Type#isParameterizedType()
The following examples show how to use
org.eclipse.jdt.core.dom.Type#isParameterizedType() .
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: StubUtility.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static String[] getVariableNameSuggestions(int variableKind, IJavaProject project, Type expectedType, Collection<String> excluded, boolean evaluateDefault) { int dim= 0; if (expectedType.isArrayType()) { ArrayType arrayType= (ArrayType)expectedType; dim= arrayType.getDimensions(); expectedType= arrayType.getElementType(); } if (expectedType.isParameterizedType()) { expectedType= ((ParameterizedType)expectedType).getType(); } String typeName= ASTNodes.getTypeName(expectedType); if (typeName.length() > 0) { return getVariableNameSuggestions(variableKind, project, typeName, dim, excluded, evaluateDefault); } return EMPTY; }
Example 2
Source File: Resolver.java From DesigniteJava with Apache License 2.0 | 5 votes |
private void specifyTypes(Type type) { if (type.isParameterizedType()) { ParameterizedType parameterizedType = (ParameterizedType) type; List<Type> typeArgs = parameterizedType.typeArguments(); for (int i = 0; i < typeArgs.size(); i++) setTypeList(typeArgs.get(i)); } else if (type.isArrayType()) { Type arrayType = ((ArrayType) type).getElementType(); setArrayType(arrayType); } }
Example 3
Source File: ASTUtil.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
private static String getPrettyTypeName(Type type) { if (type.isArrayType()) { return getPrettyTypeName((ArrayType) type); } else if (type.isParameterizedType()) { return getPrettyTypeName((ParameterizedType) type); } else if (type.isPrimitiveType()) { return getPrettyTypeName((PrimitiveType) type); } else if (type.isQualifiedType()) { return getPrettyTypeName((QualifiedType) type); } else if (type.isSimpleType()) { return getPrettyTypeName((SimpleType) type); } else { return ""; } }
Example 4
Source File: TypeResolver.java From KodeBeagle with Apache License 2.0 | 5 votes |
/** * @param type * @return */ protected String getNameOfType(final Type type) { String nameOfType = ""; if (type != null) { if (type.isPrimitiveType()) { nameOfType = type.toString(); } else if (type.isParameterizedType()) { nameOfType = getParametrizedType((ParameterizedType) type); } else if (type.isArrayType()) { final ArrayType array = (ArrayType) type; nameOfType = getNameOfType(array.getElementType()) /*+ "[]"*/; } else if (type.isUnionType()) { // TODO: this is used for exceptions till now // So we will just capture the first type that we encounter final UnionType uType = (UnionType) type; final StringBuilder sb = new StringBuilder(); for (final Object unionedType : uType.types()) { sb.append(getNameOfType((Type) unionedType)); break; } nameOfType = sb.toString(); } else if (type.isWildcardType()) { final WildcardType wType = (WildcardType) type; nameOfType = (wType.isUpperBound() ? "? extends " : "? super ") + getNameOfType(wType.getBound()); } else { nameOfType = getFullyQualifiedNameFor(type.toString()); } } return nameOfType; }
Example 5
Source File: JavaApproximateTypeInferencer.java From api-mining with GNU General Public License v3.0 | 5 votes |
/** * @param type * @return */ protected String getNameOfType(final Type type) { final String nameOfType; if (type.isPrimitiveType()) { nameOfType = type.toString(); } else if (type.isParameterizedType()) { nameOfType = getParametrizedType((ParameterizedType) type); } else if (type.isArrayType()) { final ArrayType array = (ArrayType) type; nameOfType = getNameOfType(array.getElementType()) + "[]"; } else if (type.isUnionType()) { final UnionType uType = (UnionType) type; final StringBuffer sb = new StringBuffer(); for (final Object unionedType : uType.types()) { sb.append(getNameOfType(((Type) unionedType))); sb.append(" | "); } sb.delete(sb.length() - 3, sb.length()); nameOfType = sb.toString(); } else if (type.isWildcardType()) { final WildcardType wType = (WildcardType) type; if (wType.getBound() == null) return "?"; nameOfType = (wType.isUpperBound() ? "? extends " : "? super ") + getNameOfType(wType.getBound()); } else { nameOfType = getFullyQualifiedNameFor(type.toString()); } return nameOfType; }
Example 6
Source File: JavaTypeHierarchyExtractor.java From api-mining with GNU General Public License v3.0 | 4 votes |
@Override public boolean visit(final TypeDeclaration node) { for (final Object supType : node.superInterfaceTypes()) { Type superType = (Type) supType; if (superType.isParameterizedType()) { superType = ((ParameterizedType) superType).getType(); } final String qName = superType.resolveBinding().getErasure() .getQualifiedName(); if (className.isEmpty()) { addTypes(qName, currentPackageName + "." + node.getName()); } else { addTypes(qName, className.peek() + "." + node.getName()); } } Type superclassType = node.getSuperclassType(); if (superclassType != null) { if (superclassType.isParameterizedType()) { superclassType = ((ParameterizedType) superclassType) .getType(); } addTypes(superclassType.resolveBinding().getQualifiedName(), currentPackageName + "." + node.getName()); } if (className.isEmpty()) { className.push(currentPackageName + "." + node.getName().getIdentifier()); importedNames.put(node.getName().getIdentifier(), currentPackageName + "." + node.getName().getIdentifier()); } else { className.push(className.peek() + "." + node.getName().getIdentifier()); importedNames .put(node.getName().getIdentifier(), className.peek() + "." + node.getName().getIdentifier()); } return true; }
Example 7
Source File: Util.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 4 votes |
/** * Sync method has same return type as parameterization of last async * parameter (AsyncCallback). If the async callback parameter type is raw, * just assume sync return type of void. * * @param ast {@link AST} associated with the destination compilation unit * @param asyncMethod the GWT RPC async method declaration * @param imports {@link ImportRewrite} associated with the destination * compilation unit * @return the computed return {@link Type} */ public static Type computeSyncReturnType(AST ast, MethodDeclaration asyncMethod, ImportRewrite imports) { Type returnType = ast.newPrimitiveType(PrimitiveType.VOID); @SuppressWarnings("unchecked") List<SingleVariableDeclaration> asyncParameters = asyncMethod.parameters(); // Check for no parameters on async method... just in case if (asyncParameters.isEmpty()) { return returnType; } // Grab the last parameter type, which should be the callback Type callbackType = asyncParameters.get(asyncParameters.size() - 1).getType(); // Make sure we have a parameterized callback type; otherwise, we can't // infer the return type of the sync method. if (callbackType.isParameterizedType()) { ParameterizedType callbackParamType = (ParameterizedType) callbackType; ITypeBinding callbackBinding = callbackParamType.getType().resolveBinding(); if (callbackBinding == null) { return returnType; } // Make sure the callback is of type AsyncCallback String callbackBaseTypeName = callbackBinding.getErasure().getQualifiedName(); if (callbackBaseTypeName.equals(RemoteServiceUtilities.ASYNCCALLBACK_QUALIFIED_NAME)) { @SuppressWarnings("unchecked") List<Type> callbackTypeArgs = callbackParamType.typeArguments(); // Make sure we only have one type argument if (callbackTypeArgs.size() == 1) { Type callbackTypeParameter = callbackTypeArgs.get(0); // Check for primitive wrapper type; if we have one use the actual // primitive for the sync return type. // TODO(): Maybe used linked mode to let the user choose whether to // return the primitive or its wrapper type. String qualifiedName = callbackTypeParameter.resolveBinding().getQualifiedName(); String primitiveTypeName = JavaASTUtils.getPrimitiveTypeName(qualifiedName); if (primitiveTypeName != null) { return ast.newPrimitiveType(PrimitiveType.toCode(primitiveTypeName)); } returnType = JavaASTUtils.normalizeTypeAndAddImport(ast, callbackTypeParameter, imports); } } } return returnType; }
Example 8
Source File: JavaTypeHierarchyExtractor.java From tassal with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public boolean visit(final TypeDeclaration node) { for (final Object supType : node.superInterfaceTypes()) { Type superType = (Type) supType; if (superType.isParameterizedType()) { superType = ((ParameterizedType) superType).getType(); } final String qName = superType.resolveBinding().getErasure() .getQualifiedName(); if (className.isEmpty()) { addTypes(qName, currentPackageName + "." + node.getName()); } else { addTypes(qName, className.peek() + "." + node.getName()); } } Type superclassType = node.getSuperclassType(); if (superclassType != null) { if (superclassType.isParameterizedType()) { superclassType = ((ParameterizedType) superclassType) .getType(); } addTypes(superclassType.resolveBinding().getQualifiedName(), currentPackageName + "." + node.getName()); } if (className.isEmpty()) { className.push(currentPackageName + "." + node.getName().getIdentifier()); importedNames.put(node.getName().getIdentifier(), currentPackageName + "." + node.getName().getIdentifier()); } else { className.push(className.peek() + "." + node.getName().getIdentifier()); importedNames .put(node.getName().getIdentifier(), className.peek() + "." + node.getName().getIdentifier()); } return true; }
Example 9
Source File: JavaTypeHierarchyExtractor.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public boolean visit(final TypeDeclaration node) { for (final Object supType : node.superInterfaceTypes()) { Type superType = (Type) supType; if (superType.isParameterizedType()) { superType = ((ParameterizedType) superType).getType(); } final String qName = superType.resolveBinding().getErasure() .getQualifiedName(); if (className.isEmpty()) { addTypes(qName, currentPackageName + "." + node.getName()); } else { addTypes(qName, className.peek() + "." + node.getName()); } } Type superclassType = node.getSuperclassType(); if (superclassType != null) { if (superclassType.isParameterizedType()) { superclassType = ((ParameterizedType) superclassType) .getType(); } addTypes(superclassType.resolveBinding().getQualifiedName(), currentPackageName + "." + node.getName()); } if (className.isEmpty()) { className.push(currentPackageName + "." + node.getName().getIdentifier()); importedNames.put(node.getName().getIdentifier(), currentPackageName + "." + node.getName().getIdentifier()); } else { className.push(className.peek() + "." + node.getName().getIdentifier()); importedNames .put(node.getName().getIdentifier(), className.peek() + "." + node.getName().getIdentifier()); } return true; }