List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding isBaseType
public final boolean isBaseType()
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
private MethodBinding getMethodBinding0(MethodPattern methodPattern) { if (this.unitScope == null) return null; // Try to get binding from cache Binding binding = (Binding) this.bindings.get(methodPattern); if (binding != null) { if (binding instanceof MethodBinding && binding.isValidBinding()) return (MethodBinding) binding; return null; }//from w ww . j a va 2 s . c om // Get binding from unit scope char[] typeName = PatternLocator.qualifiedPattern(methodPattern.declaringSimpleName, methodPattern.declaringQualification); if (typeName == null) { if (methodPattern.declaringType == null) return null; typeName = methodPattern.declaringType.getFullyQualifiedName().toCharArray(); } TypeBinding declaringTypeBinding = getType(typeName, typeName); if (declaringTypeBinding != null) { if (declaringTypeBinding.isArrayType()) { declaringTypeBinding = declaringTypeBinding.leafComponentType(); } if (!declaringTypeBinding.isBaseType()) { char[][] parameterTypes = methodPattern.parameterSimpleNames; if (parameterTypes == null) return null; int paramTypeslength = parameterTypes.length; ReferenceBinding referenceBinding = (ReferenceBinding) declaringTypeBinding; MethodBinding[] methods = referenceBinding.getMethods(methodPattern.selector); int methodsLength = methods.length; TypeVariableBinding[] refTypeVariables = referenceBinding.typeVariables(); int typeVarLength = refTypeVariables == null ? 0 : refTypeVariables.length; for (int i = 0; i < methodsLength; i++) { TypeBinding[] methodParameters = methods[i].parameters; int paramLength = methodParameters == null ? 0 : methodParameters.length; TypeVariableBinding[] methodTypeVariables = methods[i].typeVariables; int methTypeVarLength = methodTypeVariables == null ? 0 : methodTypeVariables.length; boolean found = false; if (methodParameters != null && paramLength == paramTypeslength) { for (int p = 0; p < paramLength; p++) { if (CharOperation.equals(methodParameters[p].sourceName(), parameterTypes[p])) { // param erasure match found = true; } else { // type variable found = false; if (refTypeVariables != null) { for (int v = 0; v < typeVarLength; v++) { if (!CharOperation.equals(refTypeVariables[v].sourceName, parameterTypes[p])) { found = false; break; } found = true; } } if (!found && methodTypeVariables != null) { for (int v = 0; v < methTypeVarLength; v++) { if (!CharOperation.equals(methodTypeVariables[v].sourceName, parameterTypes[p])) { found = false; break; } found = true; } } if (!found) break; } } } if (found) { this.bindings.put(methodPattern, methods[i]); return methods[i]; } } } } this.bindings.put(methodPattern, new ProblemMethodBinding(methodPattern.selector, null, ProblemReasons.NotFound)); return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.PatternLocator.java
License:Open Source License
protected int resolveLevelForType(char[] simpleNamePattern, char[] qualificationPattern, char[][][] patternTypeArguments, int depth, TypeBinding type) { // standard search with no generic additional information must succeed int level = resolveLevelForType(simpleNamePattern, qualificationPattern, type); if (level == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH; if (type == null || patternTypeArguments == null || patternTypeArguments.length == 0 || depth >= patternTypeArguments.length) { return level; }/*from w w w. ja v a 2 s. c o m*/ // if pattern is erasure match (see bug 79790), commute impossible to erasure int impossible = this.isErasureMatch ? ERASURE_MATCH : IMPOSSIBLE_MATCH; // pattern has type parameter(s) or type argument(s) if (type.isGenericType()) { // Binding is generic, get its type variable(s) TypeVariableBinding[] typeVariables = null; if (type instanceof SourceTypeBinding) { SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) type; typeVariables = sourceTypeBinding.typeVariables; } else if (type instanceof BinaryTypeBinding) { BinaryTypeBinding binaryTypeBinding = (BinaryTypeBinding) type; if (this.mustResolve) typeVariables = binaryTypeBinding.typeVariables(); // TODO (frederic) verify performance } if (patternTypeArguments[depth] != null && patternTypeArguments[depth].length > 0 && typeVariables != null && typeVariables.length > 0) { if (typeVariables.length != patternTypeArguments[depth].length) return IMPOSSIBLE_MATCH; } // TODO (frederic) do we need to verify each parameter? return level; // we can't do better } // raw type always match if (type.isRawType()) { return level; } // Standard types (i.e. neither generic nor parameterized nor raw types) // cannot match pattern with type parameters or arguments TypeBinding leafType = type.leafComponentType(); if (!leafType.isParameterizedType()) { return (patternTypeArguments[depth] == null || patternTypeArguments[depth].length == 0) ? level : IMPOSSIBLE_MATCH; } // Parameterized type ParameterizedTypeBinding paramTypeBinding = (ParameterizedTypeBinding) leafType; // Compare arguments only if there ones on both sides if (patternTypeArguments[depth] != null && patternTypeArguments[depth].length > 0 && paramTypeBinding.arguments != null && paramTypeBinding.arguments.length > 0) { // type parameters length must match at least specified type names length int length = patternTypeArguments[depth].length; if (paramTypeBinding.arguments.length != length) return IMPOSSIBLE_MATCH; // verify each pattern type parameter nextTypeArgument: for (int i = 0; i < length; i++) { char[] patternTypeArgument = patternTypeArguments[depth][i]; TypeBinding argTypeBinding = paramTypeBinding.arguments[i]; // get corresponding pattern wildcard switch (patternTypeArgument[0]) { case Signature.C_STAR: // unbound parameter always match case Signature.C_SUPER: // needs pattern type parameter binding // skip to next type argument as it will be resolved later continue nextTypeArgument; case Signature.C_EXTENDS: // remove wildcard from patter type argument patternTypeArgument = CharOperation.subarray(patternTypeArgument, 1, patternTypeArgument.length); break; default: // no wildcard break; } // get pattern type argument from its signature patternTypeArgument = Signature.toCharArray(patternTypeArgument); if (!this.isCaseSensitive) patternTypeArgument = CharOperation.toLowerCase(patternTypeArgument); boolean patternTypeArgHasAnyChars = CharOperation.contains(new char[] { '*', '?' }, patternTypeArgument); // Verify that names match... // ...special case for wildcard if (argTypeBinding instanceof CaptureBinding) { WildcardBinding capturedWildcard = ((CaptureBinding) argTypeBinding).wildcard; if (capturedWildcard != null) argTypeBinding = capturedWildcard; } if (argTypeBinding.isWildcard()) { WildcardBinding wildcardBinding = (WildcardBinding) argTypeBinding; switch (wildcardBinding.boundKind) { case Wildcard.EXTENDS: // Invalid if type argument is not exact if (patternTypeArgHasAnyChars) return impossible; continue nextTypeArgument; case Wildcard.UNBOUND: // there's no bound name to match => valid continue nextTypeArgument; } // Look if bound name match pattern type argument ReferenceBinding boundBinding = (ReferenceBinding) wildcardBinding.bound; if (CharOperation.match(patternTypeArgument, boundBinding.shortReadableName(), this.isCaseSensitive) || CharOperation.match(patternTypeArgument, boundBinding.readableName(), this.isCaseSensitive)) { // found name in hierarchy => match continue nextTypeArgument; } // If pattern is not exact then match fails if (patternTypeArgHasAnyChars) return impossible; // Look for bound name in type argument superclasses boundBinding = boundBinding.superclass(); while (boundBinding != null) { if (CharOperation.equals(patternTypeArgument, boundBinding.shortReadableName(), this.isCaseSensitive) || CharOperation.equals(patternTypeArgument, boundBinding.readableName(), this.isCaseSensitive)) { // found name in hierarchy => match continue nextTypeArgument; } else if (boundBinding.isLocalType() || boundBinding.isMemberType()) { // for local or member type, verify also source name (bug 81084) if (CharOperation.match(patternTypeArgument, boundBinding.sourceName(), this.isCaseSensitive)) continue nextTypeArgument; } boundBinding = boundBinding.superclass(); } return impossible; } // See if names match if (CharOperation.match(patternTypeArgument, argTypeBinding.shortReadableName(), this.isCaseSensitive) || CharOperation.match(patternTypeArgument, argTypeBinding.readableName(), this.isCaseSensitive)) { continue nextTypeArgument; } else if (argTypeBinding.isLocalType() || argTypeBinding.isMemberType()) { // for local or member type, verify also source name (bug 81084) if (CharOperation.match(patternTypeArgument, argTypeBinding.sourceName(), this.isCaseSensitive)) continue nextTypeArgument; } // If pattern is not exact then match fails if (patternTypeArgHasAnyChars) return impossible; // Scan hierarchy TypeBinding leafTypeBinding = argTypeBinding.leafComponentType(); if (leafTypeBinding.isBaseType()) return impossible; ReferenceBinding refBinding = ((ReferenceBinding) leafTypeBinding).superclass(); while (refBinding != null) { if (CharOperation.equals(patternTypeArgument, refBinding.shortReadableName(), this.isCaseSensitive) || CharOperation.equals(patternTypeArgument, refBinding.readableName(), this.isCaseSensitive)) { // found name in hierarchy => match continue nextTypeArgument; } else if (refBinding.isLocalType() || refBinding.isMemberType()) { // for local or member type, verify also source name (bug 81084) if (CharOperation.match(patternTypeArgument, refBinding.sourceName(), this.isCaseSensitive)) continue nextTypeArgument; } refBinding = refBinding.superclass(); } return impossible; } } // Recurse on enclosing type TypeBinding enclosingType = paramTypeBinding.enclosingType(); if (enclosingType != null && enclosingType.isParameterizedType() && depth < patternTypeArguments.length && qualificationPattern != null) { int lastDot = CharOperation.lastIndexOf('.', qualificationPattern); char[] enclosingQualificationPattern = lastDot == -1 ? null : CharOperation.subarray(qualificationPattern, 0, lastDot); char[] enclosingSimpleNamePattern = lastDot == -1 ? qualificationPattern : CharOperation.subarray(qualificationPattern, lastDot + 1, qualificationPattern.length); int enclosingLevel = resolveLevelForType(enclosingSimpleNamePattern, enclosingQualificationPattern, patternTypeArguments, depth + 1, enclosingType); if (enclosingLevel == impossible) return impossible; if (enclosingLevel == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH; } return level; }
From source file:com.google.gwt.dev.javac.JdtUtil.java
License:Apache License
public static String signature(TypeBinding binding) { if (binding.isBaseType()) { return String.valueOf(binding.sourceName()); } else {//from w w w. ja v a 2 s . c o m return String.valueOf(binding.constantPoolName()); } }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.UnknownTypeMirror.java
License:Open Source License
public JDTType(TypeBinding type, IdentityHashMap<TypeBinding, JDTType> originatingTypes) { originatingTypes.put(type, this); // type params are not qualified if (type instanceof TypeVariableBinding) qualifiedName = new String(type.qualifiedSourceName()); else/* ww w . j a v a 2s . c o m*/ qualifiedName = JDTUtils.getFullyQualifiedName(type); typeKind = findKind(type); isPrimitive = type.isBaseType() && type.id != TypeIds.T_void && type.id != TypeIds.T_null; isRaw = type.isRawType(); if (type instanceof ParameterizedTypeBinding && !(type instanceof RawTypeBinding)) { TypeBinding[] javaTypeArguments = ((ParameterizedTypeBinding) type).arguments; if (javaTypeArguments == null) { javaTypeArguments = new TypeBinding[0]; } typeArguments = new ArrayList<TypeMirror>(javaTypeArguments.length); for (TypeBinding typeArgument : javaTypeArguments) typeArguments.add(toTypeMirror(typeArgument, type, this, originatingTypes)); } else { typeArguments = Collections.emptyList(); } if (type instanceof ArrayBinding) { TypeBinding jdtComponentType = ((ArrayBinding) type).elementsType(); componentType = toTypeMirror(jdtComponentType, type, this, originatingTypes); } else { componentType = null; } if (type.isWildcard()) { WildcardBinding wildcardBinding = (WildcardBinding) type; if (wildcardBinding.boundKind == Wildcard.EXTENDS) { TypeBinding upperBoundBinding = wildcardBinding.bound; if (upperBoundBinding != null) { upperBound = toTypeMirror(upperBoundBinding, type, this, originatingTypes); } } } else if (type.isTypeVariable()) { TypeVariableBinding typeVariableBinding = (TypeVariableBinding) type; TypeBinding boundBinding = typeVariableBinding.firstBound; // TODO : we should confirm this if (boundBinding != null) { upperBound = toTypeMirror(boundBinding, type, this, originatingTypes); } } else { upperBound = null; } if (type.isWildcard()) { WildcardBinding wildcardBinding = (WildcardBinding) type; if (wildcardBinding.boundKind == Wildcard.SUPER) { TypeBinding lowerBoundBinding = wildcardBinding.bound; if (lowerBoundBinding != null) { lowerBound = toTypeMirror(lowerBoundBinding, type, this, originatingTypes); } } } if (type instanceof ParameterizedTypeBinding || type instanceof SourceTypeBinding || type instanceof BinaryTypeBinding) { ReferenceBinding refBinding = (ReferenceBinding) type; declaredClass = new JDTClass(refBinding, JDTModelLoader.toType(refBinding)); } if (type instanceof TypeVariableBinding) { typeParameter = new JDTTypeParameter((TypeVariableBinding) type, this, originatingTypes); } }
From source file:lombok.eclipse.agent.PatchDelegate.java
License:Open Source License
private static String typeBindingToSignature(TypeBinding binding) { binding = binding.erasure();/* w w w. j a v a2 s .c om*/ if (binding != null && binding.isBaseType()) { return new String(binding.sourceName()); } else if (binding instanceof ReferenceBinding) { String pkg = binding.qualifiedPackageName() == null ? "" : new String(binding.qualifiedPackageName()); String qsn = binding.qualifiedSourceName() == null ? "" : new String(binding.qualifiedSourceName()); return pkg.isEmpty() ? qsn : (pkg + "." + qsn); } else if (binding instanceof ArrayBinding) { StringBuilder out = new StringBuilder(); out.append(typeBindingToSignature(binding.leafComponentType())); for (int i = 0; i < binding.dimensions(); i++) out.append("[]"); return out.toString(); } return ""; }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.JDTAnnotationNode.java
License:Open Source License
private Expression createExpressionFor(TypeBinding b, Object value) { if (b.isArrayType()) { ListExpression listExpression = new ListExpression(); // FIXASC is it a groovy optimization that if the value is expected to be an array you don't have to // write it as such if (value.getClass().isArray()) { Object[] values = (Object[]) value; for (Object v : values) { listExpression.addExpression(createExpressionFor(((ArrayBinding) b).leafComponentType, v)); }// ww w . ja v a 2s. com } else { listExpression.addExpression(createExpressionFor(((ArrayBinding) b).leafComponentType, value)); } return listExpression; } else if (b.isEnum()) { ClassExpression classExpression = new ClassExpression(resolver.convertToClassNode(b)); Expression valueExpression = new PropertyExpression(classExpression, new String(((FieldBinding) value).name)); return valueExpression; } else if (CharOperation.equals(b.signature(), jlString)) { String v = ((StringConstant) value).stringValue(); return new ConstantExpression(v); } else if (b.isBaseType()) { char[] sig = b.signature(); if (CharOperation.equals(sig, baseInt)) { return new ConstantExpression(((IntConstant) value).intValue()); } else { throw new GroovyEclipseBug("NYI for signature " + new String(sig)); } } else if (b.isClass()) { ClassExpression classExpression = new ClassExpression(resolver.convertToClassNode((TypeBinding) value)); return classExpression; } throw new GroovyEclipseBug( "Problem in JDTAnnotatioNode.createExpressionFor(binding=" + b + " value=" + value + ")"); }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public TypeBinding boxing(TypeBinding type) { if (type.isBaseType()) return environment().computeBoxingType(type); return type;//www . jav a2s . c om }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
/** * Internal use only//ww w . jav a2s.c om * Given a method, returns null if arguments cannot be converted to parameters. * Will answer a substituted method in case the method was generic and type inference got triggered; * in case the method was originally compatible, then simply answer it back. */ protected final MethodBinding computeCompatibleMethod(MethodBinding method, TypeBinding[] arguments, InvocationSite invocationSite) { TypeBinding[] genericTypeArguments = invocationSite.genericTypeArguments(); TypeBinding[] parameters = method.parameters; TypeVariableBinding[] typeVariables = method.typeVariables; if (parameters == arguments && (method.returnType.tagBits & TagBits.HasTypeVariable) == 0 && genericTypeArguments == null && typeVariables == Binding.NO_TYPE_VARIABLES) return method; int argLength = arguments.length; int paramLength = parameters.length; boolean isVarArgs = method.isVarargs(); if (argLength != paramLength) if (!isVarArgs || argLength < paramLength - 1) return null; // incompatible // https://bugs.eclipse.org/bugs/show_bug.cgi?id=330435, inference should kick in only at source 1.5+ if (typeVariables != Binding.NO_TYPE_VARIABLES && compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) { // generic method TypeBinding[] newArgs = null; for (int i = 0; i < argLength; i++) { TypeBinding param = i < paramLength ? parameters[i] : parameters[paramLength - 1]; if (arguments[i].isBaseType() != param.isBaseType()) { if (newArgs == null) { newArgs = new TypeBinding[argLength]; System.arraycopy(arguments, 0, newArgs, 0, argLength); } newArgs[i] = environment().computeBoxingType(arguments[i]); } } if (newArgs != null) arguments = newArgs; method = ParameterizedGenericMethodBinding.computeCompatibleMethod(method, arguments, this, invocationSite); if (method == null) return null; // incompatible if (!method.isValidBinding()) return method; // bound check issue is taking precedence } else if (genericTypeArguments != null && compilerOptions().complianceLevel < ClassFileConstants.JDK1_7) { if (method instanceof ParameterizedGenericMethodBinding) { if (!((ParameterizedGenericMethodBinding) method).wasInferred) // attempt to invoke generic method of raw type with type hints <String>foo() return new ProblemMethodBinding(method, method.selector, genericTypeArguments, ProblemReasons.TypeArgumentsForRawGenericMethod); } else if (!method.isOverriding() || !isOverriddenMethodGeneric(method)) { return new ProblemMethodBinding(method, method.selector, genericTypeArguments, ProblemReasons.TypeParameterArityMismatch); } } if (parameterCompatibilityLevel(method, arguments) > NOT_COMPATIBLE) { if ((method.tagBits & TagBits.AnnotationPolymorphicSignature) != 0) { // generate polymorphic method return this.environment().createPolymorphicMethod(method, arguments); } return method; } // if method is generic and type arguments have been supplied, only then answer a problem // of ParameterizedMethodTypeMismatch, else a non-generic method was invoked using type arguments // in which case this problem category will be bogus if (genericTypeArguments != null && typeVariables != Binding.NO_TYPE_VARIABLES) return new ProblemMethodBinding(method, method.selector, arguments, ProblemReasons.ParameterizedMethodTypeMismatch); return null; // incompatible }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public boolean isBoxingCompatibleWith(TypeBinding expressionType, TypeBinding targetType) { LookupEnvironment environment = environment(); if (environment.globalOptions.sourceLevel < ClassFileConstants.JDK1_5 || expressionType.isBaseType() == targetType.isBaseType()) return false; // check if autoboxed type is compatible TypeBinding convertedType = environment.computeBoxingType(expressionType); return convertedType == targetType || convertedType.isCompatibleWith(targetType); }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public boolean isPossibleSubtypeOfRawType(TypeBinding paramType) { TypeBinding t = paramType.leafComponentType(); if (t.isBaseType()) return false; ReferenceBinding currentType = (ReferenceBinding) t; ReferenceBinding[] interfacesToVisit = null; int nextPosition = 0; do {//ww w . j ava2s. co m if (currentType.isRawType()) return true; if (!currentType.isHierarchyConnected()) return true; // do not fault in super types right now, so assume one is a raw type ReferenceBinding[] itsInterfaces = currentType.superInterfaces(); if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) { if (interfacesToVisit == null) { interfacesToVisit = itsInterfaces; nextPosition = interfacesToVisit.length; } else { int itsLength = itsInterfaces.length; if (nextPosition + itsLength >= interfacesToVisit.length) System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition); nextInterface: for (int a = 0; a < itsLength; a++) { ReferenceBinding next = itsInterfaces[a]; for (int b = 0; b < nextPosition; b++) if (next == interfacesToVisit[b]) continue nextInterface; interfacesToVisit[nextPosition++] = next; } } } } while ((currentType = currentType.superclass()) != null); for (int i = 0; i < nextPosition; i++) { currentType = interfacesToVisit[i]; if (currentType.isRawType()) return true; ReferenceBinding[] itsInterfaces = currentType.superInterfaces(); if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) { int itsLength = itsInterfaces.length; if (nextPosition + itsLength >= interfacesToVisit.length) System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition); nextInterface: for (int a = 0; a < itsLength; a++) { ReferenceBinding next = itsInterfaces[a]; for (int b = 0; b < nextPosition; b++) if (next == interfacesToVisit[b]) continue nextInterface; interfacesToVisit[nextPosition++] = next; } } } return false; }