public static boolean isMissing(UnresolvedType unresolved) { if (unresolved instanceof ResolvedType) { ResolvedType resolved = (ResolvedType) unresolved; return resolved.isMissing(); } else { return (unresolved == MISSING); } }
public List<UnresolvedType> getExactTypes() { List<UnresolvedType> ret = new ArrayList<UnresolvedType>(); for (int i = 0; i < typePatterns.length; i++) { UnresolvedType t = typePatterns[i].getExactType(); if (!ResolvedType.isMissing(t)) { ret.add(t); } } return ret; }
private UnresolvedType lookupTypeInScope(IScope scope, String typeName, IHasPosition location) { UnresolvedType type = null; while (ResolvedType.isMissing(type = scope.lookupType(typeName, location))) { int lastDot = typeName.lastIndexOf('.'); if (lastDot == -1) { break; } typeName = typeName.substring(0, lastDot) + '$' + typeName.substring(lastDot + 1); } return type; }
private ResolvedType lookupTypeInWorld(World world, String typeName) { UnresolvedType ut = UnresolvedType.forName(typeName); ResolvedType ret = world.resolve(ut, true); while (ret.isMissing()) { int lastDot = typeName.lastIndexOf('.'); if (lastDot == -1) { break; } typeName = typeName.substring(0, lastDot) + '$' + typeName.substring(lastDot + 1); ret = world.resolve(UnresolvedType.forName(typeName), true); } return ret; }
public final FuzzyBoolean matches(ResolvedType type, MatchKind kind) { // FuzzyBoolean typeMatch = null; // ??? This is part of gracefully handling missing references if (type.isMissing()) { return FuzzyBoolean.NO; } if (kind == STATIC) { return FuzzyBoolean.fromBoolean(matchesStatically(type)); } else if (kind == DYNAMIC) { // System.err.println("matching: " + this + " with " + type); // typeMatch = matchesInstanceof(type); // System.err.println(" got: " + ret); // return typeMatch.and(annotationPattern.matches(type)); return matchesInstanceof(type); } else { throw new IllegalArgumentException("kind must be DYNAMIC or STATIC"); } }
@Override public void resolve(World world) { if (!resolved) { // attempt resolution - this helps with the Spring bug where they resolve() the pointcut in no scope (SPR-5307) if (typePattern instanceof WildTypePattern && (annotationValues == null || annotationValues.isEmpty())) { WildTypePattern wildTypePattern = (WildTypePattern) typePattern; String fullyQualifiedName = wildTypePattern.maybeGetCleanName(); if (fullyQualifiedName != null && fullyQualifiedName.indexOf(".") != -1) { ResolvedType resolvedType = world.resolve(UnresolvedType.forName(fullyQualifiedName)); if (resolvedType != null && !resolvedType.isMissing()) { typePattern = new ExactTypePattern(resolvedType, false, false); } } } resolved = true; } }
protected boolean ajMembersNeedParameterization() { if (isParameterizedType()) { return true; } ResolvedType superclass = getSuperclass(); if (superclass != null && !superclass.isMissing()) { return superclass.ajMembersNeedParameterization(); } return false; }
private boolean implementsSerializable(ResolvedType aType) { if (aType.getSignature().equals(UnresolvedType.SERIALIZABLE.getSignature())) { return true; } ResolvedType[] interfaces = aType.getDeclaredInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (interfaces[i].isMissing()) { continue; } if (implementsSerializable(interfaces[i])) { return true; } } ResolvedType superType = aType.getSuperclass(); if (superType != null && !superType.isMissing()) { return implementsSerializable(superType); } return false; }
public List<ConcreteTypeMunger> getTypeMungers(ResolvedType onType) { World world = onType.getWorld(); List<ConcreteTypeMunger> ret = new ArrayList<ConcreteTypeMunger>(); for (Entry entry : typeMungers) { ResolvedType aspectType = world.resolve(entry.aspectType, true); if (aspectType.isMissing()) { world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.ASPECT_NEEDED, entry.aspectType, onType), onType.getSourceLocation(), null); continue; } ret.add(new TemporaryTypeMunger(entry.typeMunger, aspectType)); } return ret; }
public boolean couldMatchJoinPointsInType(Class aClass) { ResolvedType matchType = world.resolve(aClass.getName()); if (matchType.isMissing() && (world instanceof ReflectionWorld)) { // Class is a generated class that cannot be 'looked up' via getResource. // For example a proxy or lambda. // Use the class itself in this case matchType = ((ReflectionWorld)world).resolveUsingClass(aClass); } ReflectionFastMatchInfo info = new ReflectionFastMatchInfo(matchType, null, this.matchContext, world); boolean couldMatch = pointcut.fastMatch(info).maybeTrue(); if (MATCH_INFO) { System.out.println("MATCHINFO: fast match for '" + this.expression + "' against '" + aClass.getName() + "': " + couldMatch); } return couldMatch; }
/** * Special resolution for "core" types like OBJECT. These are resolved just like any other type, but if they are not found it is * more serious and we issue an error message immediately. */ // OPTIMIZE streamline path for core types? They are just simple types, // could look straight in the typemap? public ResolvedType getCoreType(UnresolvedType tx) { ResolvedType coreTy = resolve(tx, true); if (coreTy.isMissing()) { MessageUtil.error(messageHandler, WeaverMessages.format(WeaverMessages.CANT_FIND_CORE_TYPE, tx.getName())); } return coreTy; }
public boolean isTopmostImplementor(ResolvedType interfaceType) { boolean b = true; if (isInterface()) { b = false; } else if (!interfaceType.isAssignableFrom(this, true)) { b = false; } else { ResolvedType superclass = this.getSuperclass(); if (superclass.isMissing()) { b = true; // we don't know anything about supertype, and it can't be exposed to weaver } else if (interfaceType.isAssignableFrom(superclass, true)) { // check that I'm truly the topmost implementor b = false; } } // System.out.println("is " + getName() + " topmostimplementor of " + interfaceType + "? " + b); return b; }
@Override protected boolean couldEverMatchSameTypesAs(TypePattern other) { if (super.couldEverMatchSameTypesAs(other)) { return true; } // false is necessary but not sufficient UnresolvedType otherType = other.getExactType(); if (!ResolvedType.isMissing(otherType)) { return type.equals(otherType); } if (other instanceof WildTypePattern) { WildTypePattern owtp = (WildTypePattern) other; String yourSimpleNamePrefix = owtp.getNamePatterns()[0].maybeGetSimpleName(); if (yourSimpleNamePrefix != null) { return (type.getName().startsWith(yourSimpleNamePrefix)); } } return true; }
public Object visit(ReferencePointcut node, Object data) { // && pc_ref() // we know there is no support for binding in perClause: perthis(pc_ref(java.lang.String)) // TODO AV - may need some work for generics.. ResolvedPointcutDefinition pointcutDec; ResolvedType searchStart = m_fromAspectType; if (node.onType != null) { searchStart = node.onType.resolve(m_fromAspectType.getWorld()); if (searchStart.isMissing()) { return MAYBE;// this should not happen since concretize will fails but just in case.. } } pointcutDec = searchStart.findPointcut(node.name); return getPerTypePointcut(pointcutDec.getPointcut()); }
protected ResolvedType completeNonLocalType(ResolvedType ret) { if (ret.isMissing()) { return ret; // who knows ?!? } ResolvedType toResolve = ret; if (ret.isParameterizedType() || ret.isGenericType()) { toResolve = toResolve.getGenericType(); } ReferenceTypeDelegate rtd = resolveReflectionTypeDelegate((ReferenceType) toResolve, getClassLoader()); ((ReferenceType) ret).setDelegate(rtd); return ret; }
protected FuzzyBoolean matchInternal(Shadow shadow) { // ??? this is not maximally efficient // Check we'll be able to do the residue! // this bit is for pr145693 - we cannot match at all if one of the types is missing, we will be unable // to create the residue if (slots != null) { for (Slot slot: slots) { ResolvedType rt = slot.formalType; if (rt.isMissing()) { ISourceLocation[] locs = new ISourceLocation[] { getSourceLocation() }; Message m = new Message(WeaverMessages.format(WeaverMessages.MISSING_TYPE_PREVENTS_MATCH, rt.getName()), "", Message.WARNING, shadow.getSourceLocation(), null, locs); rt.getWorld().getMessageHandler().handleMessage(m); return FuzzyBoolean.NO; } } } return FuzzyBoolean.MAYBE; }
/** * Raises an [Xlint:cantFindType] message if the declaring type cannot be found or an [Xlint:unresolvableMember] message if the * type can be found (bug 149908) */ private void reportDidntFindMember(World world) { if (reportedCantFindDeclaringType || reportedUnresolvableMember) { return; } ResolvedType rType = getDeclaringType().resolve(world); if (rType.isMissing()) { world.getLint().cantFindType.signal(WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE, rType.getName()), null); reportedCantFindDeclaringType = true; } else { world.getLint().unresolvableMember.signal(getName(), null); reportedUnresolvableMember = true; } }
/** * For a TypeVariableReferenceType the delegate is the delegate for the first bound. */ @Override public ReferenceTypeDelegate getDelegate() { if (this.delegate == null) { ResolvedType resolvedFirstBound = typeVariable.getFirstBound().resolve(world); BoundedReferenceTypeDelegate brtd = null; if (resolvedFirstBound.isMissing()) { brtd = new BoundedReferenceTypeDelegate((ReferenceType) world.resolve(UnresolvedType.OBJECT)); setDelegate(brtd); // set now because getSourceLocation() below will cause a recursive step to discover the delegate world.getLint().cantFindType.signal( "Unable to find type for generic bound. Missing type is " + resolvedFirstBound.getName(), getSourceLocation()); } else { brtd = new BoundedReferenceTypeDelegate((ReferenceType) resolvedFirstBound); setDelegate(brtd); } } return this.delegate; }
protected FuzzyBoolean matchInternal(Shadow shadow) { ResolvedType enclosingType = shadow.getIWorld().resolve(shadow.getEnclosingType(), true); if (enclosingType.isMissing()) { shadow.getIWorld().getLint().cantFindType.signal(new String[] { WeaverMessages.format( WeaverMessages.CANT_FIND_TYPE_WITHINPCD, shadow.getEnclosingType().getName()) }, shadow.getSourceLocation(), new ISourceLocation[] { getSourceLocation() }); } typePattern.resolve(shadow.getIWorld()); return isWithinType(enclosingType); }
@Override protected FuzzyBoolean matchInternal(Shadow shadow) { ResolvedType enclosingType = shadow.getIWorld().resolve(shadow.getEnclosingType(), true); if (enclosingType.isMissing()) { shadow.getIWorld().getLint().cantFindType.signal(new String[] { WeaverMessages.format( WeaverMessages.CANT_FIND_TYPE_WITHINPCD, shadow.getEnclosingType().getName()) }, shadow.getSourceLocation(), new ISourceLocation[] { getSourceLocation() }); // IMessage msg = new Message( // WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_WITHINPCD, // shadow.getEnclosingType().getName()), // shadow.getSourceLocation(),true,new ISourceLocation[]{getSourceLocation()}); // shadow.getIWorld().getMessageHandler().handleMessage(msg); } annotationTypePattern.resolve(shadow.getIWorld()); return annotationTypePattern.matches(enclosingType); }