public ValueType getFieldType(FieldReference fieldReference) { ClassReader cls = classSource.get(fieldReference.getClassName()); FieldReader field = cls.getField(fieldReference.getFieldName()); return field.getType(); }
private String[] getExpectedExceptions(MethodHolder method) { AnnotationHolder annot = method.getAnnotations().get(JUNIT4_TEST); if (annot == null) { return new String[0]; } AnnotationValue expected = annot.getValue("expected"); if (expected == null) { return new String[0]; } ValueType result = expected.getJavaClass(); return new String[] { ((ValueType.Object) result).getClassName() }; }
private boolean clinitNeeded(String className) { ClassReader cls = unprocessedClassSource.get(className); if (cls == null) { return true; } return cls.getMethod(new MethodDescriptor("<clinit>", void.class)) != null; }
private void addFunctorField(ClassHolder cls, MethodReference method) { if (cls.getAnnotations().get(FunctorImpl.class.getName()) != null) { return; } FieldHolder field = new FieldHolder("$$jso_functor$$"); field.setLevel(AccessLevel.PUBLIC); field.setType(ValueType.parse(JSObject.class)); cls.addField(field); AnnotationHolder annot = new AnnotationHolder(FunctorImpl.class.getName()); annot.getValues().put("value", new AnnotationValue(method.getDescriptor().toString())); cls.getAnnotations().add(annot); }
private MethodReference getAsyncReference(MethodReference methodRef) { ValueType[] signature = new ValueType[methodRef.parameterCount() + 2]; for (int i = 0; i < methodRef.parameterCount(); ++i) { signature[i] = methodRef.getDescriptor().parameterType(i); } signature[methodRef.parameterCount()] = ValueType.parse(AsyncCallback.class); signature[methodRef.parameterCount() + 1] = ValueType.VOID; return new MethodReference(methodRef.getClassName(), methodRef.getName(), signature); }
private Variable introduce(Variable var) { if (!usedDefinitions[var.getIndex()]) { usedDefinitions[var.getIndex()] = true; } else { Variable old = var; var = program.createVariable(); var.setDebugName(old.getDebugName()); var.setLabel(old.getLabel()); } return var; }
private int indexOfMethod(ClassReader cls, MethodReader method) { int index = 0; for (MethodReader m : cls.getMethods()) { if (m.getDescriptor().equals(method.getDescriptor())) { return index; } ++index; } return -1; }
@Override public MethodReference getReference() { if (owner == null) { return null; } if (reference == null) { reference = new MethodReference(owner.getName(), descriptor); } return reference; }
public ValueType getMetaParameterType(int index) { if (!isStatic) { if (index == 0) { return ValueType.object(method.getClassName()); } else { --index; } } return method.parameterType(index); }
private void fillExceptionHandlers(Program program) { exceptionHandlers = new boolean[program.basicBlockCount()]; for (int i = 0; i < exceptionHandlers.length; ++i) { BasicBlock block = program.basicBlockAt(i); for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) { exceptionHandlers[tryCatch.getHandler().getIndex()] = true; } } }
private boolean matchSignature(ClassHierarchy hierarchy, MethodReader functionMethod, MethodReader candidateMethod) { if (functionMethod.parameterCount() > candidateMethod.parameterCount()) { return false; } for (int i = 0; i < functionMethod.parameterCount(); ++i) { if (!hierarchy.isSuperType(functionMethod.parameterType(i), candidateMethod.parameterType(i), false)) { return false; } } return true; }
private boolean isWrappedNativeCall(MethodReader method) { if (!method.hasModifier(ElementModifier.NATIVE)) { return false; } for (ValueType type : method.getParameterTypes()) { if (type.isObject(String.class)) { return true; } } return false; }
private static boolean sameParams(MethodDescriptor a, MethodDescriptor b) { if (a.parameterCount() != b.parameterCount()) { return false; } for (int i = 0; i < a.parameterCount(); ++i) { if (!a.parameterType(i).equals(b.parameterType(i))) { return false; } } return true; } }
protected final String extractClassName(ValueType itemType) { while (itemType instanceof ValueType.Array) { itemType = ((ValueType.Array) itemType).getItemType(); } return itemType instanceof ValueType.Object ? ((ValueType.Object) itemType).getClassName() : null; }
public void addLocationsOfProgram(ProgramReader program) { for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlockReader block = program.basicBlockAt(i); block.readAllInstructions(this); } }
@Override public void visit(InvokeDynamicInstruction insn) { if (insn.getReceiver() != null && !used[insn.getReceiver().getIndex()]) { insn.setReceiver(null); } }
private String[] getVariableNames(ProgramReader program, boolean debuggerFriendly) { String[] names = new String[program.variableCount()]; for (int i = 0; i < names.length; ++i) { names[i] = program.variableAt(i).getDebugName(); if (debuggerFriendly && names[i] == null) { names[i] = ""; } } return names; }
private ValueType[] parseSignature(String desc) { ValueType[] signature = MethodDescriptor.parseSignature(desc); for (int i = 0; i < signature.length; ++i) { signature[i] = referenceCache.getCached(signature[i]); } return signature; }
public void updateReference(ReferenceCache cache) { FieldReference reference = getReference(); if (reference != null) { this.reference = cache.getCached(reference); } } }
@Override public FieldReference getReference() { if (reference == null && owner != null) { reference = new FieldReference(getOwnerName(), getName()); } return reference; }