List of usage examples for org.eclipse.jdt.internal.compiler.ast Expression isTypeReference
public boolean isTypeReference()
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.PredicateGenerator.java
License:Open Source License
/** * @param predicateMethodName/*from w w w.j a v a2 s. co m*/ * @param params * @param target * @param outer * @param gen * @return an if-statement */ private Statement genSinglePredicateCheck(char[] predicateMethodName, Expression[] params, Expression target, boolean outer, AstGenerator gen) { AstGenerator skipGen = new AstGenerator(STEP_OVER_SOURCEPOSITION_START, STEP_OVER_SOURCEPOSITION_END); return gen.stealthIfNotStatement( gen.messageSend(outer ? (Reference) gen.thisReference() : target, predicateMethodName, params), genVetoStatement(skipGen, target.isTypeReference() ? skipGen.nullLiteral() : target)); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator.java
License:Open Source License
/** * Extract a variable binding from an expression, which is * suitable as an anchor for a role type. * * Note, that checking for final is not done here! * * @param site context for type name resolution * @param anchorExpr should refer to a (final) variable holding a Team instance * @param roleType Use this if the anchor expression is 'this' to * retrieve the appropriate tthis binding. * @param problemReporter for error reporting or null (no reporting) * @param typedNode expression whose type is currently being resolved (only for error positions) * @return a valid anchor or NoAnchor(reported via cannotWrap) or null (also reported) *///from w w w. ja va2s . c om public static ITeamAnchor getAnchorVariableBinding(ReferenceBinding site, /*nonnull*/ Expression anchorExpr, ReferenceBinding roleType, ProblemReporter problemReporter, ASTNode typedNode) { ITeamAnchor anchorBinding = null; // unwrap meaningless cast: if (anchorExpr instanceof CastExpression) { CastExpression cast = (CastExpression) anchorExpr; if (RoleTypeBinding.isRoleWithExplicitAnchor(cast.resolvedType)) anchorBinding = ((RoleTypeBinding) cast.resolvedType)._teamAnchor; else anchorExpr = ((CastExpression) anchorExpr).expression; } if (anchorExpr instanceof PotentialLowerExpression) anchorExpr = ((PotentialLowerExpression) anchorExpr).expression; if (anchorExpr instanceof ThisReference) { ReferenceBinding teamBinding = (ReferenceBinding) anchorExpr.resolvedType; ReferenceBinding enclosingTeam = TeamModel.findEnclosingTeamContainingRole(teamBinding, roleType); if (enclosingTeam == null) { if ((problemReporter != null)) { ASTNode location = anchorExpr; if (location.sourceEnd == 0) location = typedNode; problemReporter.typeAnchorNotEnclosingTeam(location, teamBinding, roleType); } return null; } anchorBinding = TThisBinding.getTThisForRole(roleType, enclosingTeam); if (anchorBinding == null) return cannotWrapType(roleType, problemReporter, typedNode); } else { // extract the name reference from a type anchor reference used as expression: if (anchorExpr instanceof TypeAnchorReference && ((TypeAnchorReference) anchorExpr).isExpression) { anchorExpr = ((TypeAnchorReference) anchorExpr).anchor; } if (anchorExpr instanceof ArrayReference) anchorExpr = ((ArrayReference) anchorExpr).receiver; if (anchorExpr instanceof FieldReference) { anchorBinding = ((Reference) anchorExpr).fieldBinding(); } else if (anchorExpr.isTypeReference()) { anchorBinding = null; // not an instance: not usable. ReferenceBinding teamBinding = TeamModel.findEnclosingTeamContainingRole(site, roleType); if (teamBinding == null) { if ((problemReporter != null)) problemReporter.missingTypeAnchor(anchorExpr, roleType); return null; } anchorBinding = TThisBinding.getTThisForRole(roleType, teamBinding); if (anchorBinding == null) { if ((problemReporter != null)) problemReporter.typeAnchorIsNotAVariable(anchorExpr, roleType.sourceName()); return null; } } else if (anchorExpr instanceof NameReference) { if (anchorExpr instanceof QualifiedNameReference) { QualifiedNameReference qRef = (QualifiedNameReference) anchorExpr; anchorBinding = getAnchorFromQualifiedReceiver(site, roleType, (VariableBinding) qRef.binding, qRef.otherBindings, /*mergePaths*/false, problemReporter, anchorExpr, qRef.sourcePositions); if (anchorBinding == null) return RoleTypeBinding.NoAnchor; // already reported } else { if (((NameReference) anchorExpr).binding instanceof VariableBinding) { anchorBinding = (ITeamAnchor) ((NameReference) anchorExpr).binding; if (roleType.isTypeVariable()) { ITeamAnchor[] anchors = ((TypeVariableBinding) roleType).anchors; if (anchors != null) return anchorBinding; // avoid analysis which requires knowledge about the role type } // FIXME(SH): manual resolving of base-anchor? // if (CharOperation.equals(((SingleNameReference)anchorExpr).token, IOTConstants._OT_BASE)) // { // ReferenceBinding anchorSite = ((FieldBinding)anchorBinding).declaringClass; // if ( anchorSite != site && // site.isCompatibleWith(anchorSite)) { // anchorBinding = new FieldBinding((FieldBinding)anchorBinding, site); // ((FieldBinding)anchorBinding).type = site.baseclass(); // } // } } else { if ((problemReporter != null)) problemReporter.typeAnchorIsNotAVariable(anchorExpr, roleType.sourceName()); return null; } } } else if (anchorExpr instanceof QualifiedAllocationExpression) { // propagate anchor from resolved type: QualifiedAllocationExpression allocation = (QualifiedAllocationExpression) anchorExpr; return ((RoleTypeBinding) allocation.resolvedType)._teamAnchor; } else if (anchorExpr instanceof MessageSend) { TypeBinding receiverLeaf = ((MessageSend) anchorExpr).actualReceiverType.leafComponentType(); if (RoleTypeBinding.isRoleWithExplicitAnchor(receiverLeaf)) { anchorBinding = ((RoleTypeBinding) receiverLeaf)._teamAnchor; } else { // regression fix during work on https://bugs.eclipse.org/331877 if (anchorExpr.resolvedType != null && anchorExpr.resolvedType.isRoleType()) return ((DependentTypeBinding) anchorExpr.resolvedType)._teamAnchor; return cannotWrapType(roleType, problemReporter, typedNode); } } else if (anchorExpr instanceof AllocationExpression) { // this anchor matches nothing String displayName = "fresh-instance-of-" + ((AllocationExpression) anchorExpr).type.toString(); //$NON-NLS-1$ LocalVariableBinding fakeVariable = new LocalVariableBinding(displayName.toCharArray(), roleType.enclosingType(), ClassFileConstants.AccFinal, false); fakeVariable.tagBits |= TagBits.IsFreshTeamInstance; return fakeVariable; } else if (anchorBinding == null) { return cannotWrapType(roleType, problemReporter, typedNode); } /* * anchorBinding = non-null * FieldReference * NameReference * isTypeReference() -> TThisBinding */ assert (anchorBinding != null); } /* * variableBinding = non-null, anchorType = non-null: * ThisReference * + all others that did not already quit with an error. */ // if ((problemReporter != null)) // assert anchorBinding != null; // redundant if (!anchorBinding.isTeamContainingRole(roleType)) { anchorBinding = anchorBinding.retrieveAnchorFromAnchorRoleTypeFor(roleType); if (anchorBinding == null) { if (roleType instanceof DependentTypeBinding && ((DependentTypeBinding) roleType).hasExplicitAnchor()) return cannotWrapType(roleType, problemReporter, typedNode); // not improved ReferenceBinding teamBinding = TeamModel.findEnclosingTeamContainingRole(site, roleType); if (teamBinding == null) return cannotWrapType(roleType, problemReporter, typedNode); anchorBinding = TThisBinding.getTThisForRole(roleType, teamBinding); } } assert (anchorBinding != null); return anchorBinding.asAnchorFor(roleType); }