Java Code Examples for org.eclipse.jdt.core.dom.ITypeBinding#isTypeVariable()
The following examples show how to use
org.eclipse.jdt.core.dom.ITypeBinding#isTypeVariable() .
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: FlowAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public void endVisit(SimpleName node) { if (skipNode(node) || node.isDeclaration()) return; IBinding binding= node.resolveBinding(); if (binding instanceof IVariableBinding) { IVariableBinding variable= (IVariableBinding)binding; if (!variable.isField()) { setFlowInfo(node, new LocalFlowInfo( variable, FlowInfo.READ, fFlowContext)); } } else if (binding instanceof ITypeBinding) { ITypeBinding type= (ITypeBinding)binding; if (type.isTypeVariable()) { setFlowInfo(node, new TypeVariableFlowInfo(type, fFlowContext)); } } }
Example 2
Source File: ChangeTypeRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Creates the appropriate ParameterizedType node. Recursion is needed to * handle the nested case (e.g., Vector<Vector<String>>). * @param ast * @param typeBinding * @return the created type */ private Type createParameterizedType(AST ast, ITypeBinding typeBinding){ if (typeBinding.isParameterizedType() && !typeBinding.isRawType()){ Type baseType= ast.newSimpleType(ASTNodeFactory.newName(ast, typeBinding.getErasure().getName())); ParameterizedType newType= ast.newParameterizedType(baseType); for (int i=0; i < typeBinding.getTypeArguments().length; i++){ ITypeBinding typeArg= typeBinding.getTypeArguments()[i]; Type argType= createParameterizedType(ast, typeArg); // recursive call newType.typeArguments().add(argType); } return newType; } else { if (!typeBinding.isTypeVariable()){ return ast.newSimpleType(ASTNodeFactory.newName(ast, typeBinding.getErasure().getName())); } else { return ast.newSimpleType(ast.newSimpleName(typeBinding.getName())); } } }
Example 3
Source File: ChangeSignatureProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void collectTypeVariables(ITypeBinding typeBinding, Set<ITypeBinding> typeVariablesCollector) { if (typeBinding.isTypeVariable()) { typeVariablesCollector.add(typeBinding); ITypeBinding[] typeBounds= typeBinding.getTypeBounds(); for (int i= 0; i < typeBounds.length; i++) collectTypeVariables(typeBounds[i], typeVariablesCollector); } else if (typeBinding.isArray()) { collectTypeVariables(typeBinding.getElementType(), typeVariablesCollector); } else if (typeBinding.isParameterizedType()) { ITypeBinding[] typeArguments= typeBinding.getTypeArguments(); for (int i= 0; i < typeArguments.length; i++) collectTypeVariables(typeArguments[i], typeVariablesCollector); } else if (typeBinding.isWildcardType()) { ITypeBinding bound= typeBinding.getBound(); if (bound != null) { collectTypeVariables(bound, typeVariablesCollector); } } }
Example 4
Source File: ASTResolving.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static ICompilationUnit findCompilationUnitForBinding(ICompilationUnit cu, CompilationUnit astRoot, ITypeBinding binding) throws JavaModelException { if (binding == null || !binding.isFromSource() || binding.isTypeVariable() || binding.isWildcardType()) { return null; } ASTNode node= astRoot.findDeclaringNode(binding.getTypeDeclaration()); if (node == null) { ICompilationUnit targetCU= Bindings.findCompilationUnit(binding, cu.getJavaProject()); if (targetCU != null) { return targetCU; } return null; } else if (node instanceof AbstractTypeDeclaration || node instanceof AnonymousClassDeclaration) { return cu; } return null; }
Example 5
Source File: FlowAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override public void endVisit(SimpleName node) { if (skipNode(node) || node.isDeclaration()) { return; } IBinding binding = node.resolveBinding(); if (binding instanceof IVariableBinding) { IVariableBinding variable = (IVariableBinding) binding; if (!variable.isField()) { setFlowInfo(node, new LocalFlowInfo(variable, FlowInfo.READ, fFlowContext)); } } else if (binding instanceof ITypeBinding) { ITypeBinding type = (ITypeBinding) binding; if (type.isTypeVariable()) { setFlowInfo(node, new TypeVariableFlowInfo(type, fFlowContext)); } } }
Example 6
Source File: BindingLabelProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static ImageDescriptor getTypeImageDescriptor(boolean inner, ITypeBinding binding, int flags) { if (binding.isEnum()) return JavaPluginImages.DESC_OBJS_ENUM; else if (binding.isAnnotation()) return JavaPluginImages.DESC_OBJS_ANNOTATION; else if (binding.isInterface()) { if ((flags & JavaElementImageProvider.LIGHT_TYPE_ICONS) != 0) return JavaPluginImages.DESC_OBJS_INTERFACEALT; if (inner) return getInnerInterfaceImageDescriptor(binding.getModifiers()); return getInterfaceImageDescriptor(binding.getModifiers()); } else if (binding.isClass()) { if ((flags & JavaElementImageProvider.LIGHT_TYPE_ICONS) != 0) return JavaPluginImages.DESC_OBJS_CLASSALT; if (inner) return getInnerClassImageDescriptor(binding.getModifiers()); return getClassImageDescriptor(binding.getModifiers()); } else if (binding.isTypeVariable()) { return JavaPluginImages.DESC_OBJS_TYPEVARIABLE; } // primitive type, wildcard return null; }
Example 7
Source File: GenerateHashCodeEqualsAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private HashCodeEqualsInfo getTypeInfo(ITypeBinding someType, boolean checkSuperclasses) { HashCodeEqualsInfo info= new HashCodeEqualsInfo(); if (someType.isTypeVariable()) { someType= someType.getErasure(); } while (true) { IMethodBinding[] declaredMethods= someType.getDeclaredMethods(); for (int i= 0; i < declaredMethods.length; i++) { if (declaredMethods[i].getName().equals(METHODNAME_EQUALS)) { ITypeBinding[] b= declaredMethods[i].getParameterTypes(); if ((b.length == 1) && (b[0].getQualifiedName().equals("java.lang.Object"))) { //$NON-NLS-1$ info.foundEquals= true; if (Modifier.isFinal(declaredMethods[i].getModifiers())) info.foundFinalEquals= true; } } if (declaredMethods[i].getName().equals(METHODNAME_HASH_CODE) && declaredMethods[i].getParameterTypes().length == 0) { info.foundHashCode= true; if (Modifier.isFinal(declaredMethods[i].getModifiers())) info.foundFinalHashCode= true; } if (info.foundEquals && info.foundHashCode) break; } if (checkSuperclasses) { someType= someType.getSuperclass(); if (someType == null || TypeRules.isJavaLangObject(someType)) { break; } } else { break; } } return info; }
Example 8
Source File: ConvertAnonymousToNestedRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public final boolean visit(final SimpleName node) { Assert.isNotNull(node); final ITypeBinding binding= node.resolveTypeBinding(); if (binding != null && binding.isTypeVariable() && !fBindings.containsKey(binding.getKey())) { fBindings.put(binding.getKey(), binding); fFound.add(binding); } return true; }
Example 9
Source File: CollectionElementVariable2.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * @param parentCv the parent constraint variable * @param typeVariable the type variable for this constraint * @param declarationTypeVariableIndex */ public CollectionElementVariable2(ConstraintVariable2 parentCv, ITypeBinding typeVariable, int declarationTypeVariableIndex) { super(null); fParentCv= parentCv; if (! typeVariable.isTypeVariable()) throw new IllegalArgumentException(typeVariable.toString()); fTypeVariableKey= typeVariable.getKey(); fDeclarationTypeVariableIndex= declarationTypeVariableIndex; }
Example 10
Source File: TypeEnvironment.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public TType create(ITypeBinding binding) { if (binding.isPrimitive()) { return createPrimitiveType(binding); } else if (binding.isArray()) { return createArrayType(binding); } else if (binding.isRawType()) { return createRawType(binding); } else if (binding.isGenericType()) { return createGenericType(binding); } else if (binding.isParameterizedType()) { return createParameterizedType(binding); } else if (binding.isTypeVariable()) { return createTypeVariable(binding); } else if (binding.isWildcardType()) { if (binding.getBound() == null) { return createUnboundWildcardType(binding); } else if (binding.isUpperbound()) { return createExtendsWildCardType(binding); } else { return createSuperWildCardType(binding); } } else if (binding.isCapture()) { if (fRemoveCapures) { return create(binding.getWildcard()); } else { return createCaptureType(binding); } } if ("null".equals(binding.getName())) //$NON-NLS-1$ return NULL; return createStandardType(binding); }
Example 11
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public final boolean visit(final SimpleName node) { Assert.isNotNull(node); final IBinding binding= node.resolveBinding(); if (binding instanceof ITypeBinding) { final ITypeBinding type= (ITypeBinding) binding; if (!fBindings.contains(type.getKey()) && type.isTypeVariable()) { fResult.add(node); fStatus.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_type_variables, JavaStatusContext.create(fMethod.getCompilationUnit(), node))); return false; } } return true; }
Example 12
Source File: Bindings.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean sameParameter(ITypeBinding type, String candidate, IType scope) throws JavaModelException { if (type.getDimensions() != Signature.getArrayCount(candidate)) return false; // Normalizes types if (type.isArray()) type= type.getElementType(); candidate= Signature.getElementType(candidate); if ((Signature.getTypeSignatureKind(candidate) == Signature.BASE_TYPE_SIGNATURE) != type.isPrimitive()) { return false; } if (type.isPrimitive() || type.isTypeVariable()) { return type.getName().equals(Signature.toString(candidate)); } else { // normalize (quick hack until binding.getJavaElement works) candidate= Signature.getTypeErasure(candidate); type= type.getErasure(); if (candidate.charAt(Signature.getArrayCount(candidate)) == Signature.C_RESOLVED) { return Signature.toString(candidate).equals(Bindings.getFullyQualifiedName(type)); } else { String[][] qualifiedCandidates= scope.resolveType(Signature.toString(candidate)); if (qualifiedCandidates == null || qualifiedCandidates.length == 0) return false; String packageName= type.getPackage().isUnnamed() ? "" : type.getPackage().getName(); //$NON-NLS-1$ String typeName= getTypeQualifiedName(type); for (int i= 0; i < qualifiedCandidates.length; i++) { String[] qualifiedCandidate= qualifiedCandidates[i]; if ( qualifiedCandidate[0].equals(packageName) && qualifiedCandidate[1].equals(typeName)) return true; } } } return false; }
Example 13
Source File: NewAsyncRemoteServiceInterfaceCreationWizardPage.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
static void expandTypeBinding(ITypeBinding typeBinding, StringBuilder sb, ImportManagerAdapter importsManager) { if (typeBinding.isParameterizedType()) { expandTypeBinding(typeBinding.getErasure(), sb, importsManager); sb.append("<"); ITypeBinding[] typeArguments = typeBinding.getTypeArguments(); for (int i = 0; i < typeArguments.length; ++i) { if (i != 0) { sb.append(", "); } expandTypeBinding(typeArguments[i], sb, importsManager); } sb.append(">"); } else if (typeBinding.isWildcardType()) { ITypeBinding bound = typeBinding.getBound(); if (bound == null) { sb.append("?"); } else { if (typeBinding.isUpperbound()) { sb.append("? extends "); } else { sb.append("? super "); } expandTypeBinding(bound, sb, importsManager); } } else if (typeBinding.isTypeVariable()) { sb.append(typeBinding.getName()); } else if (typeBinding.isArray()) { expandTypeBinding(typeBinding.getComponentType(), sb, importsManager); sb.append("[]"); } else if (typeBinding.isPrimitive()) { sb.append(typeBinding.getName()); } else { sb.append(importsManager.addImport(typeBinding)); } }
Example 14
Source File: JdtUtils.java From j2cl with Apache License 2.0 | 5 votes |
/** * Creates a type descriptor for the given type binding, taking into account nullability. * * @param typeBinding the type binding, used to create the type descriptor. * @param elementAnnotations the annotations on the element */ private static TypeDescriptor createTypeDescriptorWithNullability( ITypeBinding typeBinding, IAnnotationBinding[] elementAnnotations) { if (typeBinding == null) { return null; } if (typeBinding.isPrimitive()) { return PrimitiveTypes.get(typeBinding.getName()); } if (isIntersectionType(typeBinding)) { return createIntersectionType(typeBinding); } if (typeBinding.isNullType()) { return TypeDescriptors.get().javaLangObject; } if (typeBinding.isTypeVariable() || typeBinding.isCapture() || typeBinding.isWildcardType()) { return createTypeVariable(typeBinding); } boolean isNullable = isNullable(typeBinding, elementAnnotations); if (typeBinding.isArray()) { TypeDescriptor componentTypeDescriptor = createTypeDescriptor(typeBinding.getComponentType()); return ArrayTypeDescriptor.newBuilder() .setComponentTypeDescriptor(componentTypeDescriptor) .setNullable(isNullable) .build(); } return withNullability(createDeclaredType(typeBinding), isNullable); }
Example 15
Source File: RedundantNullnessTypeAnnotationsFilter.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public IAnnotationBinding[] removeUnwantedTypeAnnotations(IAnnotationBinding[] annotations, TypeLocation location, ITypeBinding type) { if (location == TypeLocation.OTHER) { return NO_ANNOTATIONS; } if(type.isTypeVariable() || type.isWildcardType()) { return annotations; } boolean excludeAllNullAnnotations = NEVER_NULLNESS_LOCATIONS.contains(location); if (excludeAllNullAnnotations || fNonNullByDefaultLocations.contains(location)) { ArrayList<IAnnotationBinding> list= new ArrayList<>(annotations.length); for (IAnnotationBinding annotation : annotations) { ITypeBinding annotationType= annotation.getAnnotationType(); if (annotationType != null) { if (annotationType.getQualifiedName().equals(fNonNullAnnotationName)) { // ignore @NonNull } else if (excludeAllNullAnnotations && annotationType.getQualifiedName().equals(fNullableAnnotationName)) { // also ignore @Nullable } else { list.add(annotation); } } else { list.add(annotation); } } return list.size() == annotations.length ? annotations : list.toArray(new IAnnotationBinding[list.size()]); } else { return annotations; } }
Example 16
Source File: SourceAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean visit(SimpleName node) { addReferencesToName(node); IBinding binding= node.resolveBinding(); if (binding instanceof ITypeBinding) { ITypeBinding type= (ITypeBinding)binding; if (type.isTypeVariable()) { addTypeVariableReference(type, node); } } else if (binding instanceof IVariableBinding) { IVariableBinding vb= (IVariableBinding)binding; if (vb.isField() && ! isStaticallyImported(node)) { Name topName= ASTNodes.getTopMostName(node); if (node == topName || node == ASTNodes.getLeftMostSimpleName(topName)) { StructuralPropertyDescriptor location= node.getLocationInParent(); if (location != SingleVariableDeclaration.NAME_PROPERTY && location != VariableDeclarationFragment.NAME_PROPERTY) { fImplicitReceivers.add(node); } } } else if (!vb.isField()) { // we have a local. Check if it is a parameter. ParameterData data= fParameters.get(binding); if (data != null) { ASTNode parent= node.getParent(); if (parent instanceof Expression) { int precedence= OperatorPrecedence.getExpressionPrecedence((Expression)parent); if (precedence != Integer.MAX_VALUE) { data.setOperatorPrecedence(precedence); } } } } } return true; }
Example 17
Source File: PromoteTempToFieldRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean visit(SimpleName node) { ITypeBinding typeBinding= node.resolveTypeBinding(); if (typeBinding != null && typeBinding.isLocal()) { if (node.isDeclaration()) { fLocalDefinitions.add(typeBinding); } else if (! fLocalDefinitions.contains(typeBinding)) { fLocalReferencesToEnclosing.add(node); } } if (typeBinding != null && typeBinding.isTypeVariable()) { if (node.isDeclaration()) { fLocalDefinitions.add(typeBinding); } else if (! fLocalDefinitions.contains(typeBinding)) { if (fMethodTypeVariables.contains(typeBinding)) { fLocalReferencesToEnclosing.add(node); } else { fClassTypeVariablesUsed= true; } } } IBinding binding= node.resolveBinding(); if (binding != null && binding.getKind() == IBinding.VARIABLE && ! ((IVariableBinding)binding).isField()) { if (node.isDeclaration()) { fLocalDefinitions.add(binding); } else if (! fLocalDefinitions.contains(binding)) { fLocalReferencesToEnclosing.add(node); } } return super.visit(node); }
Example 18
Source File: TypeURIHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public String getQualifiedName(ITypeBinding binding) { if (binding.isParameterizedType()) { return getQualifiedName(binding.getErasure()); } if (binding.isArray()) { return getQualifiedName(binding.getComponentType(), new StringBuilder()).append("[]").toString(); } if (binding.isTopLevel() || binding.isTypeVariable() || binding.isPrimitive()) return binding.getQualifiedName(); return getQualifiedName(binding.getDeclaringClass(), new StringBuilder()).append('$').append(binding.getName()).toString(); }
Example 19
Source File: JdtUtils.java From j2cl with Apache License 2.0 | 5 votes |
private static boolean isIntersectionType(ITypeBinding binding) { return binding.isIntersectionType() // JDT returns true for isIntersectionType() for type variables, wildcards and captures // with intersection type bounds. && !binding.isCapture() && !binding.isTypeVariable() && !binding.isWildcardType(); }
Example 20
Source File: ASTResolving.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static boolean isUseableTypeInContext(ITypeBinding type, IBinding context, boolean noWildcards) { if (type.isArray()) { type= type.getElementType(); } if (type.isAnonymous()) { return false; } if (type.isRawType() || type.isPrimitive()) { return true; } if (type.isTypeVariable()) { return isVariableDefinedInContext(context, type); } if (type.isGenericType()) { ITypeBinding[] typeParameters= type.getTypeParameters(); for (int i= 0; i < typeParameters.length; i++) { if (!isUseableTypeInContext(typeParameters[i], context, noWildcards)) { return false; } } return true; } if (type.isParameterizedType()) { ITypeBinding[] typeArguments= type.getTypeArguments(); for (int i= 0; i < typeArguments.length; i++) { if (!isUseableTypeInContext(typeArguments[i], context, noWildcards)) { return false; } } return true; } if (type.isCapture()) { type= type.getWildcard(); } if (type.isWildcardType()) { if (noWildcards) { return false; } if (type.getBound() != null) { return isUseableTypeInContext(type.getBound(), context, noWildcards); } } return true; }