List of usage examples for org.eclipse.jdt.internal.compiler.lookup MethodScope problemReporter
@Override
public ProblemReporter problemReporter()
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator.java
License:Open Source License
/** * Try to resolve an argument or return type as an anchored type. * * PRE: Regular type resolution has already failed. * * Currently only handles references of two components: anchor and Type. * (for parameters this is probably OK?) * NO: TODO(SH): arguments could also be anchored to arbitrary expressions/paths! * * @param type type reference to be analyzed (resolvedType is null or invalid) * @param arguments the arguments of the current method * @param index position of the argument to be analyzed * == arguments.length means: analyzing return type. * @param scope scope of the current method. * @return a RoleTypeBinding or null (after reporting error) */// w w w . ja v a 2s . c o m public static TypeBinding getTypeAnchoredToParameter(TypeReference type, Argument[] arguments, int index, MethodScope scope, CheckPoint cp) { // we only handle QualifiedTypeReferences of length 2, or QualifiedArrayTypeReferences. if (!(type instanceof QualifiedTypeReference)) { return null; // not better than before } QualifiedTypeReference argType = (QualifiedTypeReference) type; // look for anchor in argument list: VariableBinding anchor = null; char[] anchorName = argType.tokens[0]; int argPos; for (argPos = 0; argPos < index; argPos++) { Argument argument = arguments[argPos]; // ensure arguments are bound, which must happen in correct order. argument.bind(scope, argument.type.resolvedType, /*used*/false); if (CharOperation.equals(argument.name, anchorName)) // compare possible anchor { argument.binding.useFlag = LocalVariableBinding.USED; // used as anchor anchor = argument.binding; if (scope.classScope().referenceContext.isConverted) anchor.modifiers |= ClassFileConstants.AccFinal; // lost during conversion. break; } } if (anchor == null) { argPos = -1; // mark as not found in argument list anchor = findAnchorInScope(scope, anchorName); } if (anchor == null) return null; // not better than before. if (!anchor.isFinal()) { char[][] typeName = type.getTypeName(); scope.problemReporter().anchorPathNotFinal(argType, anchor, typeName[typeName.length - 1]); return null; } // defensive programming: if (anchor.type == null) return null; // anchor must be a team: if (!anchor.type.isTeam()) { if (!anchor.type.isValidBinding()) return null; //can't decide whether this is a valid team or not. reportAnchorIsNotATeam(scope, argType); return null; } // delegate for role type lookup: TypeBinding anchoredType = resolveOtherPathElements(scope, type, anchor, argType.tokens, 1, argType.dimensions()); if (anchoredType != null) { if (!anchoredType.isValidBinding()) { scope.problemReporter().invalidType(type, anchoredType); return null; } if (anchoredType.leafComponentType().isRoleType()) { // prepare for creating an AnchorListAttribute RoleTypeBinding leafRoleType = (RoleTypeBinding) anchoredType.leafComponentType(); leafRoleType._argumentPosition = argPos; final AbstractMethodDeclaration methodDecl = scope.referenceMethod(); leafRoleType._declaringMethod = new DependentTypeBinding.IMethodProvider() { public MethodBinding getMethod() { return methodDecl.binding; } }; } scope.referenceContext.compilationResult().rollBack(cp); scope.problemReporter().deprecatedPathSyntax(type); } return anchoredType; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator.java
License:Open Source License
/** * Retrieve the team anchor representing a specific method argument * @param method use this method's arguments * @param anchorArgPos position within the method's argument list * @return a valid team anchor or a ProblemAnchorBinding or null; *//*from w w w. ja v a 2 s . c o m*/ public static ITeamAnchor resolveTypeAnchoredToArgument(AbstractMethodDeclaration method, int anchorArgPos) { MethodScope scope = method.scope; Argument[] arguments = method.arguments; // ensure arguments upto the anchor are bound, which must happen in correct order: for (int i = 0; i <= anchorArgPos; i++) arguments[i].bind(scope, arguments[i].type.resolvedType, /*used*/i == anchorArgPos); TeamAnchor anchor = arguments[anchorArgPos].binding; // SH: bounds check? ((LocalVariableBinding) anchor).resolvedPosition = anchorArgPos; // check anchor for error if (anchor == null) return null; if (!anchor.isFinal() && !isConvertedArgument(anchor, scope)) { return new ProblemAnchorBinding(anchor, ProblemReasons.AnchorNotFinal); } // check anchor.type: if (anchor.type == null) return null; // anchor must be a team: if (!anchor.type.isTeam()) { if (anchor.type.isValidBinding()) //otherwise we can't decide whether this is a valid team or not. scope.problemReporter().illegalTypeAnchorNotATeam(arguments[anchorArgPos]); return null; } return anchor; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator.java
License:Open Source License
private static void reportAnchorIsNotATeam(MethodScope scope, QualifiedTypeReference argType) { // extract all but the last element from typeReference (which yields the anchor): char[][] tokens = CharOperation.subarray(argType.tokens, 0, argType.tokens.length - 1); long[] sourcePositions = new long[tokens.length]; System.arraycopy(argType.sourcePositions, 0, sourcePositions, 0, tokens.length); int sourceEnd = (int) (sourcePositions[tokens.length - 1] & 0xFFFFFFFF); QualifiedNameReference prefix = new QualifiedNameReference(tokens, sourcePositions, argType.sourceStart, sourceEnd);//from w ww. j av a2 s .c o m scope.problemReporter().illegalTypeAnchorNotATeam(prefix); }