public boolean isRoot(INode node) { if (node.parent() instanceof AApplyExpCG) { AApplyExpCG par = (AApplyExpCG) node.parent(); if (par.getRoot() == node) { return true; } } return false; }
private AMethodDeclCG consQuoteCtor(String name) { AExternalTypeCG fieldType = new AExternalTypeCG(); fieldType.setName(IJavaConstants.INT); AIdentifierVarExpCG hashcodeVar = transAssistant.getInfo().getExpAssistant().consIdVar(HASHCODE_FIELD, fieldType); AEqualsBinaryExpCG hashcodeCompare = new AEqualsBinaryExpCG(); hashcodeCompare.setType(new ABoolBasicTypeCG()); hashcodeCompare.setLeft(hashcodeVar); hashcodeCompare.setRight(consZero()); AIdentifierVarExpCG hashCodeId = transAssistant.getInfo().getExpAssistant().consIdVar(HASHCODE_FIELD, consFieldType()); AMethodTypeCG hashCodeMethodType = new AMethodTypeCG(); hashCodeMethodType.setResult(consFieldType()); ASuperVarExpCG superVar = new ASuperVarExpCG(); superVar.setName(HASH_CODE_METHOD); superVar.setType(hashCodeMethodType); superVar.setIsLambda(false); superVar.setIsLocal(false); AApplyExpCG superCall = new AApplyExpCG(); superCall.setType(consFieldType()); superCall.setRoot(superVar); AAssignToExpStmCG assignHashcode = new AAssignToExpStmCG(); assignHashcode.setTarget(hashCodeId); assignHashcode.setExp(superCall); AIfStmCG hashcodeCheck = new AIfStmCG(); hashcodeCheck.setIfExp(hashcodeCompare); hashcodeCheck.setThenStm(assignHashcode); ABlockStmCG body = new ABlockStmCG(); body.getStatements().add(hashcodeCheck); AClassTypeCG quoteClassType = new AClassTypeCG(); quoteClassType.setName(name); AMethodTypeCG constructorType = new AMethodTypeCG(); constructorType.setResult(quoteClassType); AMethodDeclCG ctor = consDefaultCtorSignature(name); ctor.setMethodType(constructorType); ctor.setBody(body); return ctor; }