@Override
 protected void migrate(
     org.lgna.project.ast.MethodInvocation methodInvocation,
     org.lgna.project.Project projectIfApplicable) {
   org.lgna.project.ast.AbstractMethod method = methodInvocation.method.getValue();
   if (method instanceof org.lgna.project.ast.JavaMethod) {
     org.lgna.project.ast.JavaMethod javaMethod = (org.lgna.project.ast.JavaMethod) method;
     if (javaMethod.getDeclaringType()
         == org.lgna.project.ast.JavaType.getInstance(org.lgna.story.SScene.class)) {
       String methodName = javaMethod.getName();
       if (methodName.equals("addMouseClickOnScreenListener")) {
         for (org.lgna.project.ast.AbstractArgument argument : methodInvocation.keyedArguments) {
           if (DEBUG_MODE) {
             edu.cmu.cs.dennisc.java.util.logging.Logger.errln(
                 "ALERT: migration removing", argument);
           }
         }
         methodInvocation.keyedArguments.clear();
         methodInvocation.method.setValue(
             org.lgna.story.ast.EventListenerMethodUtilities
                 .ADD_MOUSE_CLICK_ON_SCREEN_LISTENER_METHOD);
       } else if (methodName.equals("addMouseClickOnObjectListener")) {
         for (org.lgna.project.ast.AbstractArgument argument : methodInvocation.keyedArguments) {
           if (DEBUG_MODE) {
             edu.cmu.cs.dennisc.java.util.logging.Logger.errln(
                 "ALERT: migration removing", argument);
           }
         }
         methodInvocation.keyedArguments.clear();
         methodInvocation.method.setValue(
             org.lgna.story.ast.EventListenerMethodUtilities
                 .ADD_MOUSE_CLICK_ON_OBJECT_LISTENER_METHOD);
       }
     }
   }
 }
Ejemplo n.º 2
0
  public AbstractNode decode(
      org.w3c.dom.Element xmlElement, java.util.Map<Integer, AbstractDeclaration> map) {
    AbstractNode rv;
    if (xmlElement.hasAttribute(CodecConstants.TYPE_ATTRIBUTE)) {
      String clsName = getClassName(xmlElement);
      if (clsName.equals(JavaType.class.getName())) {
        rv = JavaType.getInstance(decodeType(xmlElement, "type"));
      } else if (clsName.equals(UserArrayType.class.getName())) {
        rv = decodeUserArrayType(xmlElement, map);
      } else if (clsName.equals(JavaConstructor.class.getName())) {
        rv = JavaConstructor.getInstance(decodeConstructor(xmlElement, "constructor"));
      } else if (clsName.equals(JavaMethod.class.getName())) {
        MethodReflectionProxy methodReflectionProxy = decodeMethod(xmlElement, "method");
        MethodReflectionProxy varArgsReplacement =
            MethodReflectionProxy.getReplacementIfNecessary(methodReflectionProxy);
        if (varArgsReplacement != null) {
          edu.cmu.cs.dennisc.java.util.logging.Logger.errln(
              "replacing", methodReflectionProxy, "with", varArgsReplacement);
          methodReflectionProxy = varArgsReplacement;
        }
        rv = JavaMethod.getInstance(methodReflectionProxy);
      } else if (clsName.equals(Getter.class.getName()) || clsName.equals(Setter.class.getName())) {

        org.w3c.dom.Node xmlFirstChild = xmlElement.getFirstChild();
        if (xmlFirstChild instanceof org.w3c.dom.Element) {
          org.w3c.dom.Element xmlFirstChildElement = (org.w3c.dom.Element) xmlFirstChild;
          if (xmlFirstChildElement.hasAttribute(CodecConstants.UNIQUE_KEY_ATTRIBUTE)) {
            int getterOrSetterUniqueKey = getUniqueKey(xmlElement);
            int fieldUniqueKey = getUniqueKey(xmlFirstChildElement);
            java.util.Map<Integer, Integer> mapToFieldKey;
            if (clsName.equals(Getter.class.getName())) {
              mapToFieldKey = EPIC_HACK_mapGetterKeyToFieldKey;
            } else {
              mapToFieldKey = EPIC_HACK_mapSetterKeyToFieldKey;
            }
            mapToFieldKey.put(getterOrSetterUniqueKey, fieldUniqueKey);
          }
        }

        org.w3c.dom.NodeList nodeList = xmlElement.getChildNodes();
        assert nodeList.getLength() == 1;
        org.w3c.dom.Element xmlField = (org.w3c.dom.Element) nodeList.item(0);
        UserField field = (UserField) decode(xmlField, map);
        if (clsName.equals(Getter.class.getName())) {
          rv = field.getGetter();
        } else {
          rv = field.getSetter();
        }
      } else if (clsName.equals(SetterParameter.class.getName())) {
        org.w3c.dom.NodeList nodeList = xmlElement.getChildNodes();
        assert nodeList.getLength() == 1;
        org.w3c.dom.Element xmlSetter = (org.w3c.dom.Element) nodeList.item(0);
        Setter setter = (Setter) decode(xmlSetter, map);
        rv = setter.getRequiredParameters().get(0);
      } else if (clsName.equals(JavaField.class.getName())) {
        rv = JavaField.getInstance(decodeField(xmlElement, "field"));
      } else if (clsName.equals(AnonymousUserConstructor.class.getName())) {
        rv = decodeAnonymousConstructor(xmlElement, map);
      } else if (clsName.equals(JavaConstructorParameter.class.getName())) {
        org.w3c.dom.NodeList nodeList = xmlElement.getChildNodes();
        assert nodeList.getLength() == 2;
        org.w3c.dom.Element xmlConstructor = (org.w3c.dom.Element) nodeList.item(0);
        JavaConstructor constructorDeclaredInJava =
            (JavaConstructor) decodeValue(xmlConstructor, map);
        org.w3c.dom.Element xmlIndex = (org.w3c.dom.Element) nodeList.item(1);
        int index = Integer.parseInt(xmlIndex.getTextContent());

        final int REQUIRED_N = constructorDeclaredInJava.getRequiredParameters().size();
        if (index < REQUIRED_N) {
          rv = constructorDeclaredInJava.getRequiredParameters().get(index);
        } else {
          if (index == REQUIRED_N) {
            rv = constructorDeclaredInJava.getVariableLengthParameter();
            if (rv != null) {
              // pass;
            } else {
              rv = constructorDeclaredInJava.getKeyedParameter();
            }
          } else {
            rv = null;
          }
        }
      } else if (clsName.equals(JavaMethodParameter.class.getName())) {
        org.w3c.dom.NodeList nodeList = xmlElement.getChildNodes();
        assert nodeList.getLength() == 2;
        org.w3c.dom.Element xmlMethod = (org.w3c.dom.Element) nodeList.item(0);
        JavaMethod methodDeclaredInJava = (JavaMethod) decodeValue(xmlMethod, map);
        org.w3c.dom.Element xmlIndex = (org.w3c.dom.Element) nodeList.item(1);
        int index = Integer.parseInt(xmlIndex.getTextContent());
        final int REQUIRED_N = methodDeclaredInJava.getRequiredParameters().size();
        if (index < REQUIRED_N) {
          rv = methodDeclaredInJava.getRequiredParameters().get(index);
        } else {
          if (index == REQUIRED_N) {
            rv = methodDeclaredInJava.getVariableLengthParameter();
            if (rv != null) {
              // pass;
            } else {
              rv = methodDeclaredInJava.getKeyedParameter();
            }
          } else {
            rv = null;
          }
        }
      } else {
        rv = (AbstractNode) newInstance(xmlElement);
        assert rv != null;
      }
      if (rv instanceof AbstractDeclaration) {
        map.put(getUniqueKey(xmlElement), (AbstractDeclaration) rv);
      }
      rv.decodeNode(this, xmlElement, map);
      if (xmlElement.hasAttribute(CodecConstants.ID_ATTRIBUTE)) {
        if (this.policy.isIdPreserved()) {
          rv.setId(java.util.UUID.fromString(xmlElement.getAttribute(CodecConstants.ID_ATTRIBUTE)));
        }
      }
    } else {
      int key = getUniqueKey(xmlElement);
      rv = map.get(key);
      if (rv != null) {
        // pass
      } else {
        if (EPIC_HACK_mapArrayTypeKeyToLeafTypeKey.containsKey(key)) {
          int leafTypeKey = EPIC_HACK_mapArrayTypeKeyToLeafTypeKey.get(key);
          AbstractDeclaration leafDeclaration = map.get(leafTypeKey);
          if (leafDeclaration instanceof UserType<?>) {
            UserType<?> leafType = (UserType<?>) leafDeclaration;
            edu.cmu.cs.dennisc.java.util.logging.Logger.outln(leafTypeKey, leafType);
            rv = leafType.getArrayType();
          } else {
            assert false : leafDeclaration;
          }
        } else if (EPIC_HACK_mapGetterKeyToFieldKey.containsKey(key)) {
          int fieldKey = EPIC_HACK_mapGetterKeyToFieldKey.get(key);
          AbstractDeclaration fieldDeclaration = map.get(fieldKey);
          if (fieldDeclaration instanceof UserField) {
            UserField userField = (UserField) fieldDeclaration;
            rv = userField.getGetter();
          }
        } else if (EPIC_HACK_mapSetterKeyToFieldKey.containsKey(key)) {
          int fieldKey = EPIC_HACK_mapSetterKeyToFieldKey.get(key);
          AbstractDeclaration fieldDeclaration = map.get(fieldKey);
          if (fieldDeclaration instanceof UserField) {
            UserField userField = (UserField) fieldDeclaration;
            rv = userField.getSetter();
          }
        } else {
          assert false : Integer.toHexString(key) + " " + map;
        }
      }
    }
    return rv;
  }