1
/* *******************************************************************
2
* Copyright (c) 2005 Contributors.
4
* This program and the accompanying materials are made available
5
* under the terms of the Eclipse Public License v1.0
6
* which accompanies this distribution and is available at
7
* http://eclipse.org/legal/epl-v10.html
10
* Adrian Colyer Initial implementation
11
* ******************************************************************/
12
package org.aspectj.weaver.patterns;
14
import org.aspectj.bridge.IMessage;
15
import org.aspectj.bridge.IMessageHandler;
16
import org.aspectj.bridge.IMessage.Kind;
17
import org.aspectj.weaver.IHasPosition;
18
import org.aspectj.weaver.ResolvedType;
19
import org.aspectj.weaver.TypeVariable;
20
import org.aspectj.weaver.UnresolvedType;
21
import org.aspectj.weaver.UnresolvedTypeVariableReferenceType;
22
import org.aspectj.weaver.World;
25
* A scope that also considers type variables when looking up a type.
28
public class ScopeWithTypeVariables implements IScope {
30
private IScope delegateScope;
31
private String[] typeVariableNames;
32
private UnresolvedTypeVariableReferenceType[] typeVarTypeXs;
34
public ScopeWithTypeVariables(String[] typeVarNames, IScope delegate) {
35
this.delegateScope = delegate;
36
this.typeVariableNames = typeVarNames;
37
this.typeVarTypeXs = new UnresolvedTypeVariableReferenceType[typeVarNames.length];
41
* @see org.aspectj.weaver.patterns.IScope#lookupType(java.lang.String, org.aspectj.weaver.IHasPosition)
43
public UnresolvedType lookupType(String name, IHasPosition location) {
44
for (int i = 0; i < typeVariableNames.length; i++) {
45
if (typeVariableNames[i].equals(name)) {
46
if (typeVarTypeXs[i] == null) {
47
typeVarTypeXs[i] = new UnresolvedTypeVariableReferenceType(new TypeVariable(name));
49
return typeVarTypeXs[i];
52
return delegateScope.lookupType(name, location);
56
* @see org.aspectj.weaver.patterns.IScope#getWorld()
58
public World getWorld() {
59
return delegateScope.getWorld();
63
* @see org.aspectj.weaver.patterns.IScope#getEnclosingType()
65
public ResolvedType getEnclosingType() {
66
return delegateScope.getEnclosingType();
70
* @see org.aspectj.weaver.patterns.IScope#getMessageHandler()
72
public IMessageHandler getMessageHandler() {
73
return delegateScope.getMessageHandler();
77
* @see org.aspectj.weaver.patterns.IScope#lookupFormal(java.lang.String)
79
public FormalBinding lookupFormal(String name) {
80
return delegateScope.lookupFormal(name);
84
* @see org.aspectj.weaver.patterns.IScope#getFormal(int)
86
public FormalBinding getFormal(int i) {
87
return delegateScope.getFormal(i);
91
* @see org.aspectj.weaver.patterns.IScope#getFormalCount()
93
public int getFormalCount() {
94
return delegateScope.getFormalCount();
98
* @see org.aspectj.weaver.patterns.IScope#getImportedPrefixes()
100
public String[] getImportedPrefixes() {
101
return delegateScope.getImportedPrefixes();
105
* @see org.aspectj.weaver.patterns.IScope#getImportedNames()
107
public String[] getImportedNames() {
108
return delegateScope.getImportedNames();
112
* @see org.aspectj.weaver.patterns.IScope#message(org.aspectj.bridge.IMessage.Kind, org.aspectj.weaver.IHasPosition, java.lang.String)
114
public void message(Kind kind, IHasPosition location, String message) {
115
delegateScope.message(kind, location, message);
119
* @see org.aspectj.weaver.patterns.IScope#message(org.aspectj.bridge.IMessage.Kind, org.aspectj.weaver.IHasPosition, org.aspectj.weaver.IHasPosition, java.lang.String)
121
public void message(Kind kind, IHasPosition location1,
122
IHasPosition location2, String message) {
123
delegateScope.message(kind,location1,location2,message);
126
public void message(IMessage aMessage) {
127
delegateScope.message(aMessage);