Access static fields directly via the classes that declare them
Previously some of these were accessing such fields through a subclass of the declaring class. That creates an unnecessary extra inter-class dependency lower in the type hierarchy than necessary. Also, suppress this warning in an automated test input where the indirect static accesses are explicitly intentional.
This commit is contained in:
parent
38c11f0fa6
commit
8cc4daf6a0
|
@ -51,6 +51,7 @@ public class MethodMadness {
|
|||
public static void staticTest() {
|
||||
System.out.println("staticTest");
|
||||
}
|
||||
@SuppressWarnings("static-access")
|
||||
protected int protectedInteger() {
|
||||
this.s = 5;
|
||||
new MethodMadness("thrownaway").staticTest(); // MethodMadness object evaluated but thrown away
|
||||
|
|
|
@ -24,8 +24,8 @@ import org.json.JSONObject;
|
|||
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
|
||||
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
|
||||
import com.ibm.wala.cast.js.ssa.JavaScriptInvoke;
|
||||
import com.ibm.wala.cast.js.types.JavaScriptMethods;
|
||||
import com.ibm.wala.cast.js.types.JavaScriptTypes;
|
||||
import com.ibm.wala.cast.types.AstMethodReference;
|
||||
import com.ibm.wala.classLoader.CallSiteReference;
|
||||
import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.classLoader.IMethod;
|
||||
|
@ -118,7 +118,7 @@ public class NodejsRequireTargetSelector implements MethodTargetSelector {
|
|||
|
||||
System.err.println(builder.getClassHierarchy());
|
||||
|
||||
IMethod method = script.getMethod(JavaScriptMethods.fnSelector);
|
||||
IMethod method = script.getMethod(AstMethodReference.fnSelector);
|
||||
previouslyRequired.put(sourceModule.getClassName(), method);
|
||||
|
||||
return method;
|
||||
|
|
|
@ -12,7 +12,6 @@ import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
|
|||
import com.ibm.wala.cast.js.ipa.callgraph.JavaScriptConstructTargetSelector;
|
||||
import com.ibm.wala.cast.js.ipa.callgraph.JavaScriptEntryPoints;
|
||||
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
|
||||
import com.ibm.wala.cast.js.test.JSCallGraphBuilderUtil;
|
||||
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
|
||||
import com.ibm.wala.classLoader.IMethod;
|
||||
import com.ibm.wala.classLoader.Language;
|
||||
|
@ -57,7 +56,7 @@ public class Driver {
|
|||
|
||||
scope.addToScope(
|
||||
scope.getJavaScriptLoader(),
|
||||
JSCallGraphBuilderUtil.getPrologueFile("prologue.js"));
|
||||
JSCallGraphUtil.getPrologueFile("prologue.js"));
|
||||
for(int i = 1; i < args.length; i++) {
|
||||
URL script = Driver.class.getClassLoader().getResource(args[i]);
|
||||
scope.addToScope(
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.ibm.wala.cast.js.html.WebPageLoaderFactory;
|
|||
import com.ibm.wala.cast.js.html.WebUtil;
|
||||
import com.ibm.wala.cast.js.html.jericho.JerichoHtmlParser;
|
||||
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
|
||||
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
|
||||
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
|
||||
import com.ibm.wala.cast.js.test.JSCallGraphBuilderUtil;
|
||||
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
|
||||
|
@ -49,7 +50,7 @@ public class JsViewerDriver extends JSCallGraphBuilderUtil {
|
|||
URL url = new URL(args[0]);
|
||||
|
||||
// computing CG + PA
|
||||
JSCallGraphBuilderUtil.setTranslatorFactory(new CAstRhinoTranslatorFactory());
|
||||
JSCallGraphUtil.setTranslatorFactory(new CAstRhinoTranslatorFactory());
|
||||
JavaScriptLoader.addBootstrapFile(WebUtil.preamble);
|
||||
|
||||
SourceModule[] sources = getSources(domless, url);
|
||||
|
|
|
@ -78,7 +78,7 @@ public class FieldBasedCGUtil {
|
|||
JavaScriptLoaderFactory loaders = new JavaScriptLoaderFactory(translatorFactory);
|
||||
Module[] scripts = new Module[]{
|
||||
new SourceURLModule(url),
|
||||
JSCallGraphBuilderUtil.getPrologueFile("prologue.js")
|
||||
JSCallGraphUtil.getPrologueFile("prologue.js")
|
||||
};
|
||||
return buildCG(loaders, scripts, builderType, monitor, supportFullPointerAnalysis);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ package com.ibm.wala.cast.js.ipa.callgraph;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil;
|
||||
import com.ibm.wala.cast.js.ipa.summaries.JavaScriptSummarizedFunction;
|
||||
import com.ibm.wala.cast.js.ipa.summaries.JavaScriptSummary;
|
||||
import com.ibm.wala.cast.js.loader.JSCallSiteReference;
|
||||
|
@ -183,7 +184,7 @@ public class JavaScriptFunctionDotCallTargetSelector implements MethodTargetSele
|
|||
|
||||
private static String getKey(int nargs, CGNode caller, CallSiteReference site) {
|
||||
if (SEPARATE_SYNTHETIC_METHOD_PER_SITE) {
|
||||
return JSCallGraphUtil.getShortName(caller) + "_" + caller.getGraphNodeId() + "_" + site.getProgramCounter();
|
||||
return CAstCallGraphUtil.getShortName(caller) + "_" + caller.getGraphNodeId() + "_" + site.getProgramCounter();
|
||||
} else {
|
||||
return ""+nargs;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
|
||||
import com.ibm.wala.cast.js.types.JavaScriptMethods;
|
||||
import com.ibm.wala.cast.js.types.JavaScriptTypes;
|
||||
import com.ibm.wala.cast.types.AstMethodReference;
|
||||
import com.ibm.wala.classLoader.CallSiteReference;
|
||||
|
@ -79,7 +78,7 @@ public class LoadFileTargetSelector implements MethodTargetSelector {
|
|||
JSCallGraphUtil.loadAdditionalFile(builder.getClassHierarchy() , cl, url);
|
||||
loadedFiles.add(url);
|
||||
IClass script = builder.getClassHierarchy().lookupClass(TypeReference.findOrCreate(cl.getReference(), "L" + url.getFile()));
|
||||
return script.getMethod(JavaScriptMethods.fnSelector);
|
||||
return script.getMethod(AstMethodReference.fnSelector);
|
||||
}
|
||||
} catch (MalformedURLException e1) {
|
||||
// do nothing, fall through and return 'target'
|
||||
|
|
|
@ -189,7 +189,7 @@ public class CAstPrinter {
|
|||
}
|
||||
|
||||
public static void xmlTo(CAstNode top, CAstSourcePositionMap pos, Writer w) {
|
||||
instance.doXmlTo(top, pos, w);
|
||||
doXmlTo(top, pos, w);
|
||||
}
|
||||
|
||||
private static void doXmlTo(CAstNode top, CAstSourcePositionMap pos, Writer w) {
|
||||
|
|
|
@ -127,7 +127,7 @@ public final /* singleton */ class AndroidModelClass extends SyntheticClass {
|
|||
clinit.setStatic(true);
|
||||
final TypeSafeInstructionFactory instructionFactory = new TypeSafeInstructionFactory(cha);
|
||||
|
||||
final Set<TypeReference> components = AndroidEntryPointManager.MANAGER.getComponents();
|
||||
final Set<TypeReference> components = AndroidEntryPointManager.getComponents();
|
||||
int ssaNo = 1;
|
||||
|
||||
if (AndroidEntryPointManager.MANAGER.doFlatComponents()) {
|
||||
|
|
|
@ -161,7 +161,7 @@ public class FlatInstantiator implements IInstantiator {
|
|||
{ // Special type?
|
||||
final SpecializedInstantiator sInst = new SpecializedInstantiator(body, instructionFactory, pm,
|
||||
cha, scope, analysisScope, this);
|
||||
if (sInst.understands(T)) {
|
||||
if (SpecializedInstantiator.understands(T)) {
|
||||
return sInst.createInstance(T, asManaged, key, seen, currentDepth);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ public class SpecializedInstantiator extends FlatInstantiator {
|
|||
appComponents.add(instance);
|
||||
}
|
||||
} else {
|
||||
for (TypeReference component : AndroidEntryPointManager.MANAGER.getComponents()) {
|
||||
for (TypeReference component : AndroidEntryPointManager.getComponents()) {
|
||||
final VariableKey iKey = new SSAValue.TypeKey(component.getName());
|
||||
|
||||
if (this.pm.isSeen(iKey)) {
|
||||
|
|
|
@ -204,7 +204,7 @@ public class Overrides {
|
|||
|
||||
{ // Make Mini-Models to override to
|
||||
for (final AndroidComponent target: AndroidComponent.values()) {
|
||||
if (AndroidEntryPointManager.MANAGER.EPContainAny(target)) {
|
||||
if (AndroidEntryPointManager.EPContainAny(target)) {
|
||||
final AndroidModel targetModel = new UnknownTargetModel(this.cha, this.options, this.cache, target);
|
||||
callTo.put(target, targetModel);
|
||||
} else {
|
||||
|
|
|
@ -32,7 +32,7 @@ import com.ibm.wala.shrikeBT.analysis.Verifier;
|
|||
import com.ibm.wala.shrikeBT.shrikeCT.CTDecoder;
|
||||
import com.ibm.wala.shrikeBT.shrikeCT.ClassInstrumenter;
|
||||
import com.ibm.wala.shrikeBT.shrikeCT.OfflineInstrumenter;
|
||||
import com.ibm.wala.shrikeCT.ClassReader;
|
||||
import com.ibm.wala.shrikeCT.ClassConstants;
|
||||
import com.ibm.wala.shrikeCT.ClassWriter;
|
||||
|
||||
/**
|
||||
|
@ -190,7 +190,7 @@ public class Bench {
|
|||
|
||||
if (ci.isChanged()) {
|
||||
ClassWriter cw = ci.emitClass();
|
||||
cw.addField(ClassReader.ACC_PUBLIC | ClassReader.ACC_STATIC, fieldName, Constants.TYPE_boolean, new ClassWriter.Element[0]);
|
||||
cw.addField(ClassConstants.ACC_PUBLIC | ClassConstants.ACC_STATIC, fieldName, Constants.TYPE_boolean, new ClassWriter.Element[0]);
|
||||
instrumenter.outputModifiedClass(ci, cw);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.ibm.wala.shrikeBT.shrikeCT.CTCompiler;
|
|||
import com.ibm.wala.shrikeBT.shrikeCT.CTDecoder;
|
||||
import com.ibm.wala.shrikeBT.shrikeCT.ClassInstrumenter;
|
||||
import com.ibm.wala.shrikeBT.shrikeCT.OfflineInstrumenter;
|
||||
import com.ibm.wala.shrikeCT.ClassConstants;
|
||||
import com.ibm.wala.shrikeCT.ClassReader;
|
||||
import com.ibm.wala.shrikeCT.ClassReader.AttrIterator;
|
||||
import com.ibm.wala.shrikeCT.ClassWriter;
|
||||
|
@ -239,27 +240,27 @@ public class CopyWriter {
|
|||
private static int copyEntry(ConstantPoolParser cp, ClassWriter w, int i) throws InvalidClassFileException {
|
||||
byte t = cp.getItemType(i);
|
||||
switch (t) {
|
||||
case ClassReader.CONSTANT_String:
|
||||
case ClassConstants.CONSTANT_String:
|
||||
return w.addCPString(cp.getCPString(i));
|
||||
case ClassReader.CONSTANT_Class:
|
||||
case ClassConstants.CONSTANT_Class:
|
||||
return w.addCPClass(cp.getCPClass(i));
|
||||
case ClassReader.CONSTANT_FieldRef:
|
||||
case ClassConstants.CONSTANT_FieldRef:
|
||||
return w.addCPFieldRef(cp.getCPRefClass(i), cp.getCPRefName(i), cp.getCPRefType(i));
|
||||
case ClassReader.CONSTANT_InterfaceMethodRef:
|
||||
case ClassConstants.CONSTANT_InterfaceMethodRef:
|
||||
return w.addCPInterfaceMethodRef(cp.getCPRefClass(i), cp.getCPRefName(i), cp.getCPRefType(i));
|
||||
case ClassReader.CONSTANT_MethodRef:
|
||||
case ClassConstants.CONSTANT_MethodRef:
|
||||
return w.addCPMethodRef(cp.getCPRefClass(i), cp.getCPRefName(i), cp.getCPRefType(i));
|
||||
case ClassReader.CONSTANT_NameAndType:
|
||||
case ClassConstants.CONSTANT_NameAndType:
|
||||
return w.addCPNAT(cp.getCPNATName(i), cp.getCPNATType(i));
|
||||
case ClassReader.CONSTANT_Integer:
|
||||
case ClassConstants.CONSTANT_Integer:
|
||||
return w.addCPInt(cp.getCPInt(i));
|
||||
case ClassReader.CONSTANT_Float:
|
||||
case ClassConstants.CONSTANT_Float:
|
||||
return w.addCPFloat(cp.getCPFloat(i));
|
||||
case ClassReader.CONSTANT_Long:
|
||||
case ClassConstants.CONSTANT_Long:
|
||||
return w.addCPLong(cp.getCPLong(i));
|
||||
case ClassReader.CONSTANT_Double:
|
||||
case ClassConstants.CONSTANT_Double:
|
||||
return w.addCPDouble(cp.getCPDouble(i));
|
||||
case ClassReader.CONSTANT_Utf8:
|
||||
case ClassConstants.CONSTANT_Utf8:
|
||||
return w.addCPUtf8(cp.getCPUtf8(i));
|
||||
}
|
||||
return -1;
|
||||
|
@ -292,8 +293,8 @@ public class CopyWriter {
|
|||
|
||||
if (1 < CPCount) {
|
||||
switch (cp.getItemType(1)) {
|
||||
case ClassReader.CONSTANT_Long:
|
||||
case ClassReader.CONSTANT_Double:
|
||||
case ClassConstants.CONSTANT_Long:
|
||||
case ClassConstants.CONSTANT_Double:
|
||||
// item 1 is a double-word item, so the next real item is at 3
|
||||
// to make sure item 3 is allocated at index 3, we'll need to
|
||||
// insert a dummy entry at index 2
|
||||
|
|
|
@ -59,7 +59,7 @@ final public class ArrayStoreInstruction extends Instruction implements IArraySt
|
|||
|
||||
@Override
|
||||
public String getType() {
|
||||
return Decoder.indexedTypes[opcode - OP_iastore];
|
||||
return Constants.indexedTypes[opcode - OP_iastore];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.Arrays;
|
|||
import java.util.Comparator;
|
||||
|
||||
import com.ibm.wala.shrikeBT.Util;
|
||||
import com.ibm.wala.shrikeCT.ClassConstants;
|
||||
import com.ibm.wala.shrikeCT.ClassReader;
|
||||
import com.ibm.wala.shrikeCT.ClassWriter;
|
||||
import com.ibm.wala.shrikeCT.ConstantValueWriter;
|
||||
|
@ -52,7 +53,7 @@ public class AddSerialVersion {
|
|||
}
|
||||
|
||||
long UID = computeSerialVersionUID(r);
|
||||
w.addField(ClassReader.ACC_PUBLIC | ClassReader.ACC_STATIC | ClassReader.ACC_FINAL, "serialVersionUID", "J",
|
||||
w.addField(ClassConstants.ACC_PUBLIC | ClassConstants.ACC_STATIC | ClassConstants.ACC_FINAL, "serialVersionUID", "J",
|
||||
new ClassWriter.Element[] { new ConstantValueWriter(w, UID) });
|
||||
}
|
||||
|
||||
|
@ -112,7 +113,7 @@ public class AddSerialVersion {
|
|||
int fieldCount = 0;
|
||||
for (int f = 0; f < fields.length; f++) {
|
||||
int flags = r.getFieldAccessFlags(f);
|
||||
if ((flags & ClassReader.ACC_PRIVATE) == 0 || (flags & (ClassReader.ACC_STATIC | ClassReader.ACC_TRANSIENT)) == 0) {
|
||||
if ((flags & ClassConstants.ACC_PRIVATE) == 0 || (flags & (ClassConstants.ACC_STATIC | ClassConstants.ACC_TRANSIENT)) == 0) {
|
||||
fields[fieldCount] = new Integer(f);
|
||||
fieldNames[f] = r.getFieldName(f);
|
||||
fieldCount++;
|
||||
|
@ -141,7 +142,7 @@ public class AddSerialVersion {
|
|||
for (int m = 0; m < methodSigs.length; m++) {
|
||||
String name = r.getMethodName(m);
|
||||
int flags = r.getMethodAccessFlags(m);
|
||||
if (name.equals("<clinit>") || (flags & ClassReader.ACC_PRIVATE) == 0) {
|
||||
if (name.equals("<clinit>") || (flags & ClassConstants.ACC_PRIVATE) == 0) {
|
||||
methods[methodCount] = new Integer(m);
|
||||
methodSigs[m] = name + r.getMethodType(m);
|
||||
if (name.equals("<clinit>")) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.io.Writer;
|
|||
|
||||
import com.ibm.wala.shrikeBT.shrikeCT.ClassInstrumenter;
|
||||
import com.ibm.wala.shrikeBT.shrikeCT.OfflineInstrumenter;
|
||||
import com.ibm.wala.shrikeCT.ClassConstants;
|
||||
import com.ibm.wala.shrikeCT.ClassReader;
|
||||
import com.ibm.wala.shrikeCT.ConstantPoolParser;
|
||||
|
||||
|
@ -60,7 +61,7 @@ public class ClassSearcher {
|
|||
ClassReader r = ci.getReader();
|
||||
ConstantPoolParser cp = r.getCP();
|
||||
for (int i = 1; i < cp.getItemCount(); i++) {
|
||||
if (cp.getItemType(i) == ConstantPoolParser.CONSTANT_Class && (cp.getCPClass(i).equals(cl1) || cp.getCPClass(i).equals(cl2))) {
|
||||
if (cp.getItemType(i) == ClassConstants.CONSTANT_Class && (cp.getCPClass(i).equals(cl1) || cp.getCPClass(i).equals(cl2))) {
|
||||
w.write(cp.getCPClass(i) + " " + resource + " " + r.getName() + "\n");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue