blob: d97fb8fb623b4b95d06b840e892ce5e4685bdf6a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/* *******************************************************************
* Copyright (c) 2006-2008 Contributors
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* ******************************************************************/
package org.aspectj.weaver;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.weaver.patterns.FormalBinding;
import org.aspectj.weaver.patterns.SimpleScope;
/**
* BindingScope that knows the enclosingType, which is needed for pointcut reference resolution
*
* @author Alexandre Vasseur
* @author Andy Clement
*/
public class BindingScope extends SimpleScope {
private final ResolvedType enclosingType;
private final ISourceContext sourceContext;
private boolean importsUpdated = false;
public BindingScope(ResolvedType type, ISourceContext sourceContext, FormalBinding[] bindings) {
super(type.getWorld(), bindings);
this.enclosingType = type;
this.sourceContext = sourceContext;
}
public ResolvedType getEnclosingType() {
return enclosingType;
}
public ISourceLocation makeSourceLocation(IHasPosition location) {
return sourceContext.makeSourceLocation(location);
}
public UnresolvedType lookupType(String name, IHasPosition location) {
// bug 126560
if (enclosingType != null && !importsUpdated) {
// add the package we're in to the list of imported
// prefixes so that we can find types in the same package
String pkgName = enclosingType.getPackageName();
if (pkgName != null && !pkgName.equals("")) {
String[] existingImports = getImportedPrefixes();
String pkgNameWithDot = pkgName.concat(".");
boolean found = false;
for (String existingImport : existingImports) {
if (existingImport.equals(pkgNameWithDot)) {
found = true;
break;
}
}
if (!found) {
String[] newImports = new String[existingImports.length + 1];
System.arraycopy(existingImports, 0, newImports, 0, existingImports.length);
newImports[existingImports.length] = pkgNameWithDot;
setImportedPrefixes(newImports);
}
}
importsUpdated = true;
}
return super.lookupType(name, location);
}
}
|