diff options
author | aclement <aclement> | 2009-09-26 00:59:55 +0000 |
---|---|---|
committer | aclement <aclement> | 2009-09-26 00:59:55 +0000 |
commit | a6720488b256f80cd591a4cac837e1b8222424bf (patch) | |
tree | 186c5372cd7bc18117e18999086eefd6f93553c8 /org.aspectj.matcher/src/org | |
parent | 53368cb03d9b205e75b5fdce8cdbf5c01a768990 (diff) | |
download | aspectj-a6720488b256f80cd591a4cac837e1b8222424bf.tar.gz aspectj-a6720488b256f80cd591a4cac837e1b8222424bf.zip |
formatted
Diffstat (limited to 'org.aspectj.matcher/src/org')
3 files changed, 167 insertions, 86 deletions
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/TypeFactory.java b/org.aspectj.matcher/src/org/aspectj/weaver/TypeFactory.java index 12779ad74..b102fb9d3 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/TypeFactory.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/TypeFactory.java @@ -33,11 +33,13 @@ public class TypeFactory { if (!aBaseType.isGenericType()) { // try and find the generic type... if (someTypeParameters != null && someTypeParameters.length > 0) { - if (!aBaseType.isRawType()) + if (!aBaseType.isRawType()) { throw new IllegalStateException("Expecting raw type, not: " + aBaseType); + } baseType = baseType.getGenericType(); - if (baseType == null) + if (baseType == null) { throw new IllegalStateException("Raw type does not have generic type set"); + } } // else if someTypeParameters is null, then the base type is allowed to be non-generic, it's an inner } ResolvedType[] resolvedParameters = inAWorld.resolve(someTypeParameters); @@ -114,8 +116,9 @@ public class TypeFactory { while (startOfParams != -1) { erasureSig.delete(startOfParams, endOfParams + 1); startOfParams = locateFirstBracket(erasureSig); - if (startOfParams != -1) + if (startOfParams != -1) { endOfParams = locateMatchingEndBracket(erasureSig, startOfParams); + } } String signatureErasure = "L" + erasureSig.toString().substring(1); @@ -124,10 +127,11 @@ public class TypeFactory { // if the signature is 'PMyInterface<String>$MyOtherType;' then there are none... String lastType = null; int nestedTypePosition = signature.indexOf("$", endOfParams); // don't look for $ INSIDE the parameters - if (nestedTypePosition != -1) + if (nestedTypePosition != -1) { lastType = signature.substring(nestedTypePosition + 1); - else + } else { lastType = new String(signature); + } startOfParams = lastType.indexOf("<"); endOfParams = locateMatchingEndBracket(lastType, startOfParams); UnresolvedType[] typeParams = UnresolvedType.NONE; @@ -157,8 +161,9 @@ public class TypeFactory { return new UnresolvedTypeVariableReferenceType(new TypeVariable(typeVariableName)); } else if (firstChar == '[') { int dims = 0; - while (signature.charAt(dims) == '[') + while (signature.charAt(dims) == '[') { dims++; + } UnresolvedType componentType = createTypeFromSignature(signature.substring(dims)); return new UnresolvedType(signature, signature.substring(0, dims) + componentType.getErasureSignature()); } else if (signature.length() == 1) { // could be a primitive @@ -187,31 +192,37 @@ public class TypeFactory { } private static int locateMatchingEndBracket(String signature, int startOfParams) { - if (startOfParams == -1) + if (startOfParams == -1) { return -1; + } int count = 1; int idx = startOfParams; while (count > 0 && idx < signature.length()) { idx++; - if (signature.charAt(idx) == '<') + if (signature.charAt(idx) == '<') { count++; - if (signature.charAt(idx) == '>') + } + if (signature.charAt(idx) == '>') { count--; + } } return idx; } private static int locateMatchingEndBracket(StringBuffer signature, int startOfParams) { - if (startOfParams == -1) + if (startOfParams == -1) { return -1; + } int count = 1; int idx = startOfParams; while (count > 0 && idx < signature.length()) { idx++; - if (signature.charAt(idx) == '<') + if (signature.charAt(idx) == '<') { count++; - if (signature.charAt(idx) == '>') + } + if (signature.charAt(idx) == '>') { count--; + } } return idx; } @@ -219,8 +230,9 @@ public class TypeFactory { private static int locateFirstBracket(StringBuffer signature) { int idx = 0; while (idx < signature.length()) { - if (signature.charAt(idx) == '<') + if (signature.charAt(idx) == '<') { return idx; + } idx++; } return -1; diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/UnresolvedType.java b/org.aspectj.matcher/src/org/aspectj/weaver/UnresolvedType.java index 43ba641d4..f1fe720da 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/UnresolvedType.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/UnresolvedType.java @@ -186,9 +186,11 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { /** * Equality is checked based on the underlying signature. {@link ResolvedType} objects' equals is by reference. */ + @Override public boolean equals(Object other) { - if (!(other instanceof UnresolvedType)) + if (!(other instanceof UnresolvedType)) { return false; + } return signature.equals(((UnresolvedType) other).signature); } @@ -196,6 +198,7 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { * Equality is checked based on the underlying signature, so the hash code of a particular type is the hash code of its * signature string. */ + @Override public final int hashCode() { return signature.hashCode(); } @@ -215,8 +218,9 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { this.signature = signature; this.signatureErasure = signatureErasure; this.typeParameters = typeParams; - if (typeParams != null) + if (typeParams != null) { this.typeKind = TypeKind.PARAMETERIZED; + } } // ---- Things we can do without a world @@ -230,8 +234,9 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { public static UnresolvedType makeArray(UnresolvedType base, int dims) { StringBuffer sig = new StringBuffer(); - for (int i = 0; i < dims; i++) + for (int i = 0; i < dims; i++) { sig.append("["); + } sig.append(base.getSignature()); return UnresolvedType.forSignature(sig.toString()); } @@ -484,10 +489,11 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { public String getBaseName() { String name = getName(); if (isParameterizedType() || isGenericType()) { - if (typeParameters == null) + if (typeParameters == null) { return name; - else + } else { return name.substring(0, name.indexOf("<")); + } } else { return name; } @@ -548,8 +554,9 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { * For parameterized types, return the signature for the raw type */ public String getErasureSignature() { - if (signatureErasure == null) + if (signatureErasure == null) { return signature; + } return signatureErasure; } @@ -577,8 +584,9 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { * @return the outermost enclosing UnresolvedType object or this. */ public UnresolvedType getOutermostType() { - if (isArray() || isPrimitiveType()) + if (isArray() || isPrimitiveType()) { return this; + } String sig = getErasureSignature(); int dollar = sig.indexOf('$'); if (dollar != -1) { @@ -605,6 +613,7 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { /** * Returns a java language string representation of this type. */ + @Override public String toString() { return getName(); // + " - " + getKind(); } @@ -668,16 +677,20 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { StringBuffer innerBuff = new StringBuffer(); while (paramNestLevel > 0) { c = signature.charAt(++i); - if (c == '<') + if (c == '<') { paramNestLevel++; - if (c == '>') + } + if (c == '>') { paramNestLevel--; - if (paramNestLevel > 0) + } + if (paramNestLevel > 0) { innerBuff.append(c); + } if (c == ';' && paramNestLevel == 1) { nameBuff.append(signatureToName(innerBuff.toString())); - if (signature.charAt(i + 1) != '>') + if (signature.charAt(i + 1) != '>') { nameBuff.append(','); + } innerBuff = new StringBuffer(); } } @@ -713,28 +726,39 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { } private static String nameToSignature(String name) { - if (name.equals("byte")) + if (name.equals("byte")) { return "B"; - if (name.equals("char")) + } + if (name.equals("char")) { return "C"; - if (name.equals("double")) + } + if (name.equals("double")) { return "D"; - if (name.equals("float")) + } + if (name.equals("float")) { return "F"; - if (name.equals("int")) + } + if (name.equals("int")) { return "I"; - if (name.equals("long")) + } + if (name.equals("long")) { return "J"; - if (name.equals("short")) + } + if (name.equals("short")) { return "S"; - if (name.equals("boolean")) + } + if (name.equals("boolean")) { return "Z"; - if (name.equals("void")) + } + if (name.equals("void")) { return "V"; - if (name.equals("?")) + } + if (name.equals("?")) { return name; - if (name.endsWith("[]")) + } + if (name.endsWith("[]")) { return "[" + nameToSignature(name.substring(0, name.length() - 2)); + } if (name.length() != 0) { // lots more tests could be made here... @@ -763,16 +787,19 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { StringBuffer innerBuff = new StringBuffer(); while (nestLevel > 0) { c = name.charAt(++i); - if (c == '<') + if (c == '<') { nestLevel++; - if (c == '>') + } + if (c == '>') { nestLevel--; + } if (c == ',' && nestLevel == 1) { nameBuff.append(nameToSignature(innerBuff.toString())); innerBuff = new StringBuffer(); } else { - if (nestLevel > 0) + if (nestLevel > 0) { innerBuff.append(c); + } } } nameBuff.append(nameToSignature(innerBuff.toString())); @@ -789,8 +816,9 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { nameBuff.append(";"); return nameBuff.toString(); } - } else + } else { throw new BCException("Bad type name: " + name); + } } public void write(DataOutputStream s) throws IOException { @@ -817,8 +845,9 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { public static UnresolvedType[] readArray(DataInputStream s) throws IOException { int len = s.readShort(); - if (len == 0) + if (len == 0) { return UnresolvedType.NONE; + } UnresolvedType[] types = new UnresolvedType[len]; for (int i = 0; i < len; i++) { types[i] = UnresolvedType.read(s); @@ -892,6 +921,7 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { public final static TypeKind TYPE_VARIABLE = new TypeKind("type_variable"); // a type variable public final static TypeKind WILDCARD = new TypeKind("wildcard"); // a generic wildcard type + @Override public String toString() { return type; } @@ -905,12 +935,14 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { public TypeVariable getTypeVariableNamed(String name) { TypeVariable[] vars = getTypeVariables(); - if (vars == null || vars.length == 0) + if (vars == null || vars.length == 0) { return null; + } for (int i = 0; i < vars.length; i++) { TypeVariable aVar = vars[i]; - if (aVar.getName().equals(name)) + if (aVar.getName().equals(name)) { return aVar; + } } return null; } diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/World.java b/org.aspectj.matcher/src/org/aspectj/weaver/World.java index b5ff4d956..a685bbd90 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/World.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/World.java @@ -144,8 +144,9 @@ public abstract class World implements Dump.INode { */ protected World() { super(); - if (trace.isTraceEnabled()) + if (trace.isTraceEnabled()) { trace.enter("<init>", this); + } Dump.registerNode(this.getClass(), this); typeMap.put("B", ResolvedType.BYTE); typeMap.put("S", ResolvedType.SHORT); @@ -157,8 +158,9 @@ public abstract class World implements Dump.INode { typeMap.put("Z", ResolvedType.BOOLEAN); typeMap.put("V", ResolvedType.VOID); precedenceCalculator = new AspectPrecedenceCalculator(this); - if (trace.isTraceEnabled()) + if (trace.isTraceEnabled()) { trace.exit("<init>"); + } } /** @@ -219,8 +221,9 @@ public abstract class World implements Dump.INode { * signatures. */ public ResolvedType[] resolve(UnresolvedType[] types) { - if (types == null) + if (types == null) { return new ResolvedType[0]; + } ResolvedType[] ret = new ResolvedType[types.length]; for (int i = 0; i < types.length; i++) { @@ -335,8 +338,9 @@ public abstract class World implements Dump.INode { * them there. Resolved types are also told their world which is needed for the special autoboxing resolved types. */ public ResolvedType resolve(ResolvedType ty) { - if (ty.isTypeVariableReference()) + if (ty.isTypeVariableReference()) { return ty; // until type variables have proper sigs... + } ResolvedType resolved = typeMap.get(ty.getSignature()); if (resolved == null) { typeMap.put(ty.getSignature(), ty); @@ -368,8 +372,9 @@ public abstract class World implements Dump.INode { if (ty.isParameterizedType()) { // ======= parameterized types ================ ResolvedType rt = resolveGenericTypeFor(ty, allowMissing); - if (rt.isMissing()) + if (rt.isMissing()) { return rt; + } ReferenceType genericType = (ReferenceType) rt; ReferenceType parameterizedType = TypeFactory.createParameterizedType(genericType, ty.typeParameters, this); return parameterizedType; @@ -386,16 +391,18 @@ public abstract class World implements Dump.INode { // ======= simple and raw types =============== String erasedSignature = ty.getErasureSignature(); ReferenceType simpleOrRawType = new ReferenceType(erasedSignature, this); - if (ty.needsModifiableDelegate()) + if (ty.needsModifiableDelegate()) { simpleOrRawType.setNeedsModifiableDelegate(true); + } ReferenceTypeDelegate delegate = resolveDelegate(simpleOrRawType); // 117854 // if (delegate == null) return ResolvedType.MISSING; - if (delegate == null) + if (delegate == null) { return new MissingResolvedTypeWithKnownSignature(ty.getSignature(), erasedSignature, this);// ResolvedType - // . - // MISSING - // ; + // . + // MISSING + // ; + } if (delegate.isGeneric() && behaveInJava5Way) { // ======== raw type =========== @@ -428,8 +435,9 @@ public abstract class World implements Dump.INode { rawType = resolve(UnresolvedType.forSignature(rawSignature), allowMissing); typeMap.put(rawSignature, rawType); } - if (rawType.isMissing()) + if (rawType.isMissing()) { return rawType; + } // Does the raw type know its generic form? (It will if we created the // raw type from a source type, it won't if its been created just @@ -544,8 +552,9 @@ public abstract class World implements Dump.INode { */ public ResolvedMember resolve(Member member) { ResolvedType declaring = member.getDeclaringType().resolve(this); - if (declaring.isRawType()) + if (declaring.isRawType()) { declaring = declaring.getGenericType(); + } ResolvedMember ret; if (member.getKind() == Member.FIELD) { ret = declaring.lookupField(member); @@ -553,8 +562,9 @@ public abstract class World implements Dump.INode { ret = declaring.lookupMethod(member); } - if (ret != null) + if (ret != null) { return ret; + } return declaring.lookupSyntheticMember(member); } @@ -739,14 +749,16 @@ public abstract class World implements Dump.INode { public boolean isIgnoringUnusedDeclaredThrownException() { // the 0x800000 is CompilerOptions.UnusedDeclaredThrownException // which is ASTNode.bit24 - if ((errorThreshold & 0x800000) != 0 || (warningThreshold & 0x800000) != 0) + if ((errorThreshold & 0x800000) != 0 || (warningThreshold & 0x800000) != 0) { return false; + } return true; } public void performExtraConfiguration(String config) { - if (config == null) + if (config == null) { return; + } // Bunch of name value pairs to split extraConfiguration = new Properties(); int pos = -1; @@ -819,12 +831,15 @@ public abstract class World implements Dump.INode { } public void setOptionalJoinpoints(String jps) { - if (jps == null) + if (jps == null) { return; - if (jps.indexOf("arrayconstruction") != -1) + } + if (jps.indexOf("arrayconstruction") != -1) { optionalJoinpoint_ArrayConstruction = true; - if (jps.indexOf("synchronization") != -1) + } + if (jps.indexOf("synchronization") != -1) { optionalJoinpoint_Synchronization = true; + } } public boolean isJoinpointArrayConstructionEnabled() { @@ -843,10 +858,11 @@ public abstract class World implements Dump.INode { // the old runtime? public boolean isTargettingAspectJRuntime12() { boolean b = false; // pr116679 - if (!isInJava5Mode()) + if (!isInJava5Mode()) { b = true; - else + } else { b = getTargetAspectjRuntimeLevel().equals(org.aspectj.weaver.Constants.RUNTIME_LEVEL_12); + } // System.err.println("Asked if targetting runtime 1.2 , returning: "+b); return b; } @@ -946,50 +962,57 @@ public abstract class World implements Dump.INode { return type; } if (type.isParameterizedType() && type.isParameterizedWithTypeVariable()) { - if (debug) + if (debug) { System.err .println("Not putting a parameterized type that utilises member declared type variables into the typemap: key=" + key + " type=" + type); + } return type; } if (type.isTypeVariableReference()) { - if (debug) + if (debug) { System.err.println("Not putting a type variable reference type into the typemap: key=" + key + " type=" + type); + } return type; } // this test should be improved - only avoid putting them in if one // of the // bounds is a member type variable if (type instanceof BoundedReferenceType) { - if (debug) + if (debug) { System.err.println("Not putting a bounded reference type into the typemap: key=" + key + " type=" + type); + } return type; } if (type instanceof MissingResolvedTypeWithKnownSignature) { - if (debug) + if (debug) { System.err.println("Not putting a missing type into the typemap: key=" + key + " type=" + type); + } return type; } if ((type instanceof ReferenceType) && (((ReferenceType) type).getDelegate() == null) && w.isExpendable(type)) { - if (debug) + if (debug) { System.err.println("Not putting expendable ref type with null delegate into typemap: key=" + key + " type=" + type); + } return type; } if (w.isExpendable(type)) { // Dont use reference queue for tracking if not profiling... if (policy == USE_WEAK_REFS) { - if (memoryProfiling) + if (memoryProfiling) { expendableMap.put(key, new WeakReference(type, rq)); - else + } else { expendableMap.put(key, new WeakReference(type)); + } } else if (policy == USE_SOFT_REFS) { - if (memoryProfiling) + if (memoryProfiling) { expendableMap.put(key, new SoftReference(type, rq)); - else + } else { expendableMap.put(key, new SoftReference(type)); + } } else { expendableMap.put(key, type); } @@ -1008,8 +1031,9 @@ public abstract class World implements Dump.INode { } public void report() { - if (!memoryProfiling) + if (!memoryProfiling) { return; + } checkq(); w.getMessageHandler().handleMessage( MessageUtil.info("MEMORY: world expendable type map reached maximum size of #" + maxExpendableMapSize @@ -1019,10 +1043,12 @@ public abstract class World implements Dump.INode { } public void checkq() { - if (!memoryProfiling) + if (!memoryProfiling) { return; - while (rq.poll() != null) + } + while (rq.poll() != null) { collectedTypes++; + } } /** @@ -1055,12 +1081,14 @@ public abstract class World implements Dump.INode { if (ret == null) { if (policy == USE_WEAK_REFS) { WeakReference wref = (WeakReference) expendableMap.remove(key); - if (wref != null) + if (wref != null) { ret = (ResolvedType) wref.get(); + } } else if (policy == USE_SOFT_REFS) { SoftReference wref = (SoftReference) expendableMap.remove(key); - if (wref != null) + if (wref != null) { ret = (ResolvedType) wref.get(); + } } else { ret = (ResolvedType) expendableMap.remove(key); } @@ -1121,8 +1149,9 @@ public abstract class World implements Dump.INode { DeclarePrecedence d = (DeclarePrecedence) i.next(); int thisOrder = d.compare(firstAspect, secondAspect); if (thisOrder != 0) { - if (orderer == null) + if (orderer == null) { orderer = d; + } if (order != 0 && order != thisOrder) { ISourceLocation[] isls = new ISourceLocation[2]; isls[0] = orderer.getSourceLocation(); @@ -1145,17 +1174,20 @@ public abstract class World implements Dump.INode { } public int compareByPrecedenceAndHierarchy(ResolvedType firstAspect, ResolvedType secondAspect) { - if (firstAspect.equals(secondAspect)) + if (firstAspect.equals(secondAspect)) { return 0; + } int ret = compareByPrecedence(firstAspect, secondAspect); - if (ret != 0) + if (ret != 0) { return ret; + } - if (firstAspect.isAssignableFrom(secondAspect)) + if (firstAspect.isAssignableFrom(secondAspect)) { return -1; - else if (secondAspect.isAssignableFrom(firstAspect)) + } else if (secondAspect.isAssignableFrom(firstAspect)) { return +1; + } return 0; } @@ -1171,8 +1203,9 @@ public abstract class World implements Dump.INode { @Override public boolean equals(Object obj) { - if (!(obj instanceof PrecedenceCacheKey)) + if (!(obj instanceof PrecedenceCacheKey)) { return false; + } PrecedenceCacheKey other = (PrecedenceCacheKey) obj; return (aspect1 == other.aspect1 && aspect2 == other.aspect2); } @@ -1313,11 +1346,13 @@ public abstract class World implements Dump.INode { } public void setSynchronizationPointcutsInUse() { - if (trace.isTraceEnabled()) + if (trace.isTraceEnabled()) { trace.enter("setSynchronizationPointcutsInUse", this); + } synchronizationPointcutsInUse = true; - if (trace.isTraceEnabled()) + if (trace.isTraceEnabled()) { trace.exit("setSynchronizationPointcutsInUse"); + } } public boolean areSynchronizationPointcutsInUse() { @@ -1330,14 +1365,16 @@ public abstract class World implements Dump.INode { * @param designatorHandler handler for the new pointcut */ public void registerPointcutHandler(PointcutDesignatorHandler designatorHandler) { - if (pointcutDesignators == null) + if (pointcutDesignators == null) { pointcutDesignators = new HashSet(); + } pointcutDesignators.add(designatorHandler); } public Set getRegisteredPointcutHandlers() { - if (pointcutDesignators == null) + if (pointcutDesignators == null) { return Collections.EMPTY_SET; + } return pointcutDesignators; } |