/** * Get the name. * @return the name */ public String getName() { return (String)name.getValue(); } }
/** * Get the name. * @return the name */ public String getName() { return (String)name.getValue(); } }
private static boolean isTypeConstant(InstanceKey instance) { if (instance instanceof ConstantKey) { ConstantKey c = (ConstantKey) instance; if (c.getValue() instanceof IClass) { return true; } } return false; }
/** * If <tt>instance</tt> is a {@link ConstantKey} and its value is an instance of {@link IClass}, * return that value. Otherwise, return <tt>null</tt>. */ private static IClass getTypeConstant(InstanceKey instance) { if (instance instanceof ConstantKey) { ConstantKey c = (ConstantKey) instance; if (c.getValue() instanceof IClass) { return (IClass) c.getValue(); } } return null; }
private static boolean isTypeConstant(InstanceKey instance) { if (instance instanceof ConstantKey) { ConstantKey c = (ConstantKey) instance; if (c.getValue() instanceof IClass) { return true; } } return false; }
/** * If <tt>instance</tt> is a {@link ConstantKey} and its value is an instance of {@link IClass}, * return that value. Otherwise, return <tt>null</tt>. */ private static IClass getTypeConstant(InstanceKey instance) { if (instance instanceof ConstantKey) { ConstantKey c = (ConstantKey) instance; if (c.getValue() instanceof IClass) { return (IClass) c.getValue(); } } return null; }
private static boolean isNonNullConstant(final InstanceKey ik) { if (ik instanceof ConstantKey<?>) { final ConstantKey<?> ck = (ConstantKey<?>) ik; return ! "null".equals(ck.getValue().toString()); } return false; }
private void handleString(final InstanceKey ik, final OrdinalSetMapping<InstanceKey> mapping, final Map<InstanceKeySite, Set<InstanceKey>> unresolvedDependencies) { if (isOfType(ik, "Ljava/lang/String")) { if (ik instanceof ConstantKey) { final String value = (String) ((ConstantKey<?>) ik).getValue(); final InstanceKeySite node = new ConstantString(mapping.getMappedIndex(ik), value); addNode(node); nodeMap.put(ik, node); } else if (ik instanceof NormalAllocationInNode) { final NormalAllocationInNode nain = (NormalAllocationInNode) ik; handleStringBuilderToString(nain, mapping, unresolvedDependencies); } } }
public Intent setAction(final InstanceKey key, final InstanceKey actionKey, boolean isExplicit) { if (actionKey == null) { return find(key); } final String action; { if (actionKey instanceof ConstantKey) { final Object actionO = ((ConstantKey<?>) actionKey).getValue(); if (actionO instanceof String) { action = StringStuff.deployment2CanonicalTypeString((String) actionO); } else if (actionO instanceof IClass) { action = ((IClass) actionO).getName().toString(); } else { throw new IllegalArgumentException("Wrong action type: " + actionO.getClass()); } } else { unbind(key); return null; } } return setAction(key, action, isExplicit); } }
public Intent setAction(final InstanceKey key, final InstanceKey actionKey, boolean isExplicit) { if (actionKey == null) { return find(key); } final String action; { if (actionKey instanceof ConstantKey) { final Object actionO = ((ConstantKey<?>) actionKey).getValue(); if (actionO instanceof String) { action = StringStuff.deployment2CanonicalTypeString((String) actionO); } else if (actionO instanceof IClass) { action = ((IClass) actionO).getName().toString(); } else { throw new IllegalArgumentException("Wrong action type: " + actionO.getClass()); } } else { unbind(key); return null; } } return setAction(key, action, isExplicit); } }
/** * if F is a supported constant representing a field, return the corresponding {@link InstanceFieldKey} for I. Otherwise, return {@code null}. */ protected PointerKey getInstanceFieldPointerKeyForConstant(InstanceKey I, ConstantKey<?> F) { Object v = F.getValue(); // FIXME: current only constant string are handled if (I.getConcreteType().getClassLoader().getLanguage().modelConstant(v)) { IField f = I.getConcreteType().getField(Atom.findOrCreateUnicodeAtom(String.valueOf(v))); return getPointerKeyForInstanceField(I, f); } return null; }
/** * if F is a supported constant representing a field, return the corresponding {@link InstanceFieldKey} for I. Otherwise, return {@code null}. */ protected PointerKey getInstanceFieldPointerKeyForConstant(InstanceKey I, ConstantKey<?> F) { Object v = F.getValue(); // FIXME: current only constant string are handled if (I.getConcreteType().getClassLoader().getLanguage().modelConstant(v)) { IField f = I.getConcreteType().getField(Atom.findOrCreateUnicodeAtom(String.valueOf(v))); return getPointerKeyForInstanceField(I, f); } return null; }
@Override protected PointerKey getInstanceFieldPointerKeyForConstant(InstanceKey I, ConstantKey<?> F) { Object v = F.getValue(); String strVal = JSCallGraphUtil.simulateToStringForPropertyNames(v); // if we know the string representation of the constant, use it... if (strVal != null) { IField f = I.getConcreteType().getField(Atom.findOrCreateUnicodeAtom(strVal)); return getPointerKeyForInstanceField(I, f); // ...otherwise it is some unknown string } else { return ReflectedFieldPointerKey.mapped(new ConcreteTypeKey(getFieldNameType(F)), I); } }
@Override protected PointerKey getInstanceFieldPointerKeyForConstant(InstanceKey I, ConstantKey<?> F) { Object v = F.getValue(); String strVal = JSCallGraphUtil.simulateToStringForPropertyNames(v); // if we know the string representation of the constant, use it... if (strVal != null) { IField f = I.getConcreteType().getField(Atom.findOrCreateUnicodeAtom(strVal)); return getPointerKeyForInstanceField(I, f); // ...otherwise it is some unknown string } else { return ReflectedFieldPointerKey.mapped(new ConcreteTypeKey(getFieldNameType(F)), I); } }
/** * If receiver is a {@link ConstantKey} whose value is an {@link IClass}, return a {@link JavaTypeContext} * representing the type of the IClass. (This corresponds to the case where we know the exact type that will be * allocated by the {@code Class.newInstance()} call.) Otherwise, return {@code null}. */ @Override public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] receiver) { if (callee.getReference().equals(ClassNewInstanceContextInterpreter.CLASS_NEW_INSTANCE_REF) && isTypeConstant(receiver[0])) { IClass c = (IClass) ((ConstantKey) receiver[0]).getValue(); if (!c.isAbstract() && !c.isInterface()) { return new JavaTypeContext(new PointType(c)); } } return null; }
/** * If receiver is a {@link ConstantKey} whose value is an {@link IClass}, return a {@link JavaTypeContext} * representing the type of the IClass. (This corresponds to the case where we know the exact type that will be * allocated by the {@code Class.newInstance()} call.) Otherwise, return {@code null}. */ @Override public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] receiver) { if (callee.getReference().equals(ClassNewInstanceContextInterpreter.CLASS_NEW_INSTANCE_REF) && isTypeConstant(receiver[0])) { IClass c = (IClass) ((ConstantKey) receiver[0]).getValue(); if (!c.isAbstract() && !c.isInterface()) { return new JavaTypeContext(new PointType(c)); } } return null; }
@Override public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] actualParameters) { Context baseContext = base.getCalleeTarget(caller, site, callee, actualParameters); if ((isInvoke(callee) || isType(callee)) && callee.getReference().getDeclaringClass().getName().equals(TypeReference.JavaLangInvokeMethodHandle.getName())) { if (actualParameters != null && actualParameters.length > 0) { InstanceKey selfKey = actualParameters[0]; if (selfKey instanceof ConstantKey && ((ConstantKey)selfKey).getConcreteType().getReference().equals(TypeReference.JavaLangInvokeMethodHandle)) { MethodReference ref = ((IMethod) ((ConstantKey)selfKey).getValue()).getReference(); return new MethodContext(baseContext, ref); } } } if (isFindStatic(callee) && callee.getDeclaringClass().getReference().equals(TypeReference.JavaLangInvokeMethodHandlesLookup)) { if (actualParameters != null && actualParameters.length > 2) { InstanceKey classKey = actualParameters[1]; InstanceKey nameKey = actualParameters[2]; if (classKey instanceof ConstantKey && ((ConstantKey)classKey).getConcreteType().getReference().equals(TypeReference.JavaLangClass) && nameKey instanceof ConstantKey && ((ConstantKey)nameKey).getConcreteType().getReference().equals(TypeReference.JavaLangString)) { return new FindContext(baseContext, ((IClass)((ConstantKey)classKey).getValue()).getReference(), (String)((ConstantKey)nameKey).getValue()); } } } return baseContext; }
@Override public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] actualParameters) { Context baseContext = base.getCalleeTarget(caller, site, callee, actualParameters); if ((isInvoke(callee) || isType(callee)) && callee.getReference().getDeclaringClass().getName().equals(TypeReference.JavaLangInvokeMethodHandle.getName())) { if (actualParameters != null && actualParameters.length > 0) { InstanceKey selfKey = actualParameters[0]; if (selfKey instanceof ConstantKey && ((ConstantKey)selfKey).getConcreteType().getReference().equals(TypeReference.JavaLangInvokeMethodHandle)) { MethodReference ref = ((IMethod) ((ConstantKey)selfKey).getValue()).getReference(); return new MethodContext(baseContext, ref); } } } if (isFindStatic(callee) && callee.getDeclaringClass().getReference().equals(TypeReference.JavaLangInvokeMethodHandlesLookup)) { if (actualParameters != null && actualParameters.length > 2) { InstanceKey classKey = actualParameters[1]; InstanceKey nameKey = actualParameters[2]; if (classKey instanceof ConstantKey && ((ConstantKey)classKey).getConcreteType().getReference().equals(TypeReference.JavaLangClass) && nameKey instanceof ConstantKey && ((ConstantKey)nameKey).getConcreteType().getReference().equals(TypeReference.JavaLangString)) { return new FindContext(baseContext, ((IClass)((ConstantKey)classKey).getValue()).getReference(), (String)((ConstantKey)nameKey).getValue()); } } } return baseContext; }