List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding notEquals
public static boolean notEquals(TypeBinding that, TypeBinding other)
From source file:org.eclipse.che.jdt.internal.core.search.matching.MethodLocator.java
License:Open Source License
private MethodBinding getMethodBinding(ReferenceBinding type, char[] methodName, TypeBinding[] argumentTypes) { MethodBinding[] methods = type.getMethods(methodName); MethodBinding method = null;/* w w w .j a v a 2 s. co m*/ methodsLoop: for (int i = 0, length = methods.length; i < length; i++) { method = methods[i]; TypeBinding[] parameters = method.parameters; if (argumentTypes.length == parameters.length) { for (int j = 0, l = parameters.length; j < l; j++) { if (TypeBinding.notEquals(parameters[j].erasure(), argumentTypes[j].erasure())) { continue methodsLoop; } } return method; } } return null; }
From source file:org.eclipse.che.jdt.internal.core.search.matching.MethodLocator.java
License:Open Source License
private boolean resolveLevelAsSuperInvocation(ReferenceBinding type, TypeBinding[] argumentTypes, char[][][] superTypeNames, boolean methodAlreadyVerified) { char[][] compoundName = type.compoundName; for (int i = 0, max = superTypeNames.length; i < max; i++) { if (CharOperation.equals(superTypeNames[i], compoundName)) { // need to verify if the type implements the pattern method if (methodAlreadyVerified) return true; // already verified before enter into this method (see resolveLevel(MessageSend)) MethodBinding[] methods = type.getMethods(this.pattern.selector); for (int j = 0, length = methods.length; j < length; j++) { MethodBinding method = methods[j]; TypeBinding[] parameters = method.parameters; if (argumentTypes.length == parameters.length) { boolean found = true; for (int k = 0, l = parameters.length; k < l; k++) { if (TypeBinding.notEquals(parameters[k].erasure(), argumentTypes[k].erasure())) { found = false; break; }/*www . ja v a 2 s .c o m*/ } if (found) { return true; } } } break; } } // If the given type is an interface then a common super interface may be found // in a parallel branch of the super hierarchy, so we need to verify all super interfaces. // If it's a class then there's only one possible branch for the hierarchy and // this branch has been already verified by the test above if (type.isInterface()) { ReferenceBinding[] interfaces = type.superInterfaces(); if (interfaces == null) return false; for (int i = 0; i < interfaces.length; i++) { if (resolveLevelAsSuperInvocation(interfaces[i], argumentTypes, superTypeNames, false)) { return true; } } } return false; }
From source file:org.eclipse.che.jdt.internal.core.search.matching.PatternLocator.java
License:Open Source License
protected void updateMatch(ParameterizedTypeBinding parameterizedBinding, char[][][] patternTypeArguments, boolean patternHasTypeParameters, int depth, MatchLocator locator) { // Only possible if locator has an unit scope. if (locator.unitScope == null) return;/*from w w w .j a v a2s. c o m*/ // Set match raw flag boolean endPattern = patternTypeArguments == null ? true : depth >= patternTypeArguments.length; TypeBinding[] argumentsBindings = parameterizedBinding.arguments; boolean isRaw = parameterizedBinding.isRawType() || (argumentsBindings == null && parameterizedBinding.genericType().isGenericType()); if (isRaw && !this.match.isRaw()) { this.match.setRaw(isRaw); } // Update match if (!endPattern && patternTypeArguments != null) { // verify if this is a reference to the generic type itself if (!isRaw && patternHasTypeParameters && argumentsBindings != null) { boolean needUpdate = false; TypeVariableBinding[] typeVariables = parameterizedBinding.genericType().typeVariables(); int length = argumentsBindings.length; if (length == typeVariables.length) { for (int i = 0; i < length; i++) { if (TypeBinding.notEquals(argumentsBindings[i], typeVariables[i])) { needUpdate = true; break; } } } if (needUpdate) { char[][] patternArguments = patternTypeArguments[depth]; updateMatch(argumentsBindings, locator, patternArguments, patternHasTypeParameters); } } else { char[][] patternArguments = patternTypeArguments[depth]; updateMatch(argumentsBindings, locator, patternArguments, patternHasTypeParameters); } } // Recurse TypeBinding enclosingType = parameterizedBinding.enclosingType(); if (enclosingType != null && (enclosingType.isParameterizedType() || enclosingType.isRawType())) { updateMatch((ParameterizedTypeBinding) enclosingType, patternTypeArguments, patternHasTypeParameters, depth + 1, locator); } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.AbstractMethodMappingDeclaration.java
License:Open Source License
public boolean checkVisibility(MethodSpec spec, ReferenceBinding baseType) { if (spec.isPrivate()) { if (TypeBinding.notEquals(baseType.getRealClass(), spec.getDeclaringClass())) { this.scope.problemReporter().mappingToInvisiblePrivate(spec, baseType, isCallin()); return false; // don't report decapsulation if this error is detected. }/*from ww w . j a v a 2 s. com*/ } spec.checkDecapsulation(baseType, this.scope); return true; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.CallinMappingDeclaration.java
License:Open Source License
/** * In this case: check match of "replace" and "callin" flags, plus static-ness * @param haveBaseMethods have base methods been resolved? * @param baseClass the role's bound base class *//* ww w . jav a 2 s. c o m*/ @Override protected void checkModifiers(boolean haveBaseMethods, ReferenceBinding baseClass) { if (this.ignoreFurtherInvestigation) // error was already flagged, i.e. missing replace return; // replace and callin matching: if (isReplaceCallin()) { if (!this.roleMethodSpec.resolvedMethod.isCallin()) { this.scope.problemReporter().replaceMappingToNonCallin(this.roleMethodSpec, this.roleMethodSpec.resolvedMethod); this.binding.tagBits |= TagBits.HasMappingIncompatibility; return; } } else { if (this.roleMethodSpec.resolvedMethod.isCallin()) { this.scope.problemReporter().callinMethodBoundNonReplace(this.roleMethodSpec, this); this.binding.tagBits |= TagBits.HasMappingIncompatibility; return; } } if (haveBaseMethods) { // static non-static consistency: if (!this.roleMethodSpec.resolvedMethod.isStatic()) { for (int i = 0; i < this.baseMethodSpecs.length; i++) { this.baseMethodSpecs[i].checkStaticness(this, false); } } if (isReplaceCallin()) { if (this.roleMethodSpec.resolvedMethod.isStatic()) { for (int i = 0; i < this.baseMethodSpecs.length; i++) { this.baseMethodSpecs[i].checkStaticness(this, true); } } } // callin-to-final? respect OTJLD 4.1(f) for (int i = 0; i < this.baseMethodSpecs.length; i++) { MethodBinding baseMethod = this.baseMethodSpecs[i].resolvedMethod; if (baseMethod != null) { if (baseMethod.isFinal()) { if (TypeBinding.notEquals(baseMethod.declaringClass, baseClass)) { this.scope.problemReporter().bindingToInheritedFinal(this.baseMethodSpecs[i], baseMethod, baseClass); this.binding.tagBits |= TagBits.HasMappingIncompatibility; } } if (baseMethod.isConstructor()) { if (this.callinModifier != TokenNameafter) { this.scope.problemReporter().callinToCtorMustBeAfter(this.baseMethodSpecs[i], baseMethod); this.binding.tagBits |= TagBits.HasMappingIncompatibility; } } } } } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.CalloutMappingDeclaration.java
License:Open Source License
@Override protected void checkModifiers(boolean haveBaseMethods, ReferenceBinding baseType) { boolean roleHasImplementation = false; MethodBinding roleMethod = this.roleMethodSpec.resolvedMethod; if (!roleMethod.isValidBinding()) return;/*from w w w . java 2 s .c om*/ // update modifiers after tsuper has generated callout methods (perhaps giving implementation to abstract decl) if (roleMethod.isAbstract() && roleMethod.copyInheritanceSrc != null && !roleMethod.copyInheritanceSrc.isAbstract()) roleMethod.modifiers &= ~ClassFileConstants.AccAbstract; roleHasImplementation = !roleMethod.isAbstract() && !roleMethod.isDefaultMethod(); if (roleHasImplementation != isCalloutOverride()) { if (roleHasImplementation) { if (isCalloutMethod(roleMethod)) { if (TypeBinding.notEquals(roleMethod.declaringClass, this.scope.enclosingSourceType()) || roleMethod.copyInheritanceSrc != null) // "local" callouts (not copied) are treated in { // MethodMappingResolver.checkForDuplicateMethodMappings() this.scope.problemReporter().regularCalloutOverridesCallout(this, roleMethod); } } else { this.scope.problemReporter().regularCalloutOverrides(this); } } else // isCalloutOverride() but not really overriding { this.scope.problemReporter().abstractMethodBoundAsOverrideCallout(this); AbstractMethodDeclaration roleMethodDeclaration = roleMethod.sourceMethod(); if (roleMethodDeclaration != null) { roleMethodDeclaration.ignoreFurtherInvestigation = true; this.ignoreFurtherInvestigation = true; } } } if (roleMethod.isCallin()) { this.scope.problemReporter().calloutBindingCallin(this.roleMethodSpec); } if (hasErrors()) { // unsuccessful attempt to implement role method as callout, // mark the method as erroneous: if (this.roleMethodSpec.resolvedMethod != null && this.roleMethodSpec.resolvedMethod.isAbstract()) { AbstractMethodDeclaration methodDecl = this.roleMethodSpec.resolvedMethod.sourceMethod(); if (methodDecl != null) methodDecl.tagAsHavingErrors(); // prevent abstract-error } } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.PotentialTranslationExpression.java
License:Open Source License
/** * Check whether rawType is already compatible perhaps using basic type conversion * @param scope/*w ww.ja v a 2 s. c o m*/ * @param rawType * @return the compatible type */ protected TypeBinding compatibleType(BlockScope scope, TypeBinding rawType) { // save and reset flags: Config oldConfig = Config.createOrResetConfig(this); try { if (areTypesCompatible(rawType, this.expectedType)) { if (!Config.requireTypeAdjustment()) { // TODO (SH) is conversion of arrays of base type allowed? TypeBinding resultType = this.resolvedType; // default if (this.resolvedType.isBaseType()) { if (TypeBinding.notEquals(rawType, this.expectedType)) { this.rawExpression = this.expression; this.rawExpression.computeConversion(scope, rawType, rawType); // null conversion. this.expression = new CastExpression(this.expression, TypeReference.baseTypeReference(this.expectedType.id, 0, null)); this.expression.constant = Constant.NotAConstant; ((CastExpression) this.expression).checkCastTypesCompatibility(scope, this.expectedType, rawType, this.expression); this.operator = "(convert to " + new String(this.expectedType.readableName()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ resultType = this.expectedType; } } if (BaseTypeBinding.isWidening(this.expectedType.id, rawType.id) && this.expression.constant != Constant.NotAConstant) this.expression.computeConversion(scope, this.expectedType, rawType); return resultType; } } } finally { // restore on any exit: Config.removeOrRestore(oldConfig, this); } return null; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.BytecodeTransformer.java
License:Open Source License
/** * When generating code for a role class, copy all non-wide string/integer constants * from all tsuper roles in order to reserve constant pool positions below 256. * Note, that this strategy is not safe, since multiple tsupers may introduce any * number of constants below 256 :(/* w w w . j a v a2 s . c o m*/ */ public void checkCopyNonWideConstants(Scope scope, ClassFile classFile) { SourceTypeBinding dstType = classFile.referenceBinding; this._writer = new ConstantPoolObjectWriter(classFile); if (dstType.isRole() && !dstType.isInterface()) // for all role classes { ReferenceBinding[] tsuperRoles = dstType.roleModel.getTSuperRoleBindings(); for (int i = 0; i < tsuperRoles.length; i++) // for all tsuper roles { RoleModel srcRole = tsuperRoles[i].roleModel; if (srcRole == null || !srcRole.hasByteCode()) continue; byte[] srcConstantPool = srcRole.getByteCode(); if (srcConstantPool == null) continue; // be shy, no idea how it could happen this._reader = new ConstantPoolObjectReader(srcRole, srcConstantPool, scope.environment()); copyAllNonWideConstants(srcRole.getConstantPoolOffsets().length, srcRole.getBinding().enclosingType(), dstType); } } if (dstType.isTeam()) { ReferenceBinding orgObjectteamsTeam = scope.getOrgObjectteamsTeam(); if (!TypeAnalyzer.isOrgObjectteamsTeam(dstType) && !dstType.superclass.isTeam()) { TeamMethodGenerator tmg = scope.environment().getTeamMethodGenerator(); if (tmg.requestBytes()) { // if o.o.Team is converted we don't have the bytecode - and shouldn't need it this._reader = new ConstantPoolObjectReader(tmg.classBytes, tmg.constantPoolOffsets, orgObjectteamsTeam.getTeamModel(), scope.environment()); copyAllNonWideConstants(tmg.constantPoolOffsets.length, dstType.superclass, dstType); } } TeamModel srcModel = dstType.superclass.getTeamModel(); if (srcModel == null) return; // if the team has a copied ctor (w/ arg-lifting), bytecodes // for the team need to be copied from the super-team, too: for (MethodBinding method : dstType.methods()) { method = method.copyInheritanceSrc; if (method == null || method.model == null) continue; // shouldn't happen anyway TeamModel methodSrcTeam = srcModel; if (TypeBinding.notEquals(method.declaringClass, srcModel.getBinding())) { // copied from implicit super team - find the source: if (!method.declaringClass.isTeam()) continue; methodSrcTeam = method.declaringClass.getTeamModel(); } if (!method.model.hasBytes()) continue; // method not relevant for copying this._reader = new ConstantPoolObjectReader(method.model, methodSrcTeam, scope.environment()); copyAllNonWideConstants(method.model.getConstantPoolOffsets().length, methodSrcTeam.getBinding(), dstType); return; // triggered by any method, this team class is fully handled. } } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.CallinPrecedenceAttribute.java
License:Open Source License
/** * Prepend type path to callin when looking from site. * @param site/*from w w w . ja v a 2s . c o m*/ * @param callinBinding * @return a '.' separated path */ private char[] getQualifiedName(ReferenceBinding site, CallinCalloutBinding callinBinding) { String name = new String(callinBinding.name); ReferenceBinding current = callinBinding.introducingRoleClass(); while (current != null && TypeBinding.notEquals(current, site)) { name = new String(current.sourceName()) + '.' + name; current = current.enclosingType(); } return name.toCharArray(); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectMapper.java
License:Open Source License
/** * This method realizes the logic of the mapping for fields. * @param srcMethod where to copy from * @param refFieldBinding what to copy/remap * @param dstTeam where to copy to * @return destination field//from ww w . j a v a 2s . c om */ public static FieldBinding mapField(MethodBinding srcMethod, FieldBinding refFieldBinding, ReferenceBinding dstTeam) { // if Binding points at Role-Field of Superteamclass, then mapping must be done if (dstTeam != null) { if (isMappableField(refFieldBinding)) { if (refFieldBinding.isSynthetic()) { RoleModel role = ((ReferenceBinding) mapClass(srcMethod, refFieldBinding.declaringClass, dstTeam)).roleModel; if (role != null) { FieldBinding dstField = role.mapSyntheticField(refFieldBinding); if (dstField != null) return dstField; } } ReferenceBinding refTeamBinding = getTeam(refFieldBinding); if (refTeamBinding != null) { ReferenceBinding srcTeamBinding = getTeam(srcMethod); if (srcTeamBinding != null) { if (TypeBinding.equalsEquals(refTeamBinding, srcTeamBinding)) { FieldBinding newBinding = searchRoleField(refFieldBinding, dstTeam); if (newBinding != null && TypeBinding.notEquals(newBinding.declaringClass, dstTeam) && !TeamModel.isTeamContainingRole(dstTeam, newBinding.declaringClass)) { // field is declared neither in dstTeam nor one of its roles. // find the class, that corresponds to the field's declaring class: ReferenceBinding updatedClass = (ReferenceBinding) mapClass(srcMethod, newBinding.declaringClass, dstTeam); // update field binding to new declaring class? if (TypeBinding.notEquals(newBinding.declaringClass, updatedClass)) newBinding = new FieldBinding(newBinding, updatedClass); } return newBinding; } } } } } return refFieldBinding; }