001 /* 002 * The JastAdd Extensible Java Compiler (http://jastadd.org) is covered 003 * by the modified BSD License. You should have received a copy of the 004 * modified BSD license with this compiler. 005 * 006 * Copyright (c) 2005-2008, Torbjorn Ekman 007 * All rights reserved. 008 */ 009 010 aspect GenericsPrettyPrint { 011 public void TypeVariable.toString(StringBuffer s) { 012 s.append(name()); 013 if(getNumTypeBound() > 0) { 014 s.append(" extends "); 015 s.append(getTypeBound(0).type().fullName()); 016 for(int i = 1; i < getNumTypeBound(); i++) { 017 s.append(" & "); 018 s.append(getTypeBound(i).type().fullName()); 019 } 020 } 021 } 022 023 public void ParTypeAccess.toString(StringBuffer s) { 024 getTypeAccess().toString(s); 025 s.append("<"); 026 for(int i = 0; i < getNumTypeArgument(); i++) { 027 if(i != 0) 028 s.append(", "); 029 getTypeArgument(i).toString(s); 030 } 031 s.append(">"); 032 } 033 034 public void ParClassDecl.toString(StringBuffer s) { 035 getModifiers().toString(s); 036 s.append("class " + getID()); 037 s.append('<'); 038 if (getNumArgument() > 0) { 039 getArgument(0).toString(s); 040 for (int i = 1; i < getNumArgument(); i++) { 041 s.append(", "); 042 getArgument(i).toString(s); 043 } 044 } 045 s.append('>'); 046 if(hasSuperClassAccess()) { 047 s.append(" extends "); 048 getSuperClassAccess().toString(s); 049 } 050 if(getNumImplements() > 0) { 051 s.append(" implements "); 052 getImplements(0).toString(s); 053 for(int i = 1; i < getNumImplements(); i++) { 054 s.append(", "); 055 getImplements(i).toString(s); 056 } 057 } 058 ppBodyDecls(s); 059 } 060 061 private void GenericClassDecl.ppTypeParameters(StringBuffer s) { 062 s.append('<'); 063 if (getNumTypeParameter() > 0) { 064 getTypeParameter(0).toString(s); 065 for (int i = 1; i < getNumTypeParameter(); i++) { 066 s.append(", "); 067 getTypeParameter(i).toString(s); 068 } 069 } 070 s.append('>'); 071 } 072 073 public void GenericClassDecl.toString(StringBuffer s) { 074 getModifiers().toString(s); 075 s.append("class " + getID()); 076 ppTypeParameters(s); 077 if(hasSuperClassAccess()) { 078 s.append(" extends "); 079 getSuperClassAccess().toString(s); 080 } 081 if(getNumImplements() > 0) { 082 s.append(" implements "); 083 getImplements(0).toString(s); 084 for(int i = 1; i < getNumImplements(); i++) { 085 s.append(", "); 086 getImplements(i).toString(s); 087 } 088 } 089 090 /* 091 s.append(" instantiated with: "); 092 for(int i = 0; i < getNumParTypeDecl(); i++) { 093 if(i != 0) s.append(", "); 094 ParTypeDecl decl = getParTypeDecl(i); 095 s.append("<"); 096 for(int j = 0; j < decl.getNumArgument(); j++) { 097 if(j != 0) s.append(", "); 098 s.append(decl.getArgument(j).type().fullName()); 099 } 100 s.append(">"); 101 } 102 */ 103 104 ppBodyDecls(s); 105 106 /* 107 for(int i = 0; i < getNumParTypeDecl(); i++) { 108 ParClassDecl decl = getParTypeDecl(i); 109 decl.toString(s); 110 } 111 */ 112 113 } 114 115 public void GenericInterfaceDecl.toString(StringBuffer s) { 116 getModifiers().toString(s); 117 s.append("interface " + getID()); 118 s.append('<'); 119 if (getNumTypeParameter() > 0) { 120 getTypeParameter(0).toString(s); 121 for (int i = 1; i < getNumTypeParameter(); i++) { 122 s.append(", "); 123 getTypeParameter(i).toString(s); 124 } 125 } 126 s.append('>'); 127 if(getNumSuperInterfaceId() > 0) { 128 s.append(" extends "); 129 getSuperInterfaceId(0).toString(s); 130 for(int i = 1; i < getNumSuperInterfaceId(); i++) { 131 s.append(", "); 132 getSuperInterfaceId(i).toString(s); 133 } 134 } 135 136 /* 137 138 s.append(" instantiated with: "); 139 for(int i = 0; i < getNumParTypeDecl(); i++) { 140 if(i != 0) s.append(", "); 141 ParTypeDecl decl = getParTypeDecl(i); 142 s.append("<"); 143 for(int j = 0; j < decl.getNumArgument(); j++) { 144 if(j != 0) s.append(", "); 145 s.append(decl.getArgument(j).type().fullName()); 146 } 147 s.append(">"); 148 } 149 */ 150 151 ppBodyDecls(s); 152 153 /* 154 for(int i = 0; i < getNumParTypeDecl(); i++) { 155 ParInterfaceDecl decl = getParTypeDecl(i); 156 decl.toString(s); 157 } 158 */ 159 } 160 161 public void Wildcard.toString(StringBuffer s) { 162 s.append("?"); 163 } 164 public void WildcardExtends.toString(StringBuffer s) { 165 s.append("? extends "); 166 getAccess().toString(s); 167 } 168 public void WildcardSuper.toString(StringBuffer s) { 169 s.append("? super "); 170 getAccess().toString(s); 171 } 172 173 }