List of usage examples for org.eclipse.jdt.internal.compiler.lookup ExtraCompilerModifiers AccVisibilityMASK
int AccVisibilityMASK
To view the source code for org.eclipse.jdt.internal.compiler.lookup ExtraCompilerModifiers AccVisibilityMASK.
Click Source Link
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.AbstractMethodMappingDeclaration.java
License:Open Source License
public void resolveMethodSpecs(RoleModel role, ReferenceBinding baseType, boolean resolveBaseMethods) { /*/* w w w . j a v a 2s. c o m*/ * CallinImplementor will generate one wrapper for each base method. * (optimize: one for each signature) */ // 1. resolve types in signatures MethodSpec[] baseMethodSpecs = getBaseMethodSpecs(); if (this.roleMethodSpec != null) { this.roleMethodSpec.resolveTypes(this.scope, false/*isBaseSide*/); // notify parameter mappings: if (isCallin() && this.mappings != null) for (ParameterMapping map : this.mappings) map.argumentsResolved(this.roleMethodSpec); } for (int i = 0; i < baseMethodSpecs.length; i++) { MethodSpec spec = baseMethodSpecs[i]; // don't fill scope (would lead to clashes!), but create a new one: CallinCalloutScope tmpScope = new CallinCalloutScope(this.scope.classScope(), this.scope.referenceContext); spec.resolveTypes(tmpScope, true/*isBaseSide*/); // notify parameter mappings: if (isCallout() && this.mappings != null) for (ParameterMapping map : this.mappings) map.argumentsResolved(spec); } // 2. find role methods .. boolean roleOK = true; if (!this.hasSignature) { // 2a. .. by name only // Note(SH): we need the class part to detect overriding // but than we have difficulties finding the correct modifiers :( ReferenceBinding receiverType = role.isRegularInterface() ? role.getBinding() : role.getClassPartBinding(); this.roleMethodSpec.resolveFeature(receiverType, this.scope, isReplaceCallin(), /*isBaseSide*/false, /*allowEnclosing*/(isCallin() && !isReplaceCallin())); this.roleMethodSpec.checkResolutionSuccess(role.getBinding(), this.scope); } else { // 2b. .. by name and signature for (int i = 0; i < this.roleMethodSpec.parameters.length; i++) { this.roleMethodSpec.parameters[i] = RoleTypeCreator.maybeWrapUnqualifiedRoleType(this.scope, this.roleMethodSpec.parameters[i], this.roleMethodSpec.arguments[i]); } boolean hasEarlyError = this.ignoreFurtherInvestigation; this.roleMethodSpec.resolveFeatureWithArgMapping(role.getBinding(), this.scope, /*isBaseSide*/false, isReplaceCallin(), /*allowEnclosing*/(isCallin() && !isReplaceCallin())); boolean reportedRoleMethodError = !hasEarlyError && this.ignoreFurtherInvestigation; boolean calloutMissingRoleMethod = false; if (isCallout() && this.roleMethodSpec.problemId() == ProblemReasons.NotFound) { calloutMissingRoleMethod = true; // we know we have a signature, repair the return type in the problem binding: this.roleMethodSpec.resolvedMethod.returnType = this.roleMethodSpec.returnType.resolvedType; } if (!this.roleMethodSpec.isValid() && !reportedRoleMethodError && !calloutMissingRoleMethod) { this.scope.problemReporter().boundMethodProblem(this.roleMethodSpec, role.getBinding(), isCallout()); roleOK = false; } else { // TODO (SH): should we wrap roleMethodSpec.returnType here?? // (checkReturnType falsely fails in GebitDispo). roleOK = !reportedRoleMethodError && this.roleMethodSpec.checkParameterTypes(this.scope, false) && this.roleMethodSpec.checkRoleReturnType(this.scope, isCallout()); } } // 3. find base methods: if (resolveBaseMethods) { if (getBaseMethodSpecs().length == 0) { // need to recover missing base method spec: Parser parser = Config.getParser(); // this could dispatch to the CompletionParser: MethodSpec baseMethodSpec = parser.recoverMissingBaseMethodSpec(this, role); if (baseMethodSpec.selector.length == 0) resolveBaseMethods = false; // prevent further analysis below. if (isCallout()) ((CalloutMappingDeclaration) this).baseMethodSpec = baseMethodSpec; else ((CallinMappingDeclaration) this).baseMethodSpecs = new MethodSpec[] { baseMethodSpec }; } if (baseType != null) { if (!this.hasSignature) { for (int i = 0; i < baseMethodSpecs.length; i++) { MethodSpec methodSpec = baseMethodSpecs[i]; methodSpec.resolveFeature(baseType, this.scope, /*expectingCallin*/false, /*isBaseSide*/true, /*allowEnclosing*/false); methodSpec.checkResolutionSuccess(baseType, this.scope); if (this.roleMethodSpec.isValid() && methodSpec.isValid()) { if (methodSpec instanceof FieldAccessSpec) { ((CalloutMappingDeclaration) this) .checkTypeCompatibility((FieldAccessSpec) methodSpec); } else { checkParametersCompatibility(methodSpec); checkReturnCompatibility(methodSpec); } checkVisibility(methodSpec, baseType); checkThrownExceptions(methodSpec); } } } else { // for now pretend all base classes are public/visible: int baseTypeModifiers = baseType.modifiers; baseType.modifiers &= ~ExtraCompilerModifiers.AccVisibilityMASK; baseType.modifiers |= ClassFileConstants.AccPublic; try { for (int i = 0; i < baseMethodSpecs.length; i++) { MethodSpec methodSpec = baseMethodSpecs[i]; methodSpec.resolveFeatureWithArgMapping(baseType, this.scope, /*isBaseSide*/true, /*callinExpected*/false, /*allowEnclosing*/false); if (!methodSpec.isValid()) { if (methodSpec.problemId() == ProblemReasons.NotVisible && canAccessInvisibleBase()) { methodSpec.resolvedMethod = ((ProblemMethodBinding) methodSpec.resolvedMethod).closestMatch; } else { this.scope.problemReporter().boundMethodProblem(methodSpec, baseType, isCallout()); continue; } } if (!methodSpec.checkBaseReturnType(this.scope, isCallin() ? TokenNameBINDOUT : TokenNameBINDIN) || !methodSpec.checkParameterTypes(this.scope, true)) continue; // translation bits are already initialized in the constructor of MethodSpec. if (roleOK) { if (this.mappings == null && this.hasParsedParamMappings) { if (methodSpec instanceof FieldAccessSpec) { ((CalloutMappingDeclaration) this) .checkTypeCompatibility((FieldAccessSpec) methodSpec); } else { checkParametersCompatibility(methodSpec); checkReturnCompatibility(methodSpec); } // if we have mappings, type checking needs to be deferred.. // or if we have problems or haven't parsed mappings skip these checks altogether } else { checkResult(methodSpec); } } // check these in both cases (?) checkVisibility(methodSpec, baseType); checkThrownExceptions(methodSpec); } } finally { baseType.modifiers = baseTypeModifiers; } } } } // 4. generally: checkModifiers(resolveBaseMethods, baseType); //{OTDTUI : SelectionOnMethodSpec needs to be informed! Is this the right location ? this.roleMethodSpec.resolveFinished(); for (int idx = 0; idx < baseMethodSpecs.length; idx++) { if (isCallin()) if (baseMethodSpecs[idx].resolvedMethod != null && baseMethodSpecs[idx].resolvedMethod.isDeprecated()) this.scope.problemReporter().callinToDeprecated(baseMethodSpecs[idx], baseMethodSpecs[idx].resolvedMethod); baseMethodSpecs[idx].resolveFinished(); } //haebor} if (this.hasSignature && this.mappings != null) { // Make simple param mappings a->x, b<-y propagate best names. // Currently no bindings exist to propagate, // so wrap the SimpleNameReference to do the propagation after it has been resolved. MethodSpec implSpec = getImplementationMethodSpec(); if (implSpec.arguments != null) { // check each parameter mapping: for (ParameterMapping mapping : this.mappings) if (mapping.expression instanceof SingleNameReference) { // for each simple mappling find the corresponding argument: char[] token = ((SingleNameReference) mapping.expression).token; long pos = (((long) mapping.expression.sourceStart) << 32) + mapping.expression.sourceEnd; for (final Argument arg : implSpec.arguments) if (CharOperation.equals(arg.name, token)) { // found; is it possibly a team anchor? if (arg.binding != null && arg.binding.couldBeTeamAnchor()) { // yes, so we need a wrapper: Expression wrappedExpr = new SingleNameReference(token, pos) { @Override public TypeBinding resolveType(BlockScope blockScope) { TypeBinding result = super.resolveType(blockScope); if (this.binding instanceof ITeamAnchor) if (((ITeamAnchor) this.binding).isValidAnchor()) arg.binding.shareBestName((ITeamAnchor) this.binding); return result; } }; if (this.mappingExpressions != null) { // also update in mappingExpressions (have different order there): for (int i = 0; i < this.mappingExpressions.length; i++) { Pair<Expression, Integer> pair = this.mappingExpressions[i]; if (pair.first == mapping.expression) { pair.first = wrappedExpr; break; } } } mapping.expression = wrappedExpr; } break; // done with this mapping } } } } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.WordValueAttribute.java
License:Open Source License
public static void readRoleClassMethodModifiersAttribute(MethodInfo info, int readOffset) { int binaryFlags = info.getModifiers() & ~ExtraCompilerModifiers.AccVisibilityMASK; // reset these bits first int newFlags = info.u2At(readOffset); info.setAccessFlags(binaryFlags | newFlags); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CalloutImplementor.java
License:Open Source License
private MethodDeclaration createAbstractRoleMethodDeclaration(MethodBinding templateBinding, CalloutMappingDeclaration calloutBindingDeclaration) { IProtectable baseFeature = null;/* ww w . j a v a2s.c o m*/ MethodSpec baseMethodSpec = calloutBindingDeclaration.baseMethodSpec; if (baseMethodSpec != null) // else syntax error? baseFeature = calloutBindingDeclaration.isCalloutToField() ? ((FieldAccessSpec) baseMethodSpec).resolvedField : baseMethodSpec.resolvedMethod; int modifiers = calloutBindingDeclaration.declaredModifiers; if (modifiers == 0) { // no modifiers declared in callout, look for base feature, last is the role method template modifiers = ((baseFeature != null) && (templateBinding.modifiers == 0)) ? baseFeature.modifiers() : templateBinding.modifiers; modifiers &= (ExtraCompilerModifiers.AccVisibilityMASK | AccStatic); } boolean isOverridingVisibility = calloutBindingDeclaration.isCalloutOverride() && (calloutBindingDeclaration.declaredModifiers != 0); if (templateBinding.isValidBinding() // short-hand callout has a Problem(NotFound) here && templateBinding.declaringClass.isRole()) { // try to find the ifc-part for 'templateBinding', // if found, use its visibility modifiers for the new method declaration, // because class part visibility modifiers are actually useless (always public..) ReferenceBinding ifcPart = templateBinding.declaringClass.roleModel.getInterfacePartBinding(); if (ifcPart != null) { MethodBinding ifcMethod = TypeAnalyzer.findMethod(calloutBindingDeclaration.scope, ifcPart, templateBinding.selector, templateBinding.parameters); if (ifcMethod != null && ifcMethod.isValidBinding()) { if (!isOverridingVisibility) { // no modifiers in callout, use interface modifiers of found role method: modifiers &= ~ExtraCompilerModifiers.AccVisibilityMASK; modifiers |= ifcMethod.modifiers & ExtraCompilerModifiers.AccVisibilityMASK; } } } } // overriding an method explicitly inherited from non-role superclass? (see TPX-416) boolean overridesExplicitNonRole = false; ReferenceBinding superRole = null; ReferenceBinding roleClass = this._role.getClassPartBinding(); if (roleClass != null) { superRole = roleClass.superclass(); if (superRole != null // have a super class && TypeBinding.notEquals(superRole.enclosingType(), roleClass.enclosingType())) // not a role from current team { MethodBinding superMethod = TypeAnalyzer.findMethod(calloutBindingDeclaration.scope, superRole, templateBinding.selector, templateBinding.parameters); if (superMethod != null && superMethod.isValidBinding()) overridesExplicitNonRole = true; // TODO(SH): need compatibility checks? (a la MethodVerifier??) } } if (calloutBindingDeclaration.binding.inferred == InferenceKind.NONE) { // don't advertise inferred callout via the interface. if (templateBinding.isStatic()) // no real ifc part for static method, fake it! createInterfaceFakeStatic(templateBinding, calloutBindingDeclaration); else if (((modifiers & AccPrivate) == 0) && !overridesExplicitNonRole) // also no ifc part for privates and methods from explicit non-role super createAbstractRoleMethodDeclarationPart(templateBinding, calloutBindingDeclaration, modifiers, INTERFACE); } return createAbstractRoleMethodDeclarationPart(templateBinding, calloutBindingDeclaration, modifiers, CLASS); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel.java
License:Open Source License
private int rewriteModifiersForBytecode() { if (this._attributes != null) for (AbstractAttribute attr : this._attributes) { if (attr.nameEquals(IOTConstants.MODIFIERS_NAME) || attr.nameEquals(IOTConstants.ROLECLASS_METHOD_MODIFIERS_NAME)) { int flags = this._binding.modifiers; int MASK = ExtraCompilerModifiers.AccVisibilityMASK; if (this._binding.declaringClass.isSynthInterface()) { // ifc part: no static methods allowed: MASK |= ClassFileConstants.AccStatic; } else { // class part: no abstract static methods allowed, remove abstract. int abstractStatic = ClassFileConstants.AccAbstract | ClassFileConstants.AccStatic; if ((flags & abstractStatic) == abstractStatic) MASK |= ClassFileConstants.AccAbstract; }/*ww w.ja va 2 s . com*/ flags &= ~MASK; flags |= ClassFileConstants.AccPublic; return flags; } } return -1; }