}
public boolean isConstructor() {
- return (returntype==null);
+ return (returntype==null) && !isstaticblock;
}
public TypeDescriptor getReturnType() {
BlockStatementNode bsn = bn.get(ii);
obn.addBlockStatement(bsn);
}
- //TODO state.addTreeCode(md, obn);
+ state.addTreeCode(md, obn);
bn = null;
}
en = null;
BlockStatementNode bsn = bn.get(i);
obn.addBlockStatement(bsn);
}
- //TODO state.addTreeCode(md, obn);
+ state.addTreeCode(md, obn);
bn = null;
}
}
}
}
/* Check return type */
- if (!md.isConstructor())
+ if (!md.isConstructor() && !md.isStaticBlock())
if (!md.getReturnType().isVoid())
checkTypeDescriptor(md.getReturnType());
SymbolTable fieldtbl = cd.getFieldTable();
FieldDescriptor fd=(FieldDescriptor)fieldtbl.get(varname);
if((fd == null) || (!fd.isStatic())){
- // no such field in the class or it is not a static field
- throw new Error("Name "+varname+" should not be used in static block: "+md);
+ // no such field in the class, check if this is a class
+ if(varname.equals("this")) {
+ throw new Error("Error: access this obj in a static block");
+ }
+ cd=getClass(varname);
+ if(cd != null) {
+ // this is a class name
+ nn.setClassDesc(cd);
+ return;
+ } else {
+ throw new Error("Name "+varname+" should not be used in static block: "+md);
+ }
} else {
// this is a static field
nn.setField(fd);