@SuppressWarnings("unchecked")
private OutputFile generateDEXmlvmFile(final OutputFile classFile, boolean proxy, BundlePhase1 resources)
{
// Log.debug(TAG, "DExing:" + classFile.getFileName());
DirectClassFile directClassFile= new DirectClassFile(classFile.getDataAsBytes(), classFile.getFileName(), false);
directClassFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
try
{
directClassFile.getMagic();
}
catch (ParseException ex)
{
Log.debug(TAG, "Could not parse class.");
return null;
}
String packagePlusClassName= directClassFile.getThisClass().getClassType().toHuman();
// We want to prevent "red" classes from being loaded. If the there is a
// green class list, and this process is run by a library loaded, then
// we expect the class to be a library class. Hence, it must be in the
// green class list. If it's not, we discard it.
if (noGenRedClass && isRedType(packagePlusClassName))
{
Log.debug("Discarding red class: " + packagePlusClassName);
return null;
}
if (enableProxyReplacement && !proxy && LibraryLoader.hasProxy(packagePlusClassName))
{
return generateDEXmlvmFile(new OutputFile(LibraryLoader.getProxy(packagePlusClassName)), true, resources);
}
// If the class has the XMLVMIgnore annotation, it will be skipped.
if (hasAnnotation(directClassFile.getAttributes(), XMLVMIgnore.class))
{
return null;
}
// If the class is synthetic, we don't want to generate code from it
// while generating the wrapper code.
if (AccessFlags.isSynthetic(directClassFile.getAccessFlags()) && (arguments.option_target() == Targets.GENCWRAPPERS || arguments.option_target() == Targets.GENCSHARPWRAPPERS))
{
return null;
}
// This is for auxiliary analysis. We record all the types that are
// referenced.
Map<String, ReferenceKind> referencedTypes= new TreeMap<String, DEXmlvmOutputProcess.ReferenceKind>();
final Document document= createDocument();
TypePlusSuperType type= process(directClassFile, document.getRootElement(), referencedTypes);
String className= type.typeName.replace('.', '_');
String jClassName= document.getRootElement().getChild("class", InstructionProcessor.vm).getAttributeValue("name");
List<Element> methods= (List<Element>) document.getRootElement().getChild("class", InstructionProcessor.vm).getChildren("method", InstructionProcessor.vm);
if (arguments.option_enable_ref_counting())
{
if (REF_LOGGING)
{
Log.debug(TAG + "-ref", "Processing class: " + jClassName);
}
// We now need to mark up the code with retains/releases.
ReferenceCounting refCounting= new ReferenceCounting();
for (Element e : methods)
{
if (REF_LOGGING)
{
Log.debug(TAG + "-ref", "Processing method: " + e.getAttributeValue("name"));
}
try
{
refCounting.process(e);
}
catch (ReferenceCountingException ex)
{
Log.error(TAG + "-ref", "Processing method: " + e.getAttributeValue("name"));
Log.error(TAG + "-ref", "Failed while processing: " + ex.getMessage() + " in " + jClassName);
return null;
}
catch (DataConversionException ex)
{
Log.error(TAG + "-ref", "Processing method: " + e.getAttributeValue("name"));
Log.error(TAG + "-ref", "Failed while processing: " + ex.getMessage() + " in " + jClassName);
return null;
}
if (REF_LOGGING)
{
Log.debug(TAG + "-ref", "Done with " + e.getAttributeValue("name"));
}
}
if (REF_LOGGING)
{
Log.debug(TAG + "-ref", "Done processing methods!");
}
}
Element classElement= document.getRootElement().getChild("class", InstructionProcessor.vm);
// If the class has the XMLVMSkeletonOnly annotation we add it to the
// class element, so that the stylesheet can use the information.
boolean skeletonOnly= hasAnnotation(directClassFile.getAttributes(), XMLVMSkeletonOnly.class);
if (skeletonOnly)
{
classElement.setAttribute("skeletonOnly", "true");
Annotation skeletonAnnotation= getAnnotation(directClassFile.getAttributes(), XMLVMSkeletonOnly.class);
for (NameValuePair pair : skeletonAnnotation.getNameValuePairs())
{
if (pair.getName().getString().equals("references"))
{
CstArray.List clazzArrayList= ((CstArray) pair.getValue()).getList();
for (int i= 0; i < clazzArrayList.size(); i++)
{
addReference(referencedTypes, ((CstType) clazzArrayList.get(i)).toHuman(), ReferenceKind.USAGE);
}
}
}
}
Annotation delegateAnnotation= getAnnotation(directClassFile.getAttributes(), XMLVMDelegate.class);
if (delegateAnnotation != null)
{
for (NameValuePair pair : delegateAnnotation.getNameValuePairs())
{
if (pair.getName().getString().equals("protocolType"))