123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- /* *******************************************************************
- * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Common Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * PARC initial implementation
- * ******************************************************************/
-
-
- package org.aspectj.weaver;
-
- import java.util.*;
-
- import org.aspectj.weaver.patterns.*;
- import org.aspectj.weaver.patterns.Pointcut;
- import org.aspectj.asm.StructureModel;
- import org.aspectj.bridge.*;
- import org.aspectj.bridge.IMessage.Kind;
-
- public abstract class World {
- protected IMessageHandler messageHandler = IMessageHandler.SYSTEM_ERR;
-
- protected Map typeMap = new HashMap(); // Signature to ResolvedType
-
- protected CrosscuttingMembersSet crosscuttingMembersSet = new CrosscuttingMembersSet(this);
-
- protected StructureModel model = null;
-
- protected Lint lint = new Lint(this);
-
- protected boolean XnoInline;
-
- protected World() {
- super();
- typeMap.put("B", ResolvedTypeX.BYTE);
- typeMap.put("S", ResolvedTypeX.SHORT);
- typeMap.put("I", ResolvedTypeX.INT);
- typeMap.put("J", ResolvedTypeX.LONG);
- typeMap.put("F", ResolvedTypeX.FLOAT);
- typeMap.put("D", ResolvedTypeX.DOUBLE);
- typeMap.put("C", ResolvedTypeX.CHAR);
- typeMap.put("Z", ResolvedTypeX.BOOLEAN);
- typeMap.put("V", ResolvedTypeX.VOID);
- }
-
- public ResolvedTypeX[] resolve(TypeX[] types) {
- int len = types.length;
- ResolvedTypeX[] ret = new ResolvedTypeX[len];
- for (int i=0; i<len; i++) {
- ret[i] = resolve(types[i]);
- }
- return ret;
- }
-
- public ResolvedTypeX resolve(TypeX ty) {
- return resolve(ty, false);
- }
-
- public ResolvedTypeX resolve(TypeX ty, boolean allowMissing) {
- //System.out.println("resolve: " + ty + " world " + typeMap.keySet());
- String signature = ty.getSignature();
- ResolvedTypeX ret = (ResolvedTypeX)typeMap.get(signature);
- if (ret != null) return ret;
-
- if (ty.isArray()) {
- ret = new ResolvedTypeX.Array(signature, this, resolve(ty.getComponentType(), allowMissing));
- } else {
- ret = resolveObjectType(ty);
- if (!allowMissing && ret == ResolvedTypeX.MISSING) {
- //Thread.currentThread().dumpStack();
- MessageUtil.error(messageHandler, "can't find type " + ty.getName());
- // + " on classpath " + classPath);
- }
- }
- //System.out.println("ret: " + ret);
- typeMap.put(signature, ret);
- return ret;
- }
-
- //XXX helper method might be bad
- public ResolvedTypeX resolve(String name) {
- return resolve(TypeX.forName(name));
- }
- protected abstract ResolvedTypeX resolveObjectType(TypeX ty);
-
- protected final boolean isCoerceableFrom(TypeX type, TypeX other) {
- return resolve(type).isCoerceableFrom(other);
- }
-
- protected final boolean isAssignableFrom(TypeX type, TypeX other) {
- return resolve(type).isAssignableFrom(other);
- }
-
- public boolean needsNoConversionFrom(TypeX type, TypeX other) {
- return resolve(type).needsNoConversionFrom(other);
- }
-
- protected final boolean isInterface(TypeX type) {
- return resolve(type).isInterface();
- }
-
- protected final ResolvedTypeX getSuperclass(TypeX type) {
- return resolve(type).getSuperclass();
- }
-
- protected final TypeX[] getDeclaredInterfaces(TypeX type) {
- return resolve(type).getDeclaredInterfaces();
- }
-
- protected final int getModifiers(TypeX type) {
- return resolve(type).getModifiers();
- }
-
- protected final ResolvedMember[] getDeclaredFields(TypeX type) {
- return resolve(type).getDeclaredFields();
- }
-
- protected final ResolvedMember[] getDeclaredMethods(TypeX type) {
- return resolve(type).getDeclaredMethods();
- }
-
- protected final ResolvedMember[] getDeclaredPointcuts(TypeX type) {
- return resolve(type).getDeclaredPointcuts();
- }
-
- // ---- members
-
-
- // XXX should we worry about dealing with context and looking up access?
- public ResolvedMember resolve(Member member) {
- ResolvedTypeX declaring = member.getDeclaringType().resolve(this);
- ResolvedMember ret;
- if (member.getKind() == Member.FIELD) {
- ret = declaring.lookupField(member);
- } else {
- ret = declaring.lookupMethod(member);
- }
-
- if (ret != null) return ret;
-
- return declaring.lookupSyntheticMember(member);
- }
-
- protected int getModifiers(Member member) {
- ResolvedMember r = resolve(member);
- if (r == null) throw new BCException("bad resolve of " + member);
- return r.getModifiers();
- }
-
- protected String[] getParameterNames(Member member) {
- return resolve(member).getParameterNames();
- }
-
- protected TypeX[] getExceptions(Member member) {
- return resolve(member).getExceptions();
- }
-
- // ---- pointcuts
-
- public ResolvedPointcutDefinition findPointcut(TypeX typeX, String name) {
- throw new RuntimeException("not implemented yet");
- }
-
- /**
- * Get the shadow mungers of this world.
- *
- * @return a list of {@link IShadowMunger}s appropriate for this world.
- */
- //public abstract List getShadowMungers();
-
- // ---- empty world
-
- public static final World EMPTY = new World() {
- public List getShadowMungers() { return Collections.EMPTY_LIST; }
- public ResolvedTypeX resolveObjectType(TypeX ty) {
- return ResolvedTypeX.MISSING;
- }
- public Advice concreteAdvice(AjAttribute.AdviceAttribute attribute, Pointcut p, Member m) {
- throw new RuntimeException("unimplemented");
- }
- public ConcreteTypeMunger concreteTypeMunger(ResolvedTypeMunger munger, ResolvedTypeX aspectType) {
- throw new RuntimeException("unimplemented");
- }
- };
-
-
- public abstract Advice concreteAdvice(
- AjAttribute.AdviceAttribute attribute,
- Pointcut pointcut,
- Member signature);
-
- public final Advice concreteAdvice(
- AdviceKind kind,
- Pointcut p,
- Member signature,
- int extraParameterFlags,
- IHasSourceLocation loc)
- {
- AjAttribute.AdviceAttribute attribute =
- new AjAttribute.AdviceAttribute(kind, p, extraParameterFlags, loc.getStart(), loc.getEnd(), loc.getSourceContext());
- return concreteAdvice(attribute, p, signature);
- }
-
-
-
- public ConcreteTypeMunger makeCflowStackFieldAdder(ResolvedMember cflowField) {
- throw new RuntimeException("unimplemented");
- }
-
- public abstract ConcreteTypeMunger concreteTypeMunger(ResolvedTypeMunger munger, ResolvedTypeX aspectType);
-
- /**
- * Nobody should hold onto a copy of this message handler, or setMessageHandler won't
- * work right.
- */
- public IMessageHandler getMessageHandler() {
- return messageHandler;
- }
-
- public void setMessageHandler(IMessageHandler messageHandler) {
- this.messageHandler = messageHandler;
- }
-
- public void showMessage(
- Kind kind,
- String message,
- ISourceLocation loc1,
- ISourceLocation loc2)
- {
- if (loc1 != null) {
- messageHandler.handleMessage(new Message(message, kind, null, loc1));
- if (loc2 != null) {
- messageHandler.handleMessage(new Message(message, kind, null, loc2));
- }
- } else {
- messageHandler.handleMessage(new Message(message, kind, null, loc2));
- }
- }
-
-
-
-
- // public void addDeclare(ResolvedTypeX onType, Declare declare, boolean forWeaving) {
- // // this is not extensible, oh well
- // if (declare instanceof DeclareErrorOrWarning) {
- // ShadowMunger m = new Checker((DeclareErrorOrWarning)declare);
- // onType.addShadowMunger(m);
- // } else if (declare instanceof DeclareDominates) {
- // declareDominates.add(declare);
- // } else if (declare instanceof DeclareParents) {
- // declareParents.add(declare);
- // } else if (declare instanceof DeclareSoft) {
- // DeclareSoft d = (DeclareSoft)declare;
- // declareSoft.add(d);
- // if (forWeaving) {
- // ShadowMunger m = Advice.makeSoftener(this, d.getPointcut().concretize(onType, 0), d.getException());
- // onType.addShadowMunger(m);
- // }
- // } else {
- // throw new RuntimeException("unimplemented");
- // }
- // }
-
-
- /**
- * Same signature as org.aspectj.util.PartialOrder.PartialComparable.compareTo
- */
- public int compareByDominates(ResolvedTypeX aspect1, ResolvedTypeX aspect2) {
- //System.out.println("dom compare: " + aspect1 + " with " + aspect2);
- //System.out.println(crosscuttingMembersSet.getDeclareDominates());
-
- //??? We probably want to cache this result. This is order N where N is the
- //??? number of dominates declares in the whole system.
- //??? This method can be called a large number of times.
- int order = 0;
- for (Iterator i = crosscuttingMembersSet.getDeclareDominates().iterator(); i.hasNext(); ) {
- DeclarePrecedence d = (DeclarePrecedence)i.next();
- int thisOrder = d.compare(aspect1, aspect2);
- //System.out.println("comparing: " + thisOrder + ": " + d);
- if (thisOrder != 0) {
- if (order != 0 && order != thisOrder) {
- throw new BCException("conflicting dominates orders");
- } else {
- order = thisOrder;
- }
- }
- }
-
-
- return order;
- }
-
-
- public int comparePrecedence(ResolvedTypeX aspect1, ResolvedTypeX aspect2) {
- //System.err.println("compare precedence " + aspect1 + ", " + aspect2);
- if (aspect1.equals(aspect2)) return 0;
-
- int ret = compareByDominates(aspect1, aspect2);
- if (ret != 0) return ret;
-
- if (aspect1.isAssignableFrom(aspect2)) return -1;
- else if (aspect2.isAssignableFrom(aspect1)) return +1;
-
- return 0;
- }
-
-
-
-
- public List getDeclareParents() {
- return crosscuttingMembersSet.getDeclareParents();
- }
-
- public List getDeclareSoft() {
- return crosscuttingMembersSet.getDeclareSofts();
- }
-
- public CrosscuttingMembersSet getCrosscuttingMembersSet() {
- return crosscuttingMembersSet;
- }
-
- public StructureModel getModel() {
- return model;
- }
-
- public void setModel(StructureModel model) {
- this.model = model;
- }
-
- public Lint getLint() {
- return lint;
- }
-
- public void setLint(Lint lint) {
- this.lint = lint;
- }
-
- public boolean isXnoInline() {
- return XnoInline;
- }
-
- public void setXnoInline(boolean xnoInline) {
- XnoInline = xnoInline;
- }
-
- }
|