1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 29 import java.util.*; 30 import org.aspectj.compiler.base.cst.*; 31 32 35 public abstract class TypeD extends ASTObject { 36 public abstract Type getType(); 37 38 public String getString() { 39 return getType().getString(); 40 } 41 42 public String toShortString() { 43 return getType().toShortString(); 44 } 45 46 public void checkSpec() { 47 49 if (fromSource() && 51 getType() != null && 52 !getType().isAnyType() && 53 !getType().isMissing() && 54 getType().getTypeDec() != null && 55 !getType().getTypeDec().isAccessible(this)) { 56 showError("can't access " + getType().getTypeDec().toShortString()); 57 } 58 } 59 60 public boolean isEquivalent(TypeD other) { 62 return getType().isEquivalent(other.getType()); 63 } 64 65 private static final int UNQUALIFIED = 1; 66 private static final int FULLY_QUALIFIED = 0; 67 private static final int NULL_TRICK = 2; 68 69 private int unparseRule; private boolean checkedQualification = false; 71 72 void makePublic(TypeDec typeDec) { 73 if (typeDec == null) return; 75 76 typeDec.getModifiers().setPublic(true); 77 if (typeDec.getEnclosingTypeDec() != null) { 78 makePublic(typeDec.getEnclosingTypeDec()); 79 } 80 } 81 82 83 void makeAccessible(Type type, ASTObject fromWhere) { 84 88 if (type.isAccessible(fromWhere, true)) return ; 89 90 getCompiler().showMessage(" fixing access to type: " + type.toShortString()); 91 92 makePublic(type.getTypeDec()); 93 } 94 95 96 public ASTObject postScope(ScopeWalker walker) { 98 if (!(walker instanceof NameHygienePass)) return this; 99 100 NameHygienePass pass = (NameHygienePass)walker; 101 102 104 if (checkedQualification) { 105 unparseRule = FULLY_QUALIFIED; 108 return this; 109 } 110 checkedQualification = true; 111 makeAccessible(getType(), this); 112 if (getType().getTypeDec() != null && getType().getTypeDec().hasGlobalName()) { 113 Type checkType = getType().getOutermostType(); 114 115 if (pass.canUseUnqualifiedName(checkType, this)) { 116 unparseRule = UNQUALIFIED; 117 } else if (pass.mustUseNullTrick(checkType, this)) { 118 unparseRule = NULL_TRICK; 119 } else { 120 unparseRule = FULLY_QUALIFIED; 121 } 122 } else { 123 unparseRule = FULLY_QUALIFIED; 124 } 125 return this; 127 } 128 129 130 public void unparse(CodeWriter writer) { 131 unparse(writer, false); 132 } 133 134 public void unparse(CodeWriter writer, boolean inExprPosition) { 135 136 Type type = getType(); 137 int realUnparseRule = unparseRule; 138 if (!writer.isOnlySignatures()) { 139 if (!checkedQualification) { 140 } 143 } 144 145 if (!inExprPosition && realUnparseRule == NULL_TRICK) { 146 realUnparseRule = FULLY_QUALIFIED; 147 } 148 149 switch (realUnparseRule) { 150 case UNQUALIFIED: 151 writer.write(getType().getExtendedId().replace('$', '.')); 152 break; 153 case FULLY_QUALIFIED: 154 writer.write(getType().getString()); 155 break; 156 case NULL_TRICK: 157 writer.write("(("); 160 writer.write(getType().getString()); 161 writer.write(")null)"); 162 break; 163 } 164 } 165 188 189 191 public TypeD(SourceLocation location) { 192 super(location); 193 194 } 195 196 197 public String getDefaultDisplayName() { 198 return "TypeD()"; 199 } 200 201 } 203 | Popular Tags |