コード例 #1
0
  public OJField getCopy() {
    /*if (isAlterable())  return substance.getCopy();*/
    /** **************** */
    // return (FieldDeclaration) substance.clone () ;
    try {

      if (substance instanceof OJFieldByteCode) {
        java.lang.reflect.Field field = ((OJFieldByteCode) substance).getByteCode();
        OJField result = (OJField) this.clone();
        // On remplace du ByteCode par du SourceCode
        FieldDeclaration fd =
            new FieldDeclaration(
                new ModifierList(field.getModifiers()),
                TypeName.forOJClass(OJClass.forClass(field.getDeclaringClass())),
                field.getName(),
                null);
        Environment env = substance.getDeclaringClass().getEnvironment();
        result.substance = new OJFieldSourceCode(env, substance.getDeclaringClass(), fd);
        return result;
      } else if (substance instanceof OJFieldSourceCode) {
        OJField result = (OJField) this.clone();
        result.substance =
            new OJFieldSourceCode(
                ((OJFieldSourceCode) this.substance).getEnvironment(),
                this.substance.getDeclaringClass(),
                (FieldDeclaration) this.substance.getSourceCode().makeRecursiveCopy());
        return result;
      }
    } catch (Exception e) {
      System.err.println("Failed to copy " + this + ": " + e);
      e.printStackTrace();
    }
    return null;
  }
コード例 #2
0
 public OJField(OJClass declarer, OJModifier modif, OJClass type, String name) {
   Environment env = declarer.getEnvironment();
   ModifierList modlist = new ModifierList();
   TypeName tname = TypeName.forOJClass(type);
   modlist.add(modif.toModifier());
   FieldDeclaration d = new FieldDeclaration(modlist, tname, name, null);
   this.substance = new OJFieldSourceCode(env, declarer, d);
 }
コード例 #3
0
 final void setType(OJClass type) throws CannotAlterException {
   definition.setTypeSpecifier(TypeName.forOJClass(type));
 }