Exemplo n.º 1
0
 public Object decodeValue(
     org.w3c.dom.Element xmlValue, java.util.Map<Integer, AbstractDeclaration> map) {
   Object rv;
   if (xmlValue.hasAttribute("isNull")) {
     rv = null;
   } else {
     String tagName = xmlValue.getTagName();
     if (tagName.equals("node")) {
       try {
         rv = decode(xmlValue, map);
       } catch (RuntimeException re) {
         re.printStackTrace();
         // rv = new NullLiteral();
         rv = null;
       }
     } else if (tagName.equals("collection")) {
       java.util.Collection collection = (java.util.Collection) newInstance(xmlValue);
       org.w3c.dom.NodeList nodeList = xmlValue.getChildNodes();
       for (int i = 0; i < nodeList.getLength(); i++) {
         org.w3c.dom.Element xmlItem = (org.w3c.dom.Element) nodeList.item(i);
         collection.add(decodeValue(xmlItem, map));
       }
       rv = collection;
       //			} else if( tagName.equals( "resource" ) ) {
       //				String uuidText = xmlValue.getAttribute( CodecConstants.UUID_ATTRIBUTE );
       //				edu.cmu.cs.dennisc.print.PrintUtilities.println( "uuidText", uuidText );
       //				java.util.UUID uuid = java.util.UUID.fromString( uuidText );
       //				edu.cmu.cs.dennisc.print.PrintUtilities.println( "uuid", uuid );
       //				rv = org.alice.virtualmachine.Resource.get( uuid );
     } else if (tagName.equals("value")) {
       Class<?> cls = getCls(xmlValue);
       String textContent = xmlValue.getTextContent();
       if (cls.equals(String.class)) {
         rv = textContent;
       } else {
         try {
           rv = edu.cmu.cs.dennisc.java.lang.reflect.ReflectionUtilities.valueOf(cls, textContent);
         } catch (RuntimeException re) {
           if ("DIVIDE".equals(textContent)) {
             rv =
                 edu.cmu.cs.dennisc.java.lang.reflect.ReflectionUtilities.valueOf(
                     cls, "REAL_DIVIDE");
           } else if ("REMAINDER".equals(textContent)) {
             rv =
                 edu.cmu.cs.dennisc.java.lang.reflect.ReflectionUtilities.valueOf(
                     cls, "REAL_REMAINDER");
           } else {
             throw re;
           }
         }
       }
     } else {
       throw new RuntimeException();
     }
   }
   return rv;
 }
Exemplo n.º 2
0
  private static org.lgna.project.ast.NamedUserType getNamedUserTypeFor(
      org.lgna.project.ast.AbstractType<?, ?, ?> ancestorType,
      org.lgna.project.ast.AbstractType<?, ?, ?>[] argumentTypes,
      int i,
      org.lgna.project.ast.AbstractField argumentField) {
    org.lgna.project.ast.AbstractType<?, ?, ?> superType;
    final int LAST_INDEX = argumentTypes.length - 1;
    if (i < LAST_INDEX) {
      superType = getNamedUserTypeFor(ancestorType, argumentTypes, i + 1, null);
    } else {
      superType = ancestorType;
    }
    edu.cmu.cs.dennisc.pattern.Criterion<org.lgna.project.ast.NamedUserType> criterion;
    if (argumentField != null) {
      criterion = new ExtendsTypeWithSuperArgumentFieldCriterion(superType, argumentField);
    } else {
      criterion = new ExtendsTypeWithConstructorParameterTypeCriterion(superType, argumentTypes[i]);
    }

    //		org.alice.ide.IDE ide = org.alice.ide.IDE.getActiveInstance();
    //		if( ide != null ) {
    //			org.alice.ide.ProjectDocument projectDocument = ide.getDocument();
    //			if( projectDocument != null ) {
    //				org.alice.ide.type.TypeCache typeCache = projectDocument.getTypeCache();
    //				typeCache.getNamedUserTypeFor( ancestorType, argumentTypes, i, argumentField );
    //			}
    //		}

    org.lgna.project.Project project = org.alice.ide.ProjectStack.peekProject();
    if (project != null) {
      java.util.Set<org.lgna.project.ast.NamedUserType> existingTypes = project.getNamedUserTypes();
      for (org.lgna.project.ast.NamedUserType existingType : existingTypes) {
        if (criterion.accept(existingType)) {
          return existingType;
        }
      }
    }
    org.lgna.project.ast.Expression[] expressions;
    if (argumentField != null) {
      expressions =
          new org.lgna.project.ast.Expression[] {
            new org.lgna.project.ast.FieldAccess(
                new org.lgna.project.ast.TypeExpression(argumentField.getDeclaringType()),
                argumentField)
          };
    } else {
      expressions = USE_PARAMETER_ACCESSES_AS_ARGUMENTS_TO_SUPER;
    }
    String name = createClassNameFromResourceType(argumentTypes[i]);

    org.lgna.project.ast.NamedUserType rv =
        createTypeFor(
            superType,
            name,
            new org.lgna.project.ast.AbstractType[] {argumentTypes[i]},
            expressions);
    if (argumentTypes[i] instanceof org.lgna.project.ast.JavaType) {
      org.lgna.project.ast.JavaType javaArgumentTypeI =
          (org.lgna.project.ast.JavaType) argumentTypes[i];
      Class<?> cls = javaArgumentTypeI.getClassReflectionProxy().getReification();
      if (edu.cmu.cs.dennisc.java.lang.reflect.ReflectionUtilities.isFinal(cls)) {
        boolean isSetResourceMethodDesired;
        if (cls.isEnum()) {
          isSetResourceMethodDesired = cls.getEnumConstants().length > 1;
        } else {
          isSetResourceMethodDesired = true;
        }
        if (isSetResourceMethodDesired) {
          String simpleClsName = cls.getSimpleName();
          org.lgna.project.ast.UserMethod setResourceMethod = new org.lgna.project.ast.UserMethod();
          setResourceMethod.managementLevel.setValue(
              org.lgna.project.ast.ManagementLevel.GENERATED);
          setResourceMethod.name.setValue("set" + simpleClsName);
          setResourceMethod.returnType.setValue(org.lgna.project.ast.JavaType.VOID_TYPE);
          org.lgna.project.ast.BlockStatement body = new org.lgna.project.ast.BlockStatement();
          setResourceMethod.body.setValue(body);

          StringBuilder parameterNameSB = new StringBuilder();
          parameterNameSB.append(Character.toLowerCase(simpleClsName.charAt(0)));
          parameterNameSB.append(simpleClsName.substring(1));
          org.lgna.project.ast.UserParameter parameter = new org.lgna.project.ast.UserParameter();
          parameter.name.setValue(parameterNameSB.toString());
          parameter.valueType.setValue(javaArgumentTypeI);

          setResourceMethod.requiredParameters.add(parameter);

          body.statements.add(
              org.lgna.project.ast.AstUtilities.createMethodInvocationStatement(
                  new org.lgna.project.ast.ThisExpression(),
                  SET_JOINTED_MODEL_RESOURCE_METHOD,
                  new org.lgna.project.ast.ParameterAccess(parameter)));

          setResourceMethod.isSignatureLocked.setValue(true);
          rv.methods.add(setResourceMethod);
        }
      }
    }
    return rv;
  }
Exemplo n.º 3
0
 // todo: investigate
 private Object newInstance(org.w3c.dom.Element xmlElement) {
   return edu.cmu.cs.dennisc.java.lang.reflect.ReflectionUtilities.newInstance(
       getClassName(xmlElement));
 }
Exemplo n.º 4
0
 // todo: investigate
 private Class<?> getCls(org.w3c.dom.Element xmlElement) {
   return edu.cmu.cs.dennisc.java.lang.reflect.ReflectionUtilities.getClassForName(
       getClassName(xmlElement));
 }