Package com.android.dx.cf.direct

Examples of com.android.dx.cf.direct.DirectClassFile


    TypeHierarchy result= new TypeHierarchy();
    final String basePath= library.getAbsolutePath();
    for (UniversalFile clazz : classes)
    {
      String fileName= clazz.getRelativePath(basePath).replace('\\', '.');
      DirectClassFile classFile= new DirectClassFile(clazz.getFileAsBytes(), fileName, false);
      classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
      try
      {
        classFile.getMagic();
      }
      catch (ParseException ex)
      {
        continue;
      }

      final int DOT_CLASS_LENGTH= ".class".length();
      String className= fileName.substring(0, fileName.length() - DOT_CLASS_LENGTH).replace('/', '.');

      // Super-class.
      if (classFile.getSuperclass() != null)
      {
        String superClassName= Util.parseClassName(classFile.getSuperclass().getClassType().getClassName()).toString();
        result.addDirectSubType(className, superClassName);
      }

      // Interfaces
      TypeList interfaces= classFile.getInterfaces();
      if (interfaces != null)
      {
        for (int i= 0; i < interfaces.size(); i++)
        {
          String interfaceName= Util.parseClassName(interfaces.getType(i).getClassName()).toString();
View Full Code Here


   */
  private static void getAllDependencies(byte[] bytes, String relativePath, Dependencies.ClassDeps classDeps)
  {

    Log.debug(TAG, relativePath);
    DirectClassFile classFile= new DirectClassFile(bytes, relativePath, false);
    classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
    try
    {
      classFile.getMagic();
    }
    catch (ParseException ex)
    {
      Log.warn(TAG, "Put to red-list as it couldn't be parsed: " + relativePath);
      BAD_CLASSES.add(classDeps.getClassName());
      return;
    }

    String superClassName= "";
    // This can happen for java.lang.Object.
    if (classFile.getSuperclass() != null)
    {
      superClassName= Util.parseClassName(classFile.getSuperclass().getClassType().getClassName()).toString();
    }

    // Super Class
    if (!superClassName.isEmpty())
    {
      Set<String> superClass= new HashSet<String>();
      superClass.add(superClassName.replace('/', '.'));
      classDeps.getMethodDeps("SUPER").addDependency(superClassName.replace('/', '.'), "");
    }

    // Interfaces
    TypeList interfaces= classFile.getInterfaces();
    if (interfaces.size() > 0)
    {
      Set<String> interfaceList= new HashSet<String>();
      for (int i= 0; i < interfaces.size(); ++i)
      {
        interfaceList.add(Util.parseClassName(interfaces.getType(i).getClassName()).toString());
        classDeps.getMethodDeps("INTERFACES").addDependency(Util.parseClassName(interfaces.getType(i).getClassName()).toString(), "");
      }
    }

    // Methods
    MethodList methods= classFile.getMethods();
    for (int i= 0; i < methods.size(); i++)
    {
      Method method= methods.get(i);
      // CstMethodRef methodRef = new
      // CstMethodRef(method.getDefiningClass(), method.getNat());
View Full Code Here

     * @param args command-line arguments
     * @return {@code non-null;} the translated class
     */
    private static ClassDefItem translate0(String filePath, byte[] bytes,
            CfOptions args) {
        DirectClassFile cf =
            new DirectClassFile(bytes, filePath, args.strictNameCheck);

        cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
        cf.getMagic();

        OptimizerOptions.loadOptimizeLists(args.optimizeListFile,
                args.dontOptimizeListFile);

        // Build up a class to output.

        CstType thisClass = cf.getThisClass();
        int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER;
        CstUtf8 sourceFile = (args.positionInfo == PositionList.NONE) ? null :
            cf.getSourceFile();
        ClassDefItem out =
            new ClassDefItem(thisClass, classAccessFlags,
                    cf.getSuperclass(), cf.getInterfaces(), sourceFile);

        Annotations classAnnotations =
            AttributeTranslator.getClassAnnotations(cf, args);
        if (classAnnotations.size() != 0) {
            out.setClassAnnotations(classAnnotations);
View Full Code Here

                    if (!name.endsWith(".class")) {
                        return true;
                    }

                    ByteArray ba = new ByteArray(bytes);
                    DirectClassFile cf
                        = new DirectClassFile(ba, name, true);

                    cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
                    AttributeList attributes = cf.getAttributes();
                    Attribute att;

                    String cfClassName
                            = cf.getThisClass().getClassType().getClassName();

                    if (cfClassName.endsWith(PACKAGE_INFO)) {
                        att = attributes.findFirst(
                                AttRuntimeInvisibleAnnotations.ATTRIBUTE_NAME);
View Full Code Here

        /*
         * First, parse the file completely, so we can safely refer to
         * attributes, etc.
         */
        classFile = new DirectClassFile(ba, getFilePath(), getStrictParse());
        classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
        classFile.getMagic(); // Force parsing to happen.

        // Next, reparse it and observe the process.
        DirectClassFile liveCf =
            new DirectClassFile(ba, getFilePath(), getStrictParse());
        liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE);
        liveCf.setObserver(this);
        liveCf.getMagic(); // Force parsing to happen.
    }
View Full Code Here

  @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"))
View Full Code Here

TOP

Related Classes of com.android.dx.cf.direct.DirectClassFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.