Package no.hal.jex

Examples of no.hal.jex.JavaRequirement


      type = reflectionHelper.getReflectiveClass(junitTestSuite.getName());
    } catch (ClassNotFoundException e) {
      return null;
    }
    JExercise jexAnnotation = (JExercise) type.getAnnotation(JExercise.class);
    JavaRequirement req = ensureJavaRequirement(packageName, type.getSimpleName(), testedClassName, jexAnnotation.tests(), false);
    setAnnotationFeatures(req, jexAnnotation);
    for (int i = 0; i < junitTestSuite.testCount(); i++) {
      createFromTestClassAnnotations(junitTestSuite.testAt(i), req);
    }
    return req;
View Full Code Here


      Member member = (Member)javaElement;
      EClass reqClass = JexPackage.eINSTANCE.getJavaRequirement();
      if (member instanceof TestRunnable) {
        reqClass = JexPackage.eINSTANCE.getJUnitTest();
      }
      JavaRequirement req = (JavaRequirement)ensureRequirement(reqClass, member, reqParent.getRequirements());
      // must add to parent before searching hierarchy
      reqParent.getRequirements().add(req);
      if (req instanceof JUnitTest) {
        JUnitTest testReq = (JUnitTest) req;
        if (member instanceof TestRunnable) {
View Full Code Here

    return (member instanceof JavaMethod && isJUnitTestClass(member.getParent()) && member.getSimpleName().startsWith("test"));
  }
  */

  private Requirement ensureRequirement(EClass eClass, Member javaElement, List otherReqs) throws JavaModelException {
    JavaRequirement newReq = (JavaRequirement)JexPackage.eINSTANCE.getEFactoryInstance().create(eClass);
    newReq.setJavaElement(javaElement);
    newReq.setText(javaElement.toString());
//    if (newReq instanceof JUnitTest && javaElement instanceof TestRunnable) {
//      ((JUnitTest)newReq).setTestRunnable((TestRunnable)javaElement);
//    }
    if (otherReqs != null) {
      for (int i = 0; i < otherReqs.size(); i++) {
        JavaRequirement otherReq = (JavaRequirement)otherReqs.get(i);
        Member otherJavaElement = (Member)otherReq.getJavaElement();
        if (otherJavaElement == javaElement) {
          return otherReq;
        }
      }
      otherReqs.add(newReq);
View Full Code Here

        partText = partText + ": " + text;
      }
      String pointsText = ExerciseView.refreshPoints((ExercisePart)obj, "{0} of {1}", null);
      text = partText + " - " + pointsText;
    } else if (obj instanceof JavaRequirement) {
      JavaRequirement req = (JavaRequirement)obj;
      JavaElement javaElement = req.getJavaElement();
      if (text == null) {
        text = javaElement.toString();
      }
    }
    return (text != null ? text : "");
View Full Code Here

      if (text != null) {
        partText = text + ": " + text;
      }
      text = partText;
    } else if (obj instanceof JavaRequirement) {
      JavaRequirement req = (JavaRequirement)obj;
      JavaElement javaElement = req.getJavaElement();
      if (text == null) {
        text = javaElement.toString();
      }
      // MessageFormat.format(req.getWhat(), new Object[]{<java_element>.getName()});
    }
    if (obj instanceof AbstractRequirement) {
      text += "<p>";
      AbstractRequirement req = (AbstractRequirement)obj;
      for (AbstractRequirement subReq: req.getRequirements()) {
        String uri = getResourceURI(subReq.eResource(), subReq);
        if (uri != null) {
          text += "<li><a href='" + uri + "'>" + subReq.getText() + "</a></li>";
        }
      }
View Full Code Here

      fireRequirementSelected(req);
    }
  }

  public void doubleClick(DoubleClickEvent event) {
    JavaRequirement req = (JavaRequirement)getSelection(event.getSelection(), JavaRequirement.class);
    if (req != null) {
      fireRequirementValidationRequested((JavaRequirement)req);
//    } else {
//      JexResource res = (JexResource)getSelection(event.getSelection(), JexResource.class);
//      JexManager manager = JexUiPlugin.getPlugin().getExerciseManager();
View Full Code Here

        partText = partText + ": " + text;
      }
      String pointsText = "<points>"; // ExerciseView.refreshPoints((ExercisePart)obj, "{0} of {1}", null);
      text = partText + " - " + pointsText;
    } else if (obj instanceof JavaRequirement) {
      JavaRequirement req = (JavaRequirement)obj;
      JavaElement javaElement = req.getJavaElement();
      if (text == null) {
        text = javaElement.toString();
      }
    }
    return (text != null ? text : "");
View Full Code Here

  }

  private JavaRequirement createFromTestClassAnnotations(IType type, String testedClassName) {
    IMemberValuePair[] annotations = JdtHelper.getAnnotationValuePairs(type, AbstractTestAnnotationsToModelConverter.JEX_ANNOTATION_NAME);
    String tests = (String) JdtHelper.getAnnotationValue(annotations, JEX_TESTS_ANNOTATION_KEY, IMemberValuePair.K_STRING);
    JavaRequirement req = ensureJavaRequirement(getPackageName(type), type.getElementName(), testedClassName, tests, false);
    setAnnotationFeatures(req, annotations);
    for (IJavaElement child : JdtHelper.getJavaElementChildren(type)) {
      if (child instanceof IMethod && isMethodTester((IMethod) child)) {
        String methodName = child.getElementName();
        String namePrefix = AbstractTestAnnotationsToModelConverter.TEST_METHOD_NAME_PREFIX;
        if (methodName.startsWith(namePrefix)) {
          String testedMethodName = Character.toLowerCase(methodName.charAt(namePrefix.length())) + methodName.substring(namePrefix.length() + 1);
          JavaClassTester javaClassTester = (JavaClassTester) req.getJavaElement();
          createFromTestMethodAnnotations((IMethod) child, testedMethodName, javaClassTester, javaClassTester.getTestedElements(), req, annotations);
        }
      }
    }
    return req;
View Full Code Here

    ensureJavaPack(name, ex.getJavaElements());
    return exercisePart;
  }
 
  protected JavaRequirement ensureJavaRequirement(String packageName, String testClassName, String testedClassName, String testsAnnotation, boolean preferJunitTest) {
    JavaRequirement req = null;
    boolean hasTestsAnnotation = testsAnnotation != null && testsAnnotation.length() > 0;
    if (hasTestsAnnotation && preferJunitTest) {
      req = JexFactory.eINSTANCE.createJUnitTest();
    } else {
      if (! hasTestsAnnotation) {
        testsAnnotation = testedClassName;
      }
      req = JexFactory.eINSTANCE.createJavaRequirement();
    }
    String packagePrefix = packageName != null && packageName.length() > 0 ? packageName + "." : "";
    req.setText((req instanceof JUnitTest ? "Test " : "") + packagePrefix + testsAnnotation);
    JavaClassTester javaClassTester = (JavaClassTester) ensureJavaClass(packageName, testClassName, JexPackage.eINSTANCE.getJavaClassTester());
    String[] superClasses = {},  superInterfaces = {};
    int pos = testsAnnotation.indexOf(' ');
    if (pos >= 0) {
      testedClassName = testsAnnotation.substring(0, pos);
      testsAnnotation = testsAnnotation.substring(pos + 1);
      String EXTENDS_KEYWORD = "extends ", IMPLEMENTS_KEYWORD = "implements ";
      int extendsPos = testsAnnotation.indexOf(EXTENDS_KEYWORD), implementsPos = testsAnnotation.indexOf(IMPLEMENTS_KEYWORD);
      if (extendsPos >= 0) {
        superClasses = parseTypeList(testsAnnotation.substring(extendsPos + EXTENDS_KEYWORD.length(), implementsPos > extendsPos ? implementsPos : testsAnnotation.length()));
      }
      if (implementsPos >= 0) {
        superInterfaces = parseTypeList(testsAnnotation.substring(implementsPos + IMPLEMENTS_KEYWORD.length(), extendsPos > implementsPos ? extendsPos : testsAnnotation.length()));
      }
    } else {
      testedClassName = testsAnnotation;
    }
    int pos3 = testedClassName.lastIndexOf('.');
    if (pos3 >= 0) {
      packageName = testedClassName.substring(0, pos3);
      testedClassName = testedClassName.substring(pos3 + 1);
    }
    JavaClass javaClass = ensureJavaClass(packageName, testedClassName, JexPackage.eINSTANCE.getJavaClass());
    addAll(javaClass.getSuperclasses(), superClasses);
    addAll(javaClass.getSuperclasses(), superInterfaces);
    javaClassTester.getTestedElements().add(javaClass);
    ExercisePart part = ensureExercisePart(exercise, packageName);
    if (req instanceof JUnitTest) {
      ((JUnitTest) req).setTestRunnable(javaClassTester);
    }
    req.setJavaElement(javaClassTester); // redundant?
    part.getRequirements().add(req);
    return req;
  }
View Full Code Here

        JavaField javaField = (JavaField) ensureJavaElement(testedElementName, methodParent.getMembers(), JexPackage.eINSTANCE.getJavaField());
        javaField.setType(returnType);
        testedElement = javaField;
      }
      javaMethodTester.getTestedElements().add(testedElement);
      JavaRequirement javaReq = JexFactory.eINSTANCE.createJavaRequirement();
      javaReq.setText("Requires " + testedElements[i].trim());
      javaReq.setJavaElement(testedElement);

      if (modifiers != null) {
        testedElement.setModifiers((Integer) JexFactory.eINSTANCE.createFromString(JexPackage.eINSTANCE.getModifiers(), modifiers));
      } else {
        javaReq.setRequiredFeatures("!modifiers");
      }
      testReq.getRequirements().add(javaReq);
    }
    return testReq;
  }
View Full Code Here

TOP

Related Classes of no.hal.jex.JavaRequirement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.