private Node buildFieldDecl(FieldDecl fd) throws SemanticException { Type t = fd.declType(); if (t.isSubtype(SJ_PROTOCOL_TYPE)) { if (!(fd instanceof SJFieldProtocolDecl)) { throw new SemanticException( "[SJProtocolDeclTypeBuilder] Protocols may only be declared using the protocol keyword: " + fd); } SJTypeNode tn = disambiguateSJTypeNode(this, ((SJProtocolDecl) fd).sessionType()); SJSessionType st = tn.type(); String sjname = fd.name(); // Should match that given by SJVariable.sjname. SJFieldInstance fi = (SJFieldInstance) fd.fieldInstance(); SJFieldProtocolInstance fpi = sjts.SJFieldProtocolInstance((SJFieldInstance) fd.fieldInstance(), st, sjname); fpi.setConstantValue( fi .constantValue()); // Currently, constant checker not run on custom nodes/type // objects. (Previously done by SJNoAliasTypeBuilder.) fd = fd.fieldInstance(fpi); fd = (FieldDecl) setSJProtocolDeclExt((SJProtocolDecl) fd, tn, sjname); updateSJFieldInstance(fi, fpi); } return fd; }