Java源码示例:org.benf.cfr.reader.util.getopt.OptionsImpl
示例1
public static void main(String[] args) {
GetOptParser getOptParser = new GetOptParser();
Options options = null;
List<String> files = null;
try {
Pair<List<String>, Options> processedArgs = getOptParser.parse(args, OptionsImpl.getFactory());
files = processedArgs.getFirst();
options = processedArgs.getSecond();
if (files.size() == 0) {
throw new IllegalArgumentException("Insufficient unqualified parameters - provide at least one filename.");
}
} catch (Exception e) {
getOptParser.showHelp(e);
System.exit(1);
}
if (options.optionIsSet(OptionsImpl.HELP) || files.isEmpty()) {
getOptParser.showOptionHelp(OptionsImpl.getFactory(), options, OptionsImpl.HELP);
return;
}
CfrDriver cfrDriver = new CfrDriver.Builder().withBuiltOptions(options).build();
cfrDriver.analyse(files);
}
示例2
public static ClassRenamer create(Options options) {
Set<String> invalidNames = OsInfo.OS().getIllegalNames();
// We still fetch the insensitivity flag from options, to allow it to be forced.
boolean renameCase = (options.getOption(OptionsImpl.CASE_INSENSITIVE_FS_RENAME));
List<ClassNameFunction> functions = ListFactory.newList();
if (!invalidNames.isEmpty()) {
functions.add(new ClassNameFunctionInvalid(renameCase, invalidNames));
}
if (renameCase) {
functions.add(new ClassNameFunctionCase());
}
if (functions.isEmpty()) {
return null;
}
return new ClassRenamer(functions);
}
示例3
public static void rewriteEnumClass(ClassFile classFile, DCCommonState state) {
Options options = state.getOptions();
ClassFileVersion classFileVersion = classFile.getClassFileVersion();
if (!options.getOption(OptionsImpl.ENUM_SUGAR, classFileVersion)) return;
JavaTypeInstance classType = classFile.getClassType();
if (!classFile.getBindingSupers().containsBase(TypeConstants.ENUM)) {
return;
}
EnumClassRewriter c = new EnumClassRewriter(classFile, classType, state);
if (!c.rewrite()) {
c.removeAllRemainingSupers();
}
}
示例4
public static List<Op03SimpleStatement> rewrite(Options options, Method method, List<Op03SimpleStatement> statementList) {
if (!method.getName().equals(MiscConstants.STATIC_INIT_METHOD)) return statementList;
if (!options.getOption(OptionsImpl.STATIC_INIT_RETURN)) return statementList;
/*
* if the final statement is a return, then replace all other returns with a jump to that.
*/
Op03SimpleStatement last = statementList.get(statementList.size()-1);
if (last.getStatement().getClass() != ReturnNothingStatement.class) return statementList;
for (int x =0, len=statementList.size()-1;x<len;++x) {
Op03SimpleStatement stm = statementList.get(x);
if (stm.getStatement().getClass() == ReturnNothingStatement.class) {
stm.replaceStatement(new GotoStatement());
stm.addTarget(last);
last.addSource(stm);
}
}
return statementList;
}
示例5
FileDumper(String dir, boolean clobber, JavaTypeInstance type, SummaryDumper summaryDumper, TypeUsageInformation typeUsageInformation, Options options, IllegalIdentifierDump illegalIdentifierDump) {
super(typeUsageInformation, options, illegalIdentifierDump, new MovableDumperContext());
this.type = type;
this.summaryDumper = summaryDumper;
Pair<String, String> names = ClassNameUtils.getPackageAndClassNames(type);
try {
String fileName = mkFilename(dir, names, summaryDumper);
File file = new File(fileName);
File parent = file.getParentFile();
if (!parent.exists() && !parent.mkdirs()) {
throw new IllegalStateException("Couldn't create dir: " + parent);
}
if (file.exists() && !clobber) {
throw new CannotCreate("File already exists, and option '" + OptionsImpl.CLOBBER_FILES.getName() + "' not set");
}
path = fileName;
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
} catch (FileNotFoundException e) {
throw new CannotCreate(e);
}
}
示例6
private void notifyAdditionalAtEnd() {
try {
List<DecompilerComment> comments = additionalComments != null ? additionalComments.getComments() : null;
if (comments != null && !comments.isEmpty()) {
writer.write("\n");
for (DecompilerComment comment : comments) {
writer.write(comment.toString() + "\n");
// It's also handy to see these on console.
if (!options.getOption(OptionsImpl.SILENT)) {
System.err.println(comment.toString());
}
}
}
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
示例7
@Override
public String decompileClassNode(FileContainer container, ClassNode cn) {
try {
byte[] bytes = JDA.getClassBytes(container, cn);
GetOptParser getOptParser = new GetOptParser();
Pair processedArgs = getOptParser.parse(generateMainMethod(), OptionsImpl.getFactory());
List files = (List)processedArgs.getFirst();
Options options = (Options)processedArgs.getSecond();
ClassFileSourceImpl classFileSource = new ClassFileSourceImpl(options);
DCCommonState dcCommonState = new DCCommonState(options, classFileSource);
return doClass(dcCommonState, bytes);
} catch (Exception e) {
return parseException(e);
}
}
示例8
public static ObfuscationMapping get(Options options, DCCommonState state) {
String path = options.getOption(OptionsImpl.OBFUSCATION_PATH);
if (path == null) {
return NullMapping.INSTANCE;
}
return new MappingFactory(options, state.getClassCache()).createFromPath(path);
}
示例9
private static DCCommonState initDCState(Map<String, String> optionsMap, ClassFileSource classFileSource) {
OptionsImpl options = new OptionsImpl(optionsMap);
ClassFileSource2 source = classFileSource == null ?
new ClassFileSourceImpl(options) :
new ClassFileSourceWrapper(classFileSource);
return new DCCommonState(options, source);
}
示例10
@Override
public void analyse(List<String> toAnalyse) {
/*
* There's an interesting question here - do we want to skip inner classes, if we've been given a wildcard?
* (or a wildcard expanded by the operating system).
*
* Assume yes.
*/
boolean skipInnerClass = toAnalyse.size() > 1 && options.getOption(OptionsImpl.SKIP_BATCH_INNER_CLASSES);
Collections.sort(toAnalyse);
for (String path : toAnalyse) {
// TODO : We shouldn't have to discard state here. But we do, because
// it causes test fails. (used class name table retains useful symbols).
classFileSource.informAnalysisRelativePathDetail(null, null);
// Note - both of these need to be reset, as they have caches.
DCCommonState dcCommonState = new DCCommonState(options, classFileSource);
DumperFactory dumperFactory = outputSinkFactory != null ?
new SinkDumperFactory(outputSinkFactory, options) :
new InternalDumperFactoryImpl(options);
AnalysisType type = options.getOption(OptionsImpl.ANALYSE_AS);
if (type == null || type == AnalysisType.DETECT) {
type = dcCommonState.detectClsJar(path);
}
if (type == AnalysisType.JAR || type == AnalysisType.WAR) {
Driver.doJar(dcCommonState, path, type, dumperFactory);
} else if (type == AnalysisType.CLASS) {
Driver.doClass(dcCommonState, path, skipInnerClass, dumperFactory);
}
}
}
示例11
public TypeUsageInformationImpl(Options options, JavaRefTypeInstance analysisType, Set<JavaRefTypeInstance> usedRefTypes, Set<DetectedStaticImport> staticImports) {
this.allowShorten = MiscUtils.mkRegexFilter(options.getOption(OptionsImpl.IMPORT_FILTER), true);
this.analysisType = analysisType;
this.iid = IllegalIdentifierDump.Factory.getOrNull(options);
this.staticImports = staticImports;
initialiseFrom(usedRefTypes);
}
示例12
private void analyseSyntheticTags(Method method, Options options) {
try {
Op04StructuredStatement code = method.getAnalysis();
if (code == null) return;
if (options.getOption(OptionsImpl.REWRITE_TRY_RESOURCES, getClassFileVersion())) {
boolean isResourceRelease = Op04StructuredStatement.isTryWithResourceSynthetic(method, code);
if (isResourceRelease) {
method.getAccessFlags().add(AccessFlagMethod.ACC_FAKE_END_RESOURCE);
}
}
} catch (Exception e) {
// ignore.
}
}
示例13
public AttributeInnerClasses(ByteData raw, ConstantPool cp) {
Boolean forbidMethodScopedClasses = cp.getDCCommonState().getOptions().getOption(OptionsImpl.FORBID_METHOD_SCOPED_CLASSES);
Boolean forbidAnonymousClasses = cp.getDCCommonState().getOptions().getOption(OptionsImpl.FORBID_ANONYMOUS_CLASSES);
this.length = raw.getS4At(OFFSET_OF_ATTRIBUTE_LENGTH);
int numberInnerClasses = raw.getU2At(OFFSET_OF_NUMBER_OF_CLASSES);
long offset = OFFSET_OF_CLASS_ARRAY;
for (int x = 0; x < numberInnerClasses; ++x) {
int innerClassInfoIdx = raw.getU2At(offset);
offset += 2;
int outerClassInfoIdx = raw.getU2At(offset);
offset += 2;
int innerNameIdx = raw.getU2At(offset);
offset += 2;
int innerAccessFlags = raw.getU2At(offset);
offset += 2;
Pair<JavaTypeInstance, JavaTypeInstance> innerOuter = getInnerOuter(innerClassInfoIdx, outerClassInfoIdx, cp);
JavaTypeInstance innerClassType = innerOuter.getFirst();
JavaTypeInstance outerClassType = innerOuter.getSecond();
// MarkAnonymous feels like a bit of a hack, but otherwise we need to propagate this information
// the whole way down the type creation path, and this is the only place we care about it.
// May add that in later.
if (outerClassType == null) {
// This option has to be set manually, because it affects state generated
// which is shared between fallback passes.
if (forbidMethodScopedClasses) {
outerClassType = innerClassType.getInnerClassHereInfo().getOuterClass();
} else {
boolean isAnonymous = !forbidAnonymousClasses && innerNameIdx == 0;
innerClassType.getInnerClassHereInfo().markMethodScoped(isAnonymous);
}
}
innerClassAttributeInfoList.add(new InnerClassAttributeInfo(
innerClassType,
outerClassType,
getOptName(innerNameIdx, cp),
AccessFlag.build(innerAccessFlags)
));
}
}
示例14
public static void wholeClassAnalysisPass3(ClassFile classFile, DCCommonState state, TypeUsageCollectingDumper typeUsage) {
Options options = state.getOptions();
if (options.getOption(OptionsImpl.REMOVE_BOILERPLATE)) {
removeRedundantSupers(classFile);
}
if (options.getOption(OptionsImpl.REMOVE_DEAD_METHODS)) {
removeDeadMethods(classFile);
}
rewriteUnreachableStatics(classFile, typeUsage);
detectFakeMethods(classFile, typeUsage);
}
示例15
@Override
public void rewrite(Op04StructuredStatement root) {
if (!(options.getOption(OptionsImpl.STRING_SWITCH, classFileVersion)
|| bytecodeMeta.has(BytecodeMeta.CodeInfoFlag.STRING_SWITCHES))
) return;
List<StructuredStatement> structuredStatements = MiscStatementTools.linearise(root);
if (structuredStatements == null) return;
rewriteComplex(structuredStatements);
rewriteEmpty(structuredStatements);
}
示例16
static void removeSynchronizedCatchBlocks(Options options, List<Op03SimpleStatement> in) {
if (!options.getOption(OptionsImpl.TIDY_MONITORS)) return;
// find all the block statements which are the first statement in a CATCHBLOCK.
List<Op03SimpleStatement> catchStarts = Functional.filter(in, new FindBlockStarts(BlockType.CATCHBLOCK));
if (catchStarts.isEmpty()) return;
boolean effect = false;
for (Op03SimpleStatement catchStart : catchStarts) {
effect = removeSynchronizedCatchBlock(catchStart, in) || effect;
}
if (effect) {
Op03Rewriters.removePointlessJumps(in);
}
}
示例17
static void collapseAssignmentsIntoConditionals(List<Op03SimpleStatement> statements, Options options, ClassFileVersion classFileVersion) {
// find all conditionals.
List<Op03SimpleStatement> ifStatements = Functional.filter(statements, new TypeFilter<IfStatement>(IfStatement.class));
if (ifStatements.isEmpty()) return;
boolean testEclipse = options.getOption(OptionsImpl.ECLIPSE);
boolean notBeforeInstanceOf = options.getOption(OptionsImpl.INSTANCEOF_PATTERN, classFileVersion);
ConditionalCondenser c = new ConditionalCondenser(testEclipse, notBeforeInstanceOf);
for (Op03SimpleStatement statement : ifStatements) {
c.collapseAssignmentsIntoConditional(statement);
}
}
示例18
static void rewriteWhilesAsFors(Options options, List<Op03SimpleStatement> statements) {
// Find all the while loops beginnings.
List<Op03SimpleStatement> whileStarts = Functional.filter(statements, new Predicate<Op03SimpleStatement>() {
@Override
public boolean test(Op03SimpleStatement in) {
return (in.getStatement() instanceof WhileStatement) && ((WhileStatement) in.getStatement()).getBlockIdentifier().getBlockType() == BlockType.WHILELOOP;
}
});
boolean aggcapture = options.getOption(OptionsImpl.FOR_LOOP_CAPTURE) == Troolean.TRUE;
for (Op03SimpleStatement whileStart : whileStarts) {
rewriteWhileAsFor(whileStart, aggcapture);
}
}
示例19
public InternalDumperFactoryImpl(Options options) {
this.checkDupes = OsInfo.OS().isCaseInsensitive() && !options.getOption(OptionsImpl.CASE_INSENSITIVE_FS_RENAME);
this.options = options;
if (!options.getOption(OptionsImpl.SILENT) && (options.optionIsSet(OptionsImpl.OUTPUT_DIR) || options.optionIsSet(OptionsImpl.OUTPUT_PATH))) {
progressDumper = new ProgressDumperStdErr();
} else {
progressDumper = ProgressDumperNop.INSTANCE;
}
this.prefix = "";
}
示例20
private Pair<String, Boolean> getPathAndClobber() {
Troolean clobber = options.getOption(OptionsImpl.CLOBBER_FILES);
if (options.optionIsSet(OptionsImpl.OUTPUT_DIR)) {
return Pair.make(options.getOption(OptionsImpl.OUTPUT_DIR), clobber.boolValue(true));
}
if (options.optionIsSet(OptionsImpl.OUTPUT_PATH)) {
return Pair.make(options.getOption(OptionsImpl.OUTPUT_PATH), clobber.boolValue(false));
}
return null;
}
示例21
StreamDumper(TypeUsageInformation typeUsageInformation, Options options, IllegalIdentifierDump illegalIdentifierDump, MovableDumperContext context) {
super(context);
this.typeUsageInformation = typeUsageInformation;
this.options = options;
this.illegalIdentifierDump = illegalIdentifierDump;
this.convertUTF = options.getOption(OptionsImpl.HIDE_UTF8);
this.emitted = SetFactory.newSet();
}
示例22
StreamDumper(TypeUsageInformation typeUsageInformation, Options options, IllegalIdentifierDump illegalIdentifierDump, MovableDumperContext context, Set<JavaTypeInstance> emitted) {
super(context);
this.typeUsageInformation = typeUsageInformation;
this.options = options;
this.illegalIdentifierDump = illegalIdentifierDump;
this.convertUTF = options.getOption(OptionsImpl.HIDE_UTF8);
this.emitted = emitted;
}
示例23
public static IllegalIdentifierDump get(Options options) {
if (options.getOption(OptionsImpl.RENAME_ILLEGAL_IDENTS)) {
return IllegalIdentifierReplacement.getInstance();
} else {
return Nop.getInstance();
}
}
示例24
public static IllegalIdentifierDump getOrNull(Options options) {
if (options.getOption(OptionsImpl.RENAME_ILLEGAL_IDENTS)) {
return IllegalIdentifierReplacement.getInstance();
} else {
return null;
}
}
示例25
public static String doClass(DCCommonState dcCommonState, byte[] content1) {
Options options = dcCommonState.getOptions();
IllegalIdentifierDump illegalIdentifierDump = IllegalIdentifierDump.Factory.get(options);
Dumper d = new ToStringDumper();
try {
StackTraceElement[] arr$;
int len$;
int i$;
StackTraceElement x;
try {
SummaryDumper summaryDumper = new NopSummaryDumper();
BaseByteData data = new BaseByteData(content1);
ClassFile c = new ClassFile(data, "", dcCommonState);
dcCommonState.configureWith(c);
try {
c = dcCommonState.getClassFile(c.getClassType());
} catch (CannotLoadClassException var20) {
}
if (options.getOption(OptionsImpl.DECOMPILE_INNER_CLASSES)) {
c.loadInnerClasses(dcCommonState);
}
if (options.getOption(OptionsImpl.RENAME_DUP_MEMBERS)) {
MemberNameResolver.resolveNames(dcCommonState, ListFactory.newList(dcCommonState.getClassCache().getLoadedTypes()));
}
c.analyseTop(dcCommonState);
TypeUsageCollector collectingDumper = new TypeUsageCollector(c);
c.collectTypeUsages(collectingDumper);
String methname = options.getOption(OptionsImpl.METHODNAME);
if (methname == null) {
c.dump(d);
} else {
try {
Iterator i$$ = c.getMethodByName(methname).iterator();
while(i$$.hasNext()) {
Method method = (Method)i$$.next();
method.dump(d, true);
}
} catch (NoSuchMethodException var21) {
throw new IllegalArgumentException("No such method '" + methname + "'.");
}
}
d.print("");
return d.toString();
} catch (ConfusedCFRException var22) {
System.err.println(var22.toString());
arr$ = var22.getStackTrace();
len$ = arr$.length;
for(i$ = 0; i$ < len$; ++i$) {
x = arr$[i$];
System.err.println(x);
}
} catch (CannotLoadClassException var23) {
System.out.println("Can't load the class specified:");
System.out.println(var23.toString());
} catch (RuntimeException var24) {
System.err.println(var24.toString());
arr$ = var24.getStackTrace();
len$ = arr$.length;
for(i$ = 0; i$ < len$; ++i$) {
x = arr$[i$];
System.err.println(x);
}
}
} finally {
if (d != null) {
d.close();
}
}
return "";
}
示例26
@Override
protected void registerSettings() {
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.SUGAR_STRINGBUFFER, true));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.SUGAR_STRINGBUILDER, true));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.ENUM_SWITCH, true));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.ENUM_SUGAR, true));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.STRING_SWITCH, true));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.ARRAY_ITERATOR, true));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.COLLECTION_ITERATOR, true));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.REWRITE_LAMBDAS, true));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.DECOMPILE_INNER_CLASSES));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.HIDE_UTF8));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.HIDE_LONGSTRINGS));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.REMOVE_BOILERPLATE));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.REMOVE_INNER_CLASS_SYNTHETICS));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.HIDE_BRIDGE_METHODS));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.LIFT_CONSTRUCTOR_INIT));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.REMOVE_DEAD_METHODS));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.REMOVE_BAD_GENERICS));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.SUGAR_ASSERTS));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.SUGAR_BOXING));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.SHOW_CFR_VERSION));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.DECODE_FINALLY));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.TIDY_MONITORS));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.COMMENT_MONITORS));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.LENIENT));
// registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.DUMP_CLASS_PATH));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.DECOMPILER_COMMENTS));
registerSetting(Troolean.class, new RawTrooleanSetting(OptionsImpl.FORCE_TOPSORT));
registerSetting(Troolean.class, new RawTrooleanSetting(OptionsImpl.FOR_LOOP_CAPTURE));
registerSetting(Troolean.class, new RawTrooleanSetting(OptionsImpl.FORCE_TOPSORT_EXTRA));
registerSetting(Troolean.class, new RawTrooleanSetting(OptionsImpl.FORCE_COND_PROPAGATE));
registerSetting(Troolean.class, new RawTrooleanSetting(OptionsImpl.FORCE_RETURNING_IFS));
registerSetting(Troolean.class, new RawTrooleanSetting(OptionsImpl.FORCE_PRUNE_EXCEPTIONS));
registerSetting(Troolean.class, new RawTrooleanSetting(OptionsImpl.FORCE_AGGRESSIVE_EXCEPTION_AGG));
registerSetting(Troolean.class, new RawTrooleanSetting(OptionsImpl.RECOVER_TYPECLASHES));
registerSetting(Troolean.class, new RawTrooleanSetting(OptionsImpl.USE_RECOVERED_ITERATOR_TYPE_HINTS));
// registerSetting(Troolean.class, new RawTrooleanSetting(OptionsImpl.OUTPUT_DIR));
// registerSetting(Troolean.class, new RawTrooleanSetting(OptionsImpl.OUTPUT_PATH));
// registerSetting(Troolean.class, new RawTrooleanSetting(OptionsImpl.CLOBBER_FILES));
registerSetting(Integer.class, new RawIntegerSetting(OptionsImpl.SHOWOPS, 0, Integer.MAX_VALUE, 1));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.SILENT));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.RECOVER));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.ECLIPSE));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.OVERRIDES, true));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.SHOW_INFERRABLE, true));
// registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.HELP));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.ALLOW_CORRECTING));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.LABELLED_BLOCKS));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.JAVA_4_CLASS_OBJECTS, true));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.HIDE_LANG_IMPORTS));
registerSetting(Integer.class, new RawIntegerSetting(OptionsImpl.FORCE_PASS, 0, Integer.MAX_VALUE, 1));
// registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.ANALYSE_AS));
// registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.JAR_FILTER));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.RENAME_MEMBERS));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.RENAME_DUP_MEMBERS));
registerSetting(Integer.class, new RawIntegerSetting(OptionsImpl.RENAME_SMALL_MEMBERS, 0, Integer.MAX_VALUE, 1));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.RENAME_ILLEGAL_IDENTS));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.RENAME_ENUM_MEMBERS));
registerSetting(Integer.class, new RawIntegerSetting(OptionsImpl.AGGRESSIVE_SIZE_REDUCTION_THRESHOLD, 0, Integer.MAX_VALUE, 1));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.STATIC_INIT_RETURN));
// registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.FILENAME));
// registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.METHODNAME));
// registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.EXTRA_CLASS_PATH));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.PULL_CODE_CASE));
registerSetting(Boolean.class, new RawBooleanSetting(OptionsImpl.ELIDE_SCALA));
}
示例27
public SummaryDumper getSummaryDumper() {
if (!options.optionIsSet(OptionsImpl.OUTPUT_DIR)) return new NopSummaryDumper();
return new FileSummaryDumper(options.getOption(OptionsImpl.OUTPUT_DIR), options, null);
}
示例28
/**
* @param options Map of options, as per {@link CfrDriver}'s builder.
* @return CFR's internal implementation of {@link ClassFileSource}
*/
static ClassFileSource createInternalClassFileSource(Map<String, String> options) {
Options parsedOptions = OptionsImpl.getFactory().create(options);
return new ClassFileSourceImpl(parsedOptions);
}
示例29
private Map<String, JarSourceEntry> getClassPathClasses() {
if (classToPathMap == null) {
boolean dump = options.getOption(OptionsImpl.DUMP_CLASS_PATH);
classToPathMap = MapFactory.newMap();
String classPath = System.getProperty("java.class.path");
String sunBootClassPath = System.getProperty("sun.boot.class.path");
if (sunBootClassPath != null) {
classPath += File.pathSeparatorChar + sunBootClassPath;
}
if (dump) {
System.out.println("/* ClassPath Diagnostic - searching :" + classPath);
}
String extraClassPath = options.getOption(OptionsImpl.EXTRA_CLASS_PATH);
if (null != extraClassPath) {
classPath = classPath + File.pathSeparatorChar + extraClassPath;
}
classRenamer = ClassRenamer.create(options);
String[] classPaths = classPath.split("" + File.pathSeparatorChar);
for (String path : classPaths) {
if (dump) {
System.out.println(" " + path);
}
File f = new File(path);
if (f.exists()) {
if (f.isDirectory()) {
if (dump) {
System.out.println(" (Directory)");
}
// Load all the jars in that directory.
File[] files = f.listFiles();
if (files != null) {
for (File file : files) {
processClassPathFile(file, file.getAbsolutePath(), classToPathMap, AnalysisType.JAR, dump);
}
}
} else {
processClassPathFile(f, path, classToPathMap, AnalysisType.JAR, dump);
}
} else {
if (dump) {
System.out.println(" (Can't access)");
}
}
}
if (dump) {
System.out.println(" */");
}
}
return classToPathMap;
}
示例30
public Method(ByteData raw, ClassFile classFile, final ConstantPool cp, final DCCommonState dcCommonState, final ClassFileVersion classFileVersion) {
Options options = dcCommonState.getOptions();
this.cp = cp;
this.classFile = classFile;
this.accessFlags = AccessFlagMethod.build(raw.getU2At(OFFSET_OF_ACCESS_FLAGS));
this.descriptorIndex = raw.getU2At(OFFSET_OF_DESCRIPTOR_INDEX);
this.hidden = Visibility.Visible;
int nameIndex = raw.getU2At(OFFSET_OF_NAME_INDEX);
String initialName = cp.getUTF8Entry(nameIndex).getValue();
int numAttributes = raw.getU2At(OFFSET_OF_ATTRIBUTES_COUNT);
ArrayList<Attribute> tmpAttributes = new ArrayList<Attribute>();
tmpAttributes.ensureCapacity(numAttributes);
long attributesLength = ContiguousEntityFactory.build(raw.getOffsetData(OFFSET_OF_ATTRIBUTES), numAttributes, tmpAttributes,
AttributeFactory.getBuilder(cp, classFileVersion));
this.attributes = new AttributeMap(tmpAttributes);
AccessFlagMethod.applyAttributes(attributes, accessFlags);
this.length = OFFSET_OF_ATTRIBUTES + attributesLength;
MethodConstructor methodConstructor = MethodConstructor.NOT;
if (initialName.equals(MiscConstants.INIT_METHOD)) {
boolean isEnum = classFile.getAccessFlags().contains(AccessFlag.ACC_ENUM);
methodConstructor = isEnum ? MethodConstructor.ENUM_CONSTRUCTOR : MethodConstructor.CONSTRUCTOR;
} else if (initialName.equals(MiscConstants.STATIC_INIT_METHOD)) {
methodConstructor = MethodConstructor.STATIC_CONSTRUCTOR;
// JVM Spec 2nd ed., chapter 4.6: All access flags except static for class initializers are ignored
// Pre java 7 class files even allow static initializers to be non-static
// See classFileParser.cpp#parse_method
accessFlags.clear();
accessFlags.add(AccessFlagMethod.ACC_STATIC);
}
this.isConstructor = methodConstructor;
if (methodConstructor.isConstructor() && accessFlags.contains(AccessFlagMethod.ACC_STRICT)) {
accessFlags.remove(AccessFlagMethod.ACC_STRICT);
classFile.getAccessFlags().add(AccessFlag.ACC_STRICT);
}
AttributeCode codeAttribute = attributes.getByName(AttributeCode.ATTRIBUTE_NAME);
if (codeAttribute == null) {
// Because we don't have a code attribute, we don't have a local variable table.
this.variableNamer = VariableNamerFactory.getNamer(null, cp);
this.codeAttribute = null;
} else {
this.codeAttribute = codeAttribute;
AttributeLocalVariableTable variableTable = options.getOption(OptionsImpl.USE_NAME_TABLE) ? this.codeAttribute.getLocalVariableTable() : null;
this.variableNamer = VariableNamerFactory.getNamer(variableTable, cp);
// This rigamarole is neccessary because we don't provide the factory for the code attribute enough information
// to get the Method (this).
this.codeAttribute.setMethod(this);
}
this.methodPrototype = generateMethodPrototype(options, initialName, methodConstructor);
if (accessFlags.contains(AccessFlagMethod.ACC_BRIDGE) &&
// javac only ever generates bridges into instances,
// however kotlin loses useful info if we hide them.
!accessFlags.contains(AccessFlagMethod.ACC_STATIC) &&
options.getOption(OptionsImpl.HIDE_BRIDGE_METHODS)) {
this.hidden = Visibility.HiddenBridge;
}
}