for (Iterator it = l.iterator(); it.hasNext();) {
Object o = it.next();
if (o instanceof IField) {
FieldAccess fieldAccess = new FieldAccess(
location,
new SimpleType(location, ((IField) o).getDeclaringIClass()),
(IField) o
);
fieldAccess.setEnclosingBlockStatement(enclosingBlockStatement);
return fieldAccess;
}
}
}
}
// JLS3 6.5.2.BL1.B1.B2.2 Static field imported through static-import-on-demand.
{
IField importedField = null;
for (Iterator it = this.staticImportsOnDemand.iterator(); it.hasNext();) {
IClass iClass = (IClass) it.next();
IField f = iClass.getDeclaredIField(identifier);
if (f != null) {
// JLS3 7.5.4 Static-Import-on-Demand Declaration
if (!UnitCompiler.this.isAccessible(f, enclosingBlockStatement)) continue;
if (importedField != null) {
UnitCompiler.this.compileError(
"Ambiguous static field import: \""
+ importedField.toString()
+ "\" vs. \""
+ f.toString()
+ "\""
);
}
importedField = f;
}
}
if (importedField != null) {
if (!importedField.isStatic()) UnitCompiler.this.compileError("Cannot static-import non-static field");
FieldAccess fieldAccess = new FieldAccess(
location,
new SimpleType(location, importedField.getDeclaringIClass()),
importedField
);
fieldAccess.setEnclosingBlockStatement(enclosingBlockStatement);
return fieldAccess;
}
}
// Hack: "java" MUST be a package, not a class.
if (identifier.equals("java")) return new Java.Package(location, identifier);
// 6.5.2.BL1.B1.B2.1 (JLS3: 6.5.2.BL1.B1.B3.2) Local class.
{
Java.LocalClassDeclaration lcd = this.findLocalClassDeclaration(scope, identifier);
if (lcd != null) return new Java.SimpleType(location, this.resolve(lcd));
}
// 6.5.2.BL1.B1.B2.2 (JLS3: 6.5.2.BL1.B1.B3.3) Member type.
if (scopeTypeDeclaration != null) {
IClass memberType = this.findMemberType(
UnitCompiler.this.resolve(scopeTypeDeclaration),
identifier,
location
);
if (memberType != null) return new Java.SimpleType(location, memberType);
}
// 6.5.2.BL1.B1.B3.1 (JLS3: 6.5.2.BL1.B1.B4.1) Single type import.
{
IClass iClass = this.importSingleType(identifier, location);
if (iClass != null) return new Java.SimpleType(location, iClass);
}
// 6.5.2.BL1.B1.B3.2 (JLS3: 6.5.2.BL1.B1.B3.1) Package member class/interface declared in this compilation unit.
// Notice that JLS2 looks this up AFTER local class, member type, single type import, while
// JLS3 looks this up BEFORE local class, member type, single type import.
{
Java.PackageMemberTypeDeclaration pmtd = scopeCompilationUnit.getPackageMemberTypeDeclaration(identifier);
if (pmtd != null) return new Java.SimpleType(location, this.resolve((Java.AbstractTypeDeclaration) pmtd));
}
// 6.5.2.BL1.B1.B4 Class or interface declared in same package.
// Notice: Why is this missing in JLS3?
{
String className = (
scopeCompilationUnit.optionalPackageDeclaration == null ?
identifier :
scopeCompilationUnit.optionalPackageDeclaration.packageName + '.' + identifier
);
IClass result = findClassByName(location, className);
if (result != null) return new Java.SimpleType(location, result);
}
// 6.5.2.BL1.B1.B5 (JLS3: 6.5.2.BL1.B1.B4.2), 6.5.2.BL1.B1.B6 Type-import-on-demand.
{
IClass importedClass = this.importTypeOnDemand(identifier, location);
if (importedClass != null) {
return new Java.SimpleType(location, importedClass);
}
}
// JLS3 6.5.2.BL1.B1.B4.3 Type imported through single static import.
{
List l = (List) this.singleStaticImports.get(identifier);
if (l != null) {
for (Iterator it = l.iterator(); it.hasNext();) {
Object o = it.next();
if (o instanceof IClass) return new SimpleType(null, (IClass) o);
}
}
}
// JLS3 6.5.2.BL1.B1.B4.4 Type imported through static-import-on-demand.