private Value setFieldValueWithConflict(ObjectReference obj, List<Field> fields, String name, String belongToClass, String value, Map<String, Object> options) throws ClassNotLoadedException, InvalidTypeException { Field field; // first try to resolve field by fully qualified name List<Field> narrowedFields = fields.stream().filter(TypeComponent::isStatic) .filter(t -> t.name().equals(name) && t.declaringType().name().equals(belongToClass)) .collect(Collectors.toList()); if (narrowedFields.isEmpty()) { // second try to resolve field by formatted name narrowedFields = fields.stream().filter(TypeComponent::isStatic) .filter(t -> t.name().equals(name) && context.getVariableFormatter().typeToString(t.declaringType(), options).equals(belongToClass)) .collect(Collectors.toList()); } if (narrowedFields.size() == 1) { field = narrowedFields.get(0); } else { throw new UnsupportedOperationException(String.format("SetVariableRequest: Name conflicted for %s.", name)); } return field.isStatic() ? setStaticFieldValue(field.declaringType(), field, name, value, options) : this.setObjectFieldValue(obj, field, name, value, options); }
@Override public boolean isSynthetic(TypeComponent typeComponent) { String name = typeComponent.name(); if (LambdaMethodFilter.isLambdaName(name)) { return false; } else { ReferenceType type = typeComponent.declaringType(); if (type.name().contains("$$Lambda$")) { return true; } } VirtualMachine machine = typeComponent.virtualMachine(); if (machine != null && machine.canGetSyntheticAttribute()) { return typeComponent.isSynthetic(); } else { return name.contains("$"); } }
/** * Get the static variable of an stack frame. * * @param stackFrame * the stack frame * @return the static variable of an stack frame. */ public static List<Variable> listStaticVariables(StackFrame stackFrame) { List<Variable> res = new ArrayList<>(); ReferenceType type = stackFrame.location().declaringType(); type.allFields().stream().filter(TypeComponent::isStatic).forEach(field -> { Variable staticVar = new Variable(field.name(), type.getValue(field)); staticVar.field = field; res.add(staticVar); }); return res; }
private static boolean hasBlueprintProtectionDomain(ObjectReference context) { return context .referenceType() .allFields() .stream() .map(TypeComponent::name) .anyMatch("bundleContext"::equals); }
private static boolean hasBundleProtectionDomain(ObjectReference context) { return context .referenceType() .allFields() .stream() .map(TypeComponent::name) .anyMatch("bundle"::equals); }
@Override public double getWeight(TypeComponent comp) { if (comp instanceof Method) return ProbabilityComputer.getMethodProbability((Method)comp, weights) * getMethodFudge(((Method)comp)); else if (comp instanceof Field) return ProbabilityComputer.getFieldProbability((Field)comp, weights); else throw new IllegalArgumentException(String.valueOf(comp)); }
@Override public double getWeight(TypeComponent comp) { double weight = super.getWeight(comp); IJavaType type = comp instanceof Field ? EclipseUtils.getTypeAndLoadIfNeeded(((Field)comp).typeName(), stack, target, typeCache) : getReturnType(receiver, (Method)comp, ((Method)comp).isConstructor()); try { weight *= getTypeFactor(type); } catch (DebugException e) { throw new RuntimeException(e); } return weight; }
public F3TypeComponent(F3VirtualMachine f3vm, TypeComponent underlying) { super(f3vm, underlying); }
@Override protected TypeComponent underlying() { return (TypeComponent) super.underlying(); }
/** * TODO: reduce the cyclomatic complexity. */ private Set<NodeModifier> createModifiers(final TypeComponent member) { final Set<NodeModifier> modifiers = new LinkedHashSet<NodeModifier>(); // final if (member.isFinal()) { modifiers.add(NM_FINAL); } // static if (member.isStatic()) { modifiers.add(NM_STATIC); } // transient if (member instanceof Field && ((Field) member).isTransient()) { modifiers.add(NM_TRANSIENT); } // volatile if (member instanceof Field && ((Field) member).isVolatile()) { modifiers.add(NM_VOLATILE); } // bridge method (for covariance in generic types) if (member instanceof Method && ((Method) member).isBridge()) { modifiers.add(NM_BRIDGE); } // constructor if (member instanceof Method && ((Method) member).isConstructor()) { modifiers.add(NM_CONSTRUCTOR); } // compiler generated method (e.g., bridges, constructors) if (member instanceof Method && ((Method) member).isSynthetic()) { modifiers.add(NM_SYNTHETIC); } return modifiers; }
private NodeVisibility createVisibility(final TypeComponent member) { return member.isPackagePrivate() ? NV_PACKAGE : member.isPrivate() ? NV_PRIVATE : member .isProtected() ? NV_PROTECTED : NV_PUBLIC; }
boolean isSynthetic(TypeComponent typeComponent);