@Override public void writeClassFile( OutputStream out, Symbol.ClassSymbol c ) throws StringOverflow, IOException, PoolOverflow { JavaFileObject sourceFile = c.sourcefile; if( sourceFile instanceof ISelfCompiledFile && ((ISelfCompiledFile)sourceFile).isSelfCompile() ) { out.write( ((ISelfCompiledFile)sourceFile).compile() ); } else { super.writeClassFile( out, c ); } } }
/** Get the ClassWriter instance for this context. */ public static ClassWriter instance(Context context) { ClassWriter instance = context.get(classWriterKey); if (instance == null) instance = new ClassWriter(context); return instance; }
/** Write field symbol, entering all references into constant pool. */ void writeField(VarSymbol v) { int flags = adjustFlags(v.flags()); databuf.appendChar(flags); if (dumpFieldModifiers) { log.errWriter.println("FIELD " + fieldName(v)); log.errWriter.println("---" + flagNames(v.flags())); } databuf.appendChar(pool.put(fieldName(v))); databuf.appendChar(pool.put(typeSig(v.erasure(types)))); int acountIdx = beginAttrs(); int acount = 0; if (v.getConstValue() != null) { int alenIdx = writeAttr(names.ConstantValue); databuf.appendChar(pool.put(v.getConstValue())); endAttr(alenIdx); acount++; } acount += writeMemberAttrs(v); endAttrs(acountIdx, acount); }
int acount = 0; if ((flags & DEPRECATED) != 0) { int alenIdx = writeAttr(names.Deprecated); endAttr(alenIdx); acount++; int alenIdx = writeAttr(names.Enum); endAttr(alenIdx); acount++; int alenIdx = writeAttr(names.Synthetic); endAttr(alenIdx); acount++; int alenIdx = writeAttr(names.Bridge); endAttr(alenIdx); acount++; int alenIdx = writeAttr(names.Varargs); endAttr(alenIdx); acount++; int alenIdx = writeAttr(names.Annotation); endAttr(alenIdx); acount++;
/** Given a type t, return the extended class name of its erasure in * external representation. */ public Name xClassName(Type t) { if (t.tag == CLASS) { return names.fromUtf(externalize(t.tsym.flatName())); } else if (t.tag == ARRAY) { return typeSig(types.erasure(t)); } else { throw new AssertionError("xClassName"); } }
int flags = adjustFlags(c.flags() & ~DEFAULT); if ((flags & PROTECTED) != 0) flags |= PUBLIC; flags = flags & ClassFlags & ~STRICTFP; pw.println(); pw.println("CLASSFILE " + c.getQualifiedName()); pw.println("---" + flagNames(flags)); case MTH: if ((e.sym.flags() & HYPOTHETICAL) == 0) methodsCount++; break; case TYP: enterInner((ClassSymbol)e.sym); break; default : Assert.error(); enterInner(local); writeFields(c.members().elems); databuf.appendChar(methodsCount); writeMethods(c.members().elems); int acountIdx = beginAttrs(); int acount = 0; if (sigReq) { Assert.check(source.allowGenerics()); int alenIdx = writeAttr(names.Signature); if (typarams.length() != 0) signatureGen.assembleParamsSig(typarams); signatureGen.assembleSig(supertype); databuf.appendChar(pool.put(signatureGen.toName()));
int flags = adjustFlags(c.flags()); if ((flags & PROTECTED) != 0) flags |= PUBLIC; flags = flags & ClassFlags & ~STRICTFP; log.errWriter.println(); log.errWriter.println("CLASSFILE " + c.getQualifiedName()); log.errWriter.println("---" + flagNames(flags)); case MTH: if ((e.sym.flags() & HYPOTHETICAL) == 0) methodsCount++; break; case TYP: enterInner((ClassSymbol)e.sym); break; default : assert false; writeFields(c.members().elems); databuf.appendChar(methodsCount); writeMethods(c.members().elems); int acountIdx = beginAttrs(); int acount = 0; if (sigReq) { assert source.allowGenerics(); int alenIdx = writeAttr(names.Signature); if (typarams.length() != 0) assembleParamsSig(typarams); assembleSig(supertype); for (List<Type> l = interfaces; l.nonEmpty(); l = l.tail) assembleSig(l.head); databuf.appendChar(pool.put(sigbuf.toName(names))); sigbuf.reset();
: CONSTANT_Methodref); poolbuf.appendChar(pool.put(m.owner)); poolbuf.appendChar(pool.put(nameType(m))); } else if (value instanceof VarSymbol) { VarSymbol v = (VarSymbol)value; poolbuf.appendByte(CONSTANT_Fieldref); poolbuf.appendChar(pool.put(v.owner)); poolbuf.appendChar(pool.put(nameType(v))); } else if (value instanceof Name) { poolbuf.appendByte(CONSTANT_Utf8); poolbuf.appendByte(CONSTANT_Class); if (c.type.tag == ARRAY) { poolbuf.appendChar(pool.put(typeSig(c.type))); } else { poolbuf.appendChar(pool.put(names.fromUtf(externalize(c.flatname)))); enterInner(c); poolbuf.appendByte(CONSTANT_NameandType); poolbuf.appendChar(pool.put(nt.name)); poolbuf.appendChar(pool.put(typeSig(nt.type))); } else if (value instanceof Integer) { poolbuf.appendByte(CONSTANT_Integer); } else if (value instanceof Type) { Type type = (Type)value; if (type.tag == CLASS) enterInner((ClassSymbol)type.tsym); poolbuf.appendByte(CONSTANT_Class); poolbuf.appendChar(pool.put(xClassName(type)));
int acountIdx = beginAttrs(); int acount = 0; int alenIdx = writeAttr(names.LineNumberTable); databuf.appendChar(code.lineInfo.length()); for (List<char[]> l = code.lineInfo.reverse(); for (int i = 0; i < l.head.length; i++) databuf.appendChar(l.head[i]); endAttr(alenIdx); acount++; int alenIdx = writeAttr(names.CharacterRangeTable); int crtIdx = beginAttrs(); int crtEntries = crt.writeCRT(databuf, code.lineMap, log); endAttrs(crtIdx, crtEntries); endAttr(alenIdx); acount++; int alenIdx = writeAttr(names.LocalVariableTable); databuf.appendChar(code.getLVTSize()); for (int i=0; i<code.varBufferSize; i++) { databuf.appendChar(pool.put(sym.name)); Type vartype = sym.erasure(types); databuf.appendChar(pool.put(typeSig(vartype))); databuf.appendChar(var.reg); if (needsLocalVariableTypeEntry(var.sym.type)) { nGenericVars++;
int acountIdx = beginAttrs(); int acount = 0; int alenIdx = writeAttr(names.LineNumberTable); databuf.appendChar(code.lineInfo.length()); for (List<char[]> l = code.lineInfo.reverse(); for (int i = 0; i < l.head.length; i++) databuf.appendChar(l.head[i]); endAttr(alenIdx); acount++; int alenIdx = writeAttr(names.CharacterRangeTable); int crtIdx = beginAttrs(); int crtEntries = crt.writeCRT(databuf, code.lineMap, log); endAttrs(crtIdx, crtEntries); endAttr(alenIdx); acount++; int alenIdx = writeAttr(names.LocalVariableTable); databuf.appendChar(code.varBufferSize); if (!types.isSameType(sym.type, vartype)) nGenericVars++; databuf.appendChar(pool.put(typeSig(vartype))); databuf.appendChar(var.reg); endAttr(alenIdx); acount++;
/** Write "inner classes" attribute. */ void writeInnerClasses() { int alenIdx = writeAttr(names.InnerClasses); databuf.appendChar(innerClassesQueue.length()); for (List<ClassSymbol> l = innerClassesQueue.toList(); l.nonEmpty(); l = l.tail) { ClassSymbol inner = l.head; char flags = (char) adjustFlags(inner.flags_field); if (dumpInnerClassModifiers) { log.errWriter.println("INNERCLASS " + inner.name); log.errWriter.println("---" + flagNames(flags)); } databuf.appendChar(pool.get(inner)); databuf.appendChar( inner.owner.kind == TYP ? pool.get(inner.owner) : 0); databuf.appendChar( inner.name.len != 0 ? pool.get(inner.name) : 0); databuf.appendChar(flags); } endAttr(alenIdx); }
/** Write member (field or method) attributes; * return number of attributes written. */ int writeMemberAttrs(Symbol sym) { int acount = writeFlagAttrs(sym.flags()); long flags = sym.flags(); if (source.allowGenerics() && (flags & (SYNTHETIC|BRIDGE)) != SYNTHETIC && (flags & ANONCONSTR) == 0 && (!types.isSameType(sym.type, sym.erasure(types)) || hasTypeVar(sym.type.getThrownTypes()))) { // note that a local class with captured variables // will get a signature attribute int alenIdx = writeAttr(names.Signature); databuf.appendChar(pool.put(typeSig(sym.type))); endAttr(alenIdx); acount++; } acount += writeJavaAnnotations(sym.getAnnotationMirrors()); return acount; }
/** Write member (field or method) attributes; * return number of attributes written. */ int writeMemberAttrs(Symbol sym) { int acount = writeFlagAttrs(sym.flags()); long flags = sym.flags(); if (source.allowGenerics() && (flags & (SYNTHETIC|BRIDGE)) != SYNTHETIC && (flags & ANONCONSTR) == 0 && (!types.isSameType(sym.type, sym.erasure(types)) || signatureGen.hasTypeVar(sym.type.getThrownTypes()))) { // note that a local class with captured variables // will get a signature attribute int alenIdx = writeAttr(names.Signature); databuf.appendChar(pool.put(typeSig(sym.type))); endAttr(alenIdx); acount++; } acount += writeJavaAnnotations(sym.getRawAttributes()); acount += writeTypeAnnotations(sym.getRawTypeAttributes(), false); return acount; }
ListBuffer<Attribute.Compound> invisibles = new ListBuffer<Attribute.Compound>(); for (Attribute.Compound a : attrs) { switch (getRetention(a.type.tsym)) { case SOURCE: break; case CLASS: invisibles.append(a); break; int attrIndex = writeAttr(names.RuntimeVisibleAnnotations); databuf.appendChar(visibles.length()); for (Attribute.Compound a : visibles) writeCompoundAttribute(a); endAttr(attrIndex); attrCount++; int attrIndex = writeAttr(names.RuntimeInvisibleAnnotations); databuf.appendChar(invisibles.length()); for (Attribute.Compound a : invisibles) writeCompoundAttribute(a); endAttr(attrIndex); attrCount++;
/** Write the EnclosingMethod attribute with a specified name. * Returns the number of attributes written (0 or 1). */ protected int writeEnclosingMethodAttribute(Name attributeName, ClassSymbol c) { if (c.owner.kind != MTH && // neither a local class c.name != names.empty) // nor anonymous return 0; int alenIdx = writeAttr(attributeName); ClassSymbol enclClass = c.owner.enclClass(); MethodSymbol enclMethod = (c.owner.type == null // local to init block || c.owner.kind != MTH) // or member init ? null : (MethodSymbol)c.owner; databuf.appendChar(pool.put(enclClass)); databuf.appendChar(enclMethod == null ? 0 : pool.put(nameType(c.owner))); endAttr(alenIdx); return 1; }
int attrIndex = writeAttr(names.RuntimeVisibleAnnotations); databuf.appendChar(visibles.length()); for (Attribute.Compound a : visibles) writeCompoundAttribute(a); endAttr(attrIndex); attrCount++; int attrIndex = writeAttr(names.RuntimeInvisibleAnnotations); databuf.appendChar(invisibles.length()); for (Attribute.Compound a : invisibles) writeCompoundAttribute(a); endAttr(attrIndex); attrCount++;
com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()); ClassReader reader = ClassReader.instance(task.getContext()); ClassWriter writer = ClassWriter.instance(task.getContext()); Symtab syms = Symtab.instance(task.getContext()); Attribute.Compound proprietary =
void assembleClassSig(Type type) { ClassType ct = (ClassType)type; ClassSymbol c = (ClassSymbol)ct.tsym; enterInner(c); Type outer = ct.getEnclosingType(); if (outer.allparams().nonEmpty()) { boolean rawOuter = c.owner.kind == MTH || // either a local class c.name == names.empty; // or anonymous assembleClassSig(rawOuter ? types.erasure(outer) : outer); sigbuf.appendByte('.'); assert c.flatname.startsWith(c.owner.enclClass().flatname); sigbuf.appendName(rawOuter ? c.flatname.subName(c.owner.enclClass() .flatname.len+1, c.flatname.len) : c.name); } else { sigbuf.appendBytes(externalize(c.flatname)); } if (ct.getTypeArguments().nonEmpty()) { sigbuf.appendByte('<'); assembleSig(ct.getTypeArguments()); sigbuf.appendByte('>'); } }
int attrIndex = writeAttr(names.RuntimeVisibleTypeAnnotations); databuf.appendChar(visibles.length()); for (Attribute.TypeCompound p : visibles) writeTypeAnnotation(p); endAttr(attrIndex); attrCount++; int attrIndex = writeAttr(names.RuntimeInvisibleTypeAnnotations); databuf.appendChar(invisibles.length()); for (Attribute.TypeCompound p : invisibles) writeTypeAnnotation(p); endAttr(attrIndex); attrCount++;
@Override protected void classReference(ClassSymbol c) { enterInner(c); }