use of com.datatorrent.stram.webapp.asm.CompactMethodNode in project apex-core by apache.
the class TypeGraph method getPublicSetterGetterAndPorts.
private void getPublicSetterGetterAndPorts(TypeGraphVertex tgv, List<CompactMethodNode> setters, List<CompactMethodNode> getters, Map<Type, Type> typeReplacement, List<CompactFieldNode> ports) {
CompactClassNode exClass = null;
// check if the class needs to be excluded
for (String e : EXCLUDE_CLASSES) {
if (e.equals(tgv.getOrLoadClassNode().getName())) {
exClass = tgv.getOrLoadClassNode();
break;
}
}
if (exClass != null) {
// So the setter/getter methods in Operater, Object, Class won't be counted
for (CompactMethodNode compactMethodNode : exClass.getGetterMethods()) {
for (Iterator<CompactMethodNode> iterator = getters.iterator(); iterator.hasNext(); ) {
CompactMethodNode cmn = iterator.next();
if (cmn.getName().equals(compactMethodNode.getName())) {
iterator.remove();
}
}
}
for (CompactMethodNode compactMethodNode : exClass.getSetterMethods()) {
for (Iterator<CompactMethodNode> iterator = setters.iterator(); iterator.hasNext(); ) {
CompactMethodNode cmn = iterator.next();
if (cmn.getName().equals(compactMethodNode.getName())) {
iterator.remove();
}
}
}
} else {
if (tgv.getOrLoadClassNode().getSetterMethods() != null) {
setters.addAll(tgv.getOrLoadClassNode().getSetterMethods());
}
if (tgv.getOrLoadClassNode().getGetterMethods() != null) {
getters.addAll(tgv.getOrLoadClassNode().getGetterMethods());
}
}
TypeGraphVertex portVertex = typeGraph.get(Operator.Port.class.getName());
List<CompactFieldNode> fields = tgv.getOrLoadClassNode().getPorts();
if (fields != null) {
for (CompactFieldNode field : fields) {
TypeGraphVertex fieldVertex = typeGraph.get(field.getDescription());
if (isAncestor(portVertex, fieldVertex) && !isNodeInList(ports, field)) {
ports.add(field);
}
}
}
ClassSignatureVisitor csv = tgv.getOrLoadClassNode().getCsv();
Type superC = csv.getSuperClass();
addReplacement(superC, typeReplacement);
if (csv.getInterfaces() != null) {
for (Type it : csv.getInterfaces()) {
addReplacement(it, typeReplacement);
}
}
for (TypeGraphVertex ancestor : tgv.ancestors) {
getPublicSetterGetterAndPorts(ancestor, setters, getters, typeReplacement, ports);
}
}
use of com.datatorrent.stram.webapp.asm.CompactMethodNode in project apex-core by apache.
the class TypeGraph method addClassPropertiesAndPorts.
private void addClassPropertiesAndPorts(String clazzName, JSONObject desc) throws JSONException {
TypeGraphVertex tgv = typeGraph.get(clazzName);
if (tgv == null) {
return;
}
Map<String, JSONObject> results = new TreeMap<>();
List<CompactMethodNode> getters = new LinkedList<>();
List<CompactMethodNode> setters = new LinkedList<>();
Map<Type, Type> typeReplacement = new HashMap<>();
List<CompactFieldNode> ports = new LinkedList<>();
getPublicSetterGetterAndPorts(tgv, setters, getters, typeReplacement, ports);
desc.put("portTypeInfo", getPortTypeInfo(clazzName, typeReplacement, ports));
for (CompactMethodNode setter : setters) {
String prop = WordUtils.uncapitalize(setter.getName().substring(3));
JSONObject propJ = results.get(prop);
if (propJ == null) {
propJ = new JSONObject();
propJ.put("name", prop);
results.put(prop, propJ);
}
propJ.put("canSet", true);
propJ.put("canGet", false);
MethodSignatureVisitor msv = null;
msv = setter.getMethodSignatureNode();
if (msv == null) {
continue;
}
List<Type> param = msv.getParameters();
if (CollectionUtils.isEmpty(param)) {
propJ.put("type", "UNKNOWN");
} else {
// only one param in setter method
setTypes(propJ, param.get(0), typeReplacement);
// propJ.put("type", param.getTypeObj().getClassName());
}
// propJ.put("type", typeString);
}
for (CompactMethodNode getter : getters) {
int si = getter.getName().startsWith("is") ? 2 : 3;
String prop = WordUtils.uncapitalize(getter.getName().substring(si));
JSONObject propJ = results.get(prop);
if (propJ == null) {
propJ = new JSONObject();
propJ.put("name", prop);
results.put(prop, propJ);
propJ.put("canSet", false);
// propJ.put("type", Type.getReturnType(getter.desc).getClassName());
MethodSignatureVisitor msv = null;
msv = getter.getMethodSignatureNode();
if (msv == null) {
continue;
}
Type rt = msv.getReturnType();
if (rt == null) {
propJ.put("type", "UNKNOWN");
} else {
setTypes(propJ, rt, typeReplacement);
// propJ.put("type", param.getTypeObj().getClassName());
}
}
propJ.put("canGet", true);
}
desc.put("properties", results.values());
}
Aggregations