• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ClassDef类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.android.dex.ClassDef的典型用法代码示例。如果您正苦于以下问题:Java ClassDef类的具体用法?Java ClassDef怎么用?Java ClassDef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ClassDef类属于com.android.dex包,在下文中一共展示了ClassDef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: transformClassDef

import com.android.dex.ClassDef; //导入依赖的package包/类
/**
 * Reads a class_def_item beginning at {@code in} and writes the index and
 * data.
 */
private void transformClassDef(Dex in, ClassDef classDef, IndexMap indexMap) {
    idsDefsOut.assertFourByteAligned();
    idsDefsOut.writeInt(classDef.getTypeIndex());
    idsDefsOut.writeInt(classDef.getAccessFlags());
    idsDefsOut.writeInt(classDef.getSupertypeIndex());
    idsDefsOut.writeInt(classDef.getInterfacesOffset());

    int sourceFileIndex = indexMap.adjustString(classDef.getSourceFileIndex());
    idsDefsOut.writeInt(sourceFileIndex);

    int annotationsOff = classDef.getAnnotationsOffset();
    idsDefsOut.writeInt(indexMap.adjustAnnotationDirectory(annotationsOff));

    int classDataOff = classDef.getClassDataOffset();
    if (classDataOff == 0) {
        idsDefsOut.writeInt(0);
    } else {
        idsDefsOut.writeInt(classDataOut.getPosition());
        ClassData classData = in.readClassData(classDef);
        transformClassData(in, classData, indexMap);
    }

    int staticValuesOff = classDef.getStaticValuesOffset();
    idsDefsOut.writeInt(indexMap.adjustStaticValues(staticValuesOff));
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:30,代码来源:DexMerger.java


示例2: findAssignableTypes

import com.android.dex.ClassDef; //导入依赖的package包/类
/**
 * Returns the set of types that can be assigned to {@code typeIndex}.
 */
private Set<Integer> findAssignableTypes(Dex dex, int typeIndex) {
    Set<Integer> assignableTypes = new HashSet<Integer>();
    assignableTypes.add(typeIndex);

    for (ClassDef classDef : dex.classDefs()) {
        if (assignableTypes.contains(classDef.getSupertypeIndex())) {
            assignableTypes.add(classDef.getTypeIndex());
            continue;
        }

        for (int implemented : classDef.getInterfaces()) {
            if (assignableTypes.contains(implemented)) {
                assignableTypes.add(classDef.getTypeIndex());
                break;
            }
        }
    }

    return assignableTypes;
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:24,代码来源:FindUsages.java


示例3: loadStaticValues

import com.android.dex.ClassDef; //导入依赖的package包/类
private void loadStaticValues(ClassDef cls, List<FieldNode> staticFields) throws DecodeException {
	for (FieldNode f : staticFields) {
		if (f.getAccessFlags().isFinal()) {
			f.addAttr(FieldInitAttr.NULL_VALUE);
		}
	}
	int offset = cls.getStaticValuesOffset();
	if (offset == 0) {
		return;
	}
	Dex.Section section = dex.openSection(offset);
	StaticValuesParser parser = new StaticValuesParser(dex, section);
	parser.processFields(staticFields);

	// process const fields
	root().getConstValues().processConstFields(this, staticFields);
}
 
开发者ID:skylot,项目名称:jadx,代码行数:18,代码来源:ClassNode.java


示例4: readSortableTypes

import com.android.dex.ClassDef; //导入依赖的package包/类
/**
 * Reads just enough data on each class so that we can sort it and then find
 * it later.
 */
private void readSortableTypes(SortableType[] sortableTypes, Dex buffer,
        IndexMap indexMap) {
    for (ClassDef classDef : buffer.classDefs()) {
        SortableType sortableType = indexMap.adjust(new SortableType(buffer, classDef));
        int t = sortableType.getTypeIndex();
        if (sortableTypes[t] == null) {
            sortableTypes[t] = sortableType;
        } else if (collisionPolicy != CollisionPolicy.KEEP_FIRST) {
            throw new DexException("Multiple dex files define "
                    + buffer.typeNames().get(classDef.getTypeIndex()));
        }
    }
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:18,代码来源:DexMerger.java


示例5: tryAssignDepth

import com.android.dex.ClassDef; //导入依赖的package包/类
/**
 * Assigns this type's depth if the depths of its supertype and implemented
 * interfaces are known. Returns false if the depth couldn't be computed
 * yet.
 */
public boolean tryAssignDepth(SortableType[] types) {
    int max;
    if (classDef.getSupertypeIndex() == ClassDef.NO_INDEX) {
        max = 0; // this is Object.class or an interface
    } else {
        SortableType sortableSupertype = types[classDef.getSupertypeIndex()];
        if (sortableSupertype == null) {
            max = 1; // unknown, so assume it's a root.
        } else if (sortableSupertype.depth == -1) {
            return false;
        } else {
            max = sortableSupertype.depth;
        }
    }

    for (short interfaceIndex : classDef.getInterfaces()) {
        SortableType implemented = types[interfaceIndex];
        if (implemented == null) {
            max = Math.max(max, 1); // unknown, so assume it's a root.
        } else if (implemented.depth == -1) {
            return false;
        } else {
            max = Math.max(max, implemented.depth);
        }
    }

    depth = max + 1;
    return true;
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:35,代码来源:SortableType.java


示例6: adjust

import com.android.dex.ClassDef; //导入依赖的package包/类
public ClassDef adjust(ClassDef classDef) {
    return new ClassDef(target, classDef.getOffset(), adjustType(classDef.getTypeIndex()),
            classDef.getAccessFlags(), adjustType(classDef.getSupertypeIndex()),
            adjustTypeListOffset(classDef.getInterfacesOffset()), classDef.getSourceFileIndex(),
            classDef.getAnnotationsOffset(), classDef.getClassDataOffset(),
            classDef.getStaticValuesOffset());
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:8,代码来源:IndexMap.java


示例7: grep

import com.android.dex.ClassDef; //导入依赖的package包/类
/**
 * Prints usages to out. Returns the number of matches found.
 */
public int grep() {
    for (ClassDef classDef : dex.classDefs()) {
        currentClass = classDef;
        currentMethod = null;

        if (classDef.getClassDataOffset() == 0) {
            continue;
        }

        ClassData classData = dex.readClassData(classDef);

        // find the strings in encoded constants
        int staticValuesOffset = classDef.getStaticValuesOffset();
        if (staticValuesOffset != 0) {
            readArray(new EncodedValueReader(dex.open(staticValuesOffset)));
        }

        // find the strings in method bodies
        for (ClassData.Method method : classData.allMethods()) {
            currentMethod = method;
            if (method.getCodeOffset() != 0) {
                codeReader.visitAll(dex.readCode(method).getInstructions());
            }
        }
    }

    currentClass = null;
    currentMethod = null;
    return count;
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:34,代码来源:Grep.java


示例8: findUsages

import com.android.dex.ClassDef; //导入依赖的package包/类
/**
 * Prints usages to out.
 */
public void findUsages() {
    if (fieldIds == null || methodIds == null) {
        return;
    }

    for (ClassDef classDef : dex.classDefs()) {
        currentClass = classDef;
        currentMethod = null;

        if (classDef.getClassDataOffset() == 0) {
            continue;
        }

        ClassData classData = dex.readClassData(classDef);
        for (ClassData.Field field : classData.allFields()) {
            int fieldIndex = field.getFieldIndex();
            if (fieldIds.contains(fieldIndex)) {
                out.println(location() + " field declared " + dex.fieldIds().get(fieldIndex));
            }
        }

        for (ClassData.Method method : classData.allMethods()) {
            currentMethod = method;
            int methodIndex = method.getMethodIndex();
            if (methodIds.contains(methodIndex)) {
                out.println(location() + " method declared " + dex.methodIds().get(methodIndex));
            }
            if (method.getCodeOffset() != 0) {
                codeReader.visitAll(dex.readCode(method).getInstructions());
            }
        }
    }

    currentClass = null;
    currentMethod = null;
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:40,代码来源:FindUsages.java


示例9: printClassDefs

import com.android.dex.ClassDef; //导入依赖的package包/类
private void printClassDefs() {
    int index = 0;
    for (ClassDef classDef : dex.classDefs()) {
        System.out.println("class def " + index + ": " + classDef);
        index++;
    }
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:8,代码来源:DexIndexPrinter.java


示例10: readSortableTypes

import com.android.dex.ClassDef; //导入依赖的package包/类
/**
 * Reads just enough data on each class so that we can sort it and then find
 * it later.
 */
private void readSortableTypes(SortableType[] sortableTypes, Dex buffer,
        IndexMap indexMap) {
    for (ClassDef classDef : buffer.classDefs()) {
        SortableType sortableType = indexMap.adjust(
                new SortableType(buffer, indexMap, classDef));
        int t = sortableType.getTypeIndex();
        if (sortableTypes[t] == null) {
            sortableTypes[t] = sortableType;
        } else if (collisionPolicy != CollisionPolicy.KEEP_FIRST) {
            throw new DexException("Multiple dex files define "
                    + buffer.typeNames().get(classDef.getTypeIndex()));
        }
    }
}
 
开发者ID:johnlee175,项目名称:dex,代码行数:19,代码来源:DexMerger.java


示例11: tryAssignDepth

import com.android.dex.ClassDef; //导入依赖的package包/类
/**
 * Assigns this type's depth if the depths of its supertype and implemented
 * interfaces are known. Returns false if the depth couldn't be computed
 * yet.
 */
public boolean tryAssignDepth(SortableType[] types) {
    int max;
    if (classDef.getSupertypeIndex() == ClassDef.NO_INDEX) {
        max = 0; // this is Object.class or an interface
    } else if (classDef.getSupertypeIndex() == classDef.getTypeIndex()) {
        // This is an invalid class extending itself.
        throw new DexException("Class with type index " + classDef.getTypeIndex()
                + " extends itself");
    } else {
        SortableType sortableSupertype = types[classDef.getSupertypeIndex()];
        if (sortableSupertype == null) {
            max = 1; // unknown, so assume it's a root.
        } else if (sortableSupertype.depth == -1) {
            return false;
        } else {
            max = sortableSupertype.depth;
        }
    }

    for (short interfaceIndex : classDef.getInterfaces()) {
        SortableType implemented = types[interfaceIndex];
        if (implemented == null) {
            max = Math.max(max, 1); // unknown, so assume it's a root.
        } else if (implemented.depth == -1) {
            return false;
        } else {
            max = Math.max(max, implemented.depth);
        }
    }

    depth = max + 1;
    return true;
}
 
开发者ID:johnlee175,项目名称:dex,代码行数:39,代码来源:SortableType.java


示例12: loadAnnotations

import com.android.dex.ClassDef; //导入依赖的package包/类
private void loadAnnotations(ClassDef cls) {
	int offset = cls.getAnnotationsOffset();
	if (offset != 0) {
		try {
			new AnnotationsParser(this).parse(offset);
		} catch (Exception e) {
			LOG.error("Error parsing annotations in {}", this, e);
		}
	}
}
 
开发者ID:niranjan94,项目名称:show-java,代码行数:11,代码来源:ClassNode.java


示例13: loadClasses

import com.android.dex.ClassDef; //导入依赖的package包/类
public void loadClasses() throws DecodeException {
	for (ClassDef cls : dexBuf.classDefs()) {
		ClassNode clsNode = new ClassNode(this, cls);
		classes.add(clsNode);
		clsMap.put(clsNode.getClassInfo(), clsNode);
	}
}
 
开发者ID:niranjan94,项目名称:show-java,代码行数:8,代码来源:DexNode.java


示例14: assertMultidexOutput

import com.android.dex.ClassDef; //导入依赖的package包/类
private Multimap<String, String> assertMultidexOutput(int expectedClassCount,
    Path outputArchive, Set<String> mainDexList) throws IOException {
  SetMultimap<String, String> dexFiles = HashMultimap.create();
  try (ZipFile output = new ZipFile(outputArchive.toFile())) {
    Enumeration<? extends ZipEntry> entries = output.entries();
    while (entries.hasMoreElements()) {
      ZipEntry entry = entries.nextElement();
      assertThat(entry.getName()).containsMatch("classes[2-9]?.dex");
      Dex dex = new Dex(output.getInputStream(entry));
      for (ClassDef clazz : dex.classDefs()) {
        dexFiles.put(entry.getName(),
            toSlashedClassName(dex.typeNames().get(clazz.getTypeIndex())));
      }
    }
  }
  assertThat(dexFiles.keySet().size()).isAtLeast(2); // test sanity
  assertThat(dexFiles.size()).isAtLeast(1); // test sanity
  assertThat(dexFiles).hasSize(expectedClassCount);
  for (int i = 0; i < dexFiles.keySet().size(); ++i) {
    assertThat(dexFiles).containsKey(expectedDexFileName(i));
  }
  for (int i = 1; i < dexFiles.keySet().size(); ++i) {
    Set<String> prev = dexFiles.get(expectedDexFileName(i - 1));
    if (i == 1) {
      prev = Sets.difference(prev, mainDexList);
    }
    Set<String> shard = dexFiles.get(expectedDexFileName(i));
    for (String c1 : prev) {
      for (String c2 : shard) {
        assertThat(ZipEntryComparator.compareClassNames(c2, c1))
            .named(c2 + " in shard " + i + " should compare as larger than " + c1
                + "; list of all shards for reference: " + dexFiles)
            .isGreaterThan(0);
      }
    }
  }
  return dexFiles;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:39,代码来源:DexFileMergerTest.java


示例15: loadClasses

import com.android.dex.ClassDef; //导入依赖的package包/类
public void loadClasses() {
	for (ClassDef cls : dexBuf.classDefs()) {
		ClassNode clsNode = new ClassNode(this, cls);
		classes.add(clsNode);
		clsMap.put(clsNode.getClassInfo(), clsNode);
	}
}
 
开发者ID:skylot,项目名称:jadx,代码行数:8,代码来源:DexNode.java



注:本文中的com.android.dex.ClassDef类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DetailEntryImpl类代码示例发布时间:2022-05-23
下一篇:
Java EnumTemperature类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap