Ejemplo n.º 1
0
  private void _classListLocate(Class<?> clazz, List<? extends Annotation> expectedAnnotations) {

    List<Annotation> actualAnnotations = AnnotationLocator.locate(clazz);

    Assert.assertEquals(clazz.getName(), expectedAnnotations.size(), actualAnnotations.size());

    for (int i = 0; i < expectedAnnotations.size(); i++) {
      Annotation expectedAnnotation = expectedAnnotations.get(i);
      Annotation actualAnnotation = actualAnnotations.get(i);

      Assert.assertEquals(
          clazz.getName(), expectedAnnotation.annotationType(), actualAnnotation.annotationType());

      if (expectedAnnotation.annotationType() == Mix.class) {
        Mix expectedMix = (Mix) expectedAnnotation;
        Mix actualMix = (Mix) actualAnnotation;

        Assert.assertEquals("@Mix : " + clazz.getName(), expectedMix.value(), actualMix.value());
      } else {
        Type expectedType = (Type) expectedAnnotation;
        Type actualType = (Type) actualAnnotation;

        Assert.assertEquals("@Type : ", expectedType.value(), actualType.value());
      }
    }
  }
Ejemplo n.º 2
0
  @Override
  /**
   * ******************************************************************* Method that gets mixed
   * message and the file to unmix the message
   *
   * @param filename file that contains the undo commands to revert message to original
   * @param userMessage mixed message that is returned from the mix program
   * @return unmix original message before mixing it up
   *     ******************************************************************
   */
  public String UnMixUsingFile(String filename, String userMessage) {
    if (userMessage.trim().equals("")) {
      throw new IllegalArgumentException();
    }

    String str;
    String unmix = userMessage;
    Mix mix = new Mix();

    // calls the mix command and then sets the unmix message
    // provided as the usermessage on mix class -> pretty much did
    // the same thing so I guessed I could use this for easier process.
    mix.setInitialMessage(userMessage);

    // sets the filename output extension if it was not provided
    if (!filename.contains(".txt")) {
      filename = filename + ".txt";
    }

    try {
      // open the data file
      Scanner fileReader = new Scanner(new File(filename));
      LinkList<String> commands = new LinkList<String>();

      // goes through the file and adds it to the linked if it hasNextLine()
      while (fileReader.hasNextLine()) {
        str = fileReader.nextLine();
        commands.addfirst(str);
      }

      // goes through the linked list and process each
      // command to unmix the commands
      for (int i = 0; i < commands.count(); i++) {
        String s = commands.readList(i).getData();
        unmix = mix.processCommand(s);
      }

      return unmix;
    }
    // could not find file
    catch (FileNotFoundException error) {
      throw new IllegalArgumentException();
    }

    // problem reading the file
    catch (Exception error) {
      throw error;
    }
  }
Ejemplo n.º 3
0
  private void _classSingleLocate(Class<?> clazz, int expectedMixValue, int expectedTypeValue) {

    Mix actualMix = AnnotationLocator.locate(clazz, Mix.class);

    if (expectedMixValue == -1) {
      Assert.assertNull("@Mix : " + clazz.getName(), actualMix);
    } else {
      Assert.assertEquals("@Mix : " + clazz.getName(), expectedMixValue, actualMix.value());
    }

    Type actualType = AnnotationLocator.locate(clazz, Type.class);

    if (expectedTypeValue == -1) {
      Assert.assertNull("@Type : " + clazz.getName(), actualType);
    } else {
      Assert.assertEquals("@Type : " + clazz.getName(), expectedTypeValue, actualType.value());
    }
  }
Ejemplo n.º 4
0
  private void _methodSingleLocate(
      Class<?> clazz,
      int[] expectedMethodValues,
      int[] expectedMixValues,
      int[] expectedTypeValues) {

    for (int i = 0; i < 6; i++) {
      java.lang.reflect.Method method = _interfaceMethods[i];
      int expectedMethodValue = expectedMethodValues[i];

      Method methodAnnotation = AnnotationLocator.locate(method, clazz, Method.class);

      if (methodAnnotation == null) {
        Assert.assertEquals("@Method : " + clazz.getName(), -1, expectedMethodValue);

        continue;
      }

      Assert.assertEquals(
          "@Method : " + method.getName() + "()@" + clazz.getName(),
          expectedMethodValue,
          methodAnnotation.value());

      try {
        method = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());

        methodAnnotation = AnnotationLocator.locate(method, null, Method.class);

        Assert.assertEquals(
            method.getName() + "()@" + clazz.getName(),
            expectedMethodValue,
            methodAnnotation.value());
      } catch (Exception e) {
      }
    }

    for (int i = 0; i < 6; i++) {
      java.lang.reflect.Method method = _interfaceMethods[i];
      int expectedMixValue = expectedMixValues[i];

      Mix mixAnnotation = AnnotationLocator.locate(method, clazz, Mix.class);

      if (mixAnnotation == null) {
        Assert.assertEquals("@Mix : " + clazz.getName(), -1, expectedMixValue);

        continue;
      }

      Assert.assertEquals(
          "@Mix : " + method.getName() + "()@" + clazz.getName(),
          expectedMixValue,
          mixAnnotation.value());

      try {
        method = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());

        mixAnnotation = AnnotationLocator.locate(method, null, Mix.class);

        Assert.assertEquals(
            method.getName() + "()@" + clazz.getName(), expectedMixValue, mixAnnotation.value());
      } catch (Exception e) {
      }
    }

    for (int i = 0; i < 6; i++) {
      java.lang.reflect.Method method = _interfaceMethods[i];
      int expectedTypeValue = expectedTypeValues[i];

      Type typeAnnotation = AnnotationLocator.locate(method, clazz, Type.class);

      if (typeAnnotation == null) {
        Assert.assertEquals("@Type : " + clazz.getName(), -1, expectedTypeValue);

        continue;
      }

      Assert.assertEquals(
          "@Type : " + method.getName() + "()@" + clazz.getName(),
          expectedTypeValue,
          typeAnnotation.value());

      try {
        method = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());

        typeAnnotation = AnnotationLocator.locate(method, null, Type.class);

        Assert.assertEquals(
            method.getName() + "()@" + clazz.getName(), expectedTypeValue, typeAnnotation.value());
      } catch (Exception e) {
      }
    }
  }
Ejemplo n.º 5
0
  private void _methodListLocate(Class<?> clazz, List<Annotation[]> expectedAnnotationsList) {

    for (int i = 0; i < _interfaceMethods.length; i++) {
      Annotation[] expectedAnnotations = expectedAnnotationsList.get(i);

      java.lang.reflect.Method method = _interfaceMethods[i];
      List<Annotation> actualAnnotations = AnnotationLocator.locate(method, clazz);

      Assert.assertEquals(
          method.getName() + "()@" + clazz.getName(),
          expectedAnnotations.length,
          actualAnnotations.size());

      for (int j = 0; j < expectedAnnotations.length; j++) {
        Annotation expectedAnnotation = expectedAnnotations[j];
        Annotation actualAnnotation = actualAnnotations.get(j);

        Assert.assertEquals(
            method.getName() + "()@" + clazz.getName(),
            expectedAnnotation.annotationType(),
            actualAnnotation.annotationType());

        if (expectedAnnotation.annotationType() == Mix.class) {
          Mix expectedMix = (Mix) expectedAnnotation;
          Mix actualMix = (Mix) actualAnnotation;

          Assert.assertEquals(
              "@Mix : " + method.getName() + "()@" + clazz.getName(),
              expectedMix.value(),
              actualMix.value());
        } else if (expectedAnnotation.annotationType() == Method.class) {
          Method expectedType = (Method) expectedAnnotation;
          Method actualMethod = (Method) actualAnnotation;

          Assert.assertEquals(
              "@Method : " + method.getName() + "()@" + clazz.getName(),
              expectedType.value(),
              actualMethod.value());
        } else {
          Type expectedType = (Type) expectedAnnotation;
          Type actualType = (Type) actualAnnotation;

          Assert.assertEquals(
              "@Type : " + method.getName() + "()@" + clazz.getName(),
              expectedType.value(),
              actualType.value());
        }
      }

      try {
        method = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());

        actualAnnotations = AnnotationLocator.locate(method, null);

        Assert.assertEquals(
            method.getName() + "()@" + clazz.getName(),
            expectedAnnotations.length,
            actualAnnotations.size());

        for (int j = 0; j < expectedAnnotations.length; j++) {
          Annotation expectedAnnotation = expectedAnnotations[j];
          Annotation actualAnnotation = actualAnnotations.get(j);

          Assert.assertEquals(
              method.getName() + "()@" + clazz.getName(),
              expectedAnnotation.annotationType(),
              actualAnnotation.annotationType());

          if (expectedAnnotation.annotationType() == Mix.class) {
            Mix expectedMix = (Mix) expectedAnnotation;
            Mix actualMix = (Mix) actualAnnotation;

            Assert.assertEquals(
                "@Mix : " + method.getName() + "()@" + clazz.getName(),
                expectedMix.value(),
                actualMix.value());
          } else if (expectedAnnotation.annotationType() == Method.class) {

            Method expectedType = (Method) expectedAnnotation;
            Method actualMethod = (Method) actualAnnotation;

            Assert.assertEquals(
                "@Method : " + method.getName() + "()@" + clazz.getName(),
                expectedType.value(),
                actualMethod.value());
          } else {
            Type expectedType = (Type) expectedAnnotation;
            Type actualType = (Type) actualAnnotation;

            Assert.assertEquals(
                "@Type : " + method.getName() + "()@" + clazz.getName(),
                expectedType.value(),
                actualType.value());
          }
        }
      } catch (Exception e) {
      }
    }
  }
  public void startElement(String uri, String localName, String name, Attributes attributes)
      throws SAXException {
    if (collectText) {
      if (collectHTML) {
        text.append("<").append(localName);
        int nAttributes = attributes.getLength();
        for (int i = 0; i < nAttributes; i++) {
          String qname = attributes.getQName(i);
          String value = attributes.getValue(i);
          text.append(" ").append(qname).append("=\"").append(value).append("\"");
        }
      }
      pendingEndElement = true;
    } else {
      Integer stateObj = null;
      pushState();
      if (NAMESPACE_API.equals(uri)) {
        stateObj = (Integer) states.get(localName);
        if (stateObj != null) {
          int state = stateObj.intValue();
          switch (state) {
            case STATE_ABOUTME:
              {
                startCollectingText(localName, attributes);
                break;
              }

            case STATE_ALIAS:
              {
                Alias alias = new Alias();
                this.currentObject = alias;
                addCollectionElement(TAG_ALIAS, alias);
                alias.name = attributes.getValue(ATTRIBUTE_ALAIS_NAME);
                alias.datatype = attributes.getValue(ATTRIBUTE_ALAIS_TYPE);

                break;
              }

            case STATE_ANCESTOR:
              {
                Ancestor ancestor = new Ancestor();
                this.currentObject = ancestor;
                addCollectionElement(TAG_ANCESTOR, ancestor);
                ancestor.dataType = attributes.getValue(ATTRIBUTE_ANCESTOR_DATATYPE);

                break;
              }

            case STATE_API:
              {
                this.apis.libraryVersion = attributes.getValue(ATTRIBUTE_API_VERSION);
                this.apis.language = attributes.getValue(ATTRIBUTE_API_LANGUAGE);
                this.apis.getterPattern = attributes.getValue(ATTRIBUTE_API_GETTERPATTERN);
                this.apis.setterPattern = attributes.getValue(ATTRIBUTE_API_SETTERPATTERN);
                this.apis.setterPattern = attributes.getValue(ATTRIBUTE_API_SETTERPATTERN);
                this.apis.spec = attributes.getValue(ATTRIBUTE_API_SPEC);
                this.collections = new HashMap();
                break;
              }

            case STATE_AUTHOR:
              {
                Author author = new Author();
                this.currentObject = author;

                author.email = attributes.getValue(ATTRIBUTE_AUTHOR_EMAIL);
                author.location = attributes.getValue(ATTRIBUTE_AUTHOR_LOCATION);
                author.name = attributes.getValue(ATTRIBUTE_AUTHOR_NAME);
                author.organization = attributes.getValue(ATTRIBUTE_AUTHOR_ORGANIZATION);
                author.photo = attributes.getValue(ATTRIBUTE_AUTHOR_PHOTO);
                author.type = attributes.getValue(ATTRIBUTE_AUTHOR_TYPE);
                author.website = attributes.getValue(ATTRIBUTE_AUTHOR_WEBSITE);

                addCollectionElement(TAG_AUTHOR, author);
                break;
              }

            case STATE_AVAILABLE:
              {
                DepreciatedOrAvailable available = new DepreciatedOrAvailable();
                if (this.currentObject instanceof VersionableElement)
                  ((VersionableElement) this.currentObject).available = available;
                available.version = attributes.getValue(ATTRIBUTE_AVAILABLE_VERSION);
                startCollectingText(localName, attributes);
                break;
              }

            case STATE_CLASS:
            case STATE_INTERFACE:
              {
                ClassData clazz = new ClassData();
                this.currentObject = clazz;
                if (STATE_INTERFACE == state) {
                  clazz.isInterface = true;
                  addCollectionElement(TAG_INTERFACE, clazz);
                } else addCollectionElement(TAG_CLASS, clazz);
                clazz.name = attributes.getValue(ATTRIBUTE_CLASS_NAME);
                clazz.superclass = attributes.getValue(ATTRIBUTE_CLASS_SUPERCLASS);
                clazz.visibility = attributes.getValue(ATTRIBUTE_CLASS_VISIBILITY);
                clazz.getterPattern = attributes.getValue(ATTRIBUTE_CLASS_GETTERPATTERN);
                clazz.setterPattern = attributes.getValue(ATTRIBUTE_CLASS_SETTERPATTERN);

                this.collections = new HashMap();
                break;
              }

            case STATE_CONSTRUCTOR:
            case STATE_METHOD:
              {
                Method method = new Method();
                if (STATE_CONSTRUCTOR == state) {
                  method.isContructor = true;
                  addCollectionElement(TAG_CONSTRUCTOR, method);
                } else addCollectionElement(TAG_METHOD, method);
                this.currentObject = method;
                method.scope = attributes.getValue(ATTRIBUTE_CONSTRUCTOR_SCOPE);
                method.visibility = attributes.getValue(ATTRIBUTE_CONSTRUCTOR_VISIBILITY);
                method.name = attributes.getValue(ATTRIBUTE_METHOD_NAME);

                this.collections = new HashMap();
                break;
              }

            case STATE_DEPRECIATED:
              {
                DepreciatedOrAvailable depreciated = new DepreciatedOrAvailable();
                if (this.currentObject instanceof VersionableElement)
                  ((VersionableElement) this.currentObject).depreciated = depreciated;
                depreciated.isDepreciated = true;
                depreciated.version = attributes.getValue(ATTRIBUTE_DEPRECIATED_VERSION);
                startCollectingText(localName, attributes);
                break;
              }

            case STATE_DESCRIPTION:
              {
                startCollectingText(localName, attributes);
                break;
              }

            case STATE_ENUM:
              {
                Enum enumData = new Enum();
                this.currentObject = enumData;
                addCollectionElement(TAG_ENUM, enumData);
                enumData.name = attributes.getValue(ATTRIBUTE_ENUM_NAME);
                enumData.datatype = attributes.getValue(ATTRIBUTE_ENUM_DATATYPE);

                break;
              }

            case STATE_EVENT:
              {
                Event event = new Event();
                this.currentObject = event;
                addCollectionElement(TAG_EVENT, event);

                this.collections = new HashMap();
                break;
              }

            case STATE_EXCEPTION:
              {
                Exception exception = new Exception();
                this.currentObject = exception;
                addCollectionElement(TAG_EXCEPTION, exception);

                this.collections = new HashMap();
                break;
              }

            case STATE_FIELD:
            case STATE_PROPERTY:
              {
                Property property = new Property();
                this.currentObject = property;
                if (STATE_FIELD == state) {
                  property.isField = true;
                  addCollectionElement(TAG_FIELD, property);
                } else addCollectionElement(TAG_PROPERTY, property);
                property.name = attributes.getValue(ATTRIBUTE_FIELD_NAME);
                property.dataType = attributes.getValue(ATTRIBUTE_FIELD_DATATYPE);
                property.scope = attributes.getValue(ATTRIBUTE_FIELD_SCOPE);
                property.visibility = attributes.getValue(ATTRIBUTE_FIELD_VISIBILITY);

                this.collections = new HashMap();
                break;
              }

            case STATE_INCLUDE:
              {
                String src = attributes.getValue(ATTRIBUTE_INCLUDE_SRC);
                handleInclude(src);
                break;
              }

            case STATE_MIX:
              {
                Mix mix = new Mix();
                addCollectionElement(TAG_MIX, mix);
                this.currentObject = mix;
                mix.datatype = attributes.getValue(ATTRIBUTE_MIX_DATATYPE);
                mix.fromScope = attributes.getValue(ATTRIBUTE_MIX_FROMSCOPE);
                mix.toScope = attributes.getValue(ATTRIBUTE_MIX_TOSCOPE);

                break;
              }

            case STATE_MIXIN:
              {
                Mixin mixin = new Mixin();
                addCollectionElement(TAG_MIXIN, mixin);
                this.currentObject = mixin;
                mixin.name = attributes.getValue(ATTRIBUTE_MIXIN_NAME);
                mixin.scope = attributes.getValue(ATTRIBUTE_MIXIN_SCOPE);
                mixin.visibility = attributes.getValue(ATTRIBUTE_MIXIN_VISIBILITY);

                break;
              }

            case STATE_NAMESPACE:
              {
                Namespace namespace = new Namespace();
                addCollectionElement(TAG_NAMESPACE, namespace);
                this.currentObject = namespace;
                namespace.name = attributes.getValue(ATTRIBUTE_NAMESPACE_NAME);
                namespace.visibility = attributes.getValue(ATTRIBUTE_NAMESPACE_VISIBILITY);

                break;
              }

            case STATE_PARAMETER:
              {
                Parameter parameter = new Parameter();
                this.currentObject = parameter;
                addCollectionElement(TAG_PARAMETER, parameter);
                parameter.name = attributes.getValue(ATTRIBUTE_PARAMETER_NAME);
                parameter.dataType = attributes.getValue(ATTRIBUTE_PARAMETER_DATATYPE);
                parameter.usage = attributes.getValue(ATTRIBUTE_PARAMETER_USAGE);

                this.collections = new HashMap();
                break;
              }

            case STATE_QOUTE:
              {
                startCollectingText(localName, attributes);
                break;
              }

            case STATE_RETURNS:
              {
                ReturnsData returnData = new ReturnsData();
                if (this.currentObject instanceof Method)
                  ((Method) this.currentObject).returns = returnData;
                else if (this.currentObject instanceof Event)
                  ((Event) this.currentObject).returns = returnData;
                else if (this.currentObject instanceof Exception)
                  ((Exception) this.currentObject).returns = returnData;
                this.currentObject = returnData;
                returnData.dataType = attributes.getValue(ATTRIBUTE_RETURNS_DATATYPE);
                break;
              }
          }
          this.currentState = state;
        }
      }
    }
  }