Package no.hal.jex

Examples of no.hal.jex.JavaClass


    return super.getImage(object);
  }
 
  @Override
  public String getImageName(Object object) {
    JavaClass javaClass = (JavaClass)object;
    if (javaClass.getClassKind() == ClassKind.INTERFACE_KIND) {
      return JDT_UI_IMAGE_PREFIX + "int_obj.gif";
    } else if (javaClass.getClassKind() == ClassKind.ENUM_KIND) {
      String modifierString = getAccessModifierString(javaClass, JexFactoryImpl.getModifier("public"), null);
      return JDT_UI_IMAGE_PREFIX + "enum_" + (modifierString != null ? modifierString + "_" : "") + "obj.gif";
    }
    return JDT_UI_IMAGE_PREFIX + "class_obj.gif";
  }
View Full Code Here


      JavaPack pack = (JavaPack)parent;
      List<IMember> classes = JdtHelper.findJavaMembers((IPackageFragment) javaElement, null, IJavaElement.TYPE, IType.class);
      createJexClasses(classes, depth, pack.getClasses());
      createNamedClass(pack.getName() + "." + ALL_TESTS_TEST_SUITE_NAME, JexPackage.eINSTANCE.getTestSuite(), null, depth, pack.getClasses());
    } else if (parent instanceof JavaClass && javaElement instanceof IType) {
      JavaClass javaClass = (JavaClass)parent;
      IType type = (IType)javaElement;
      List<IMember> fields = JdtHelper.findJavaMembers(type, null, IJavaElement.FIELD, IField.class);
      for (Iterator<IMember> it = fields.iterator(); it.hasNext();) {
        IField field = (IField) it.next();
        if (matchesModifiers(field)) {
          if (parent instanceof TestRunnable) {
            continue;
          }
          ensureJexMember(JexPackage.eINSTANCE.getJavaField(), field, javaClass.getMembers());
        }
      }
      List<IMember> methods = JdtHelper.findJavaMembers(type, null, IJavaElement.METHOD, IMethod.class);
      for (Iterator<IMember> it = methods.iterator(); it.hasNext();) {
        IMethod method = (IMethod)it.next();
        if (matchesModifiers(method)) {
          EClass methodClass = JexPackage.eINSTANCE.getJavaMethod();
          if (parent instanceof TestRunnable) {
            if (! isMethodTester(method)) {
              continue;
            }
            methodClass = JexPackage.eINSTANCE.getJavaMethodTester();
          }
          JavaMethod newMethod = (JavaMethod)ensureJexMember(methodClass, method, javaClass.getMembers());
          // clear type if method is a constructor
          if (newMethod.getSimpleName().equals(javaClass.getSimpleName())) {
            newMethod.setReturnType(null);
          }
          if (newMethod instanceof JavaMethodTester && parent instanceof JavaClassTester) {
            for (Member member : ((JavaClassTester) parent).getTestedElements()) {
              Member testedMethod = findTestedMethod(newMethod.getSimpleName(), ((JavaClass) member).getMembers());
              if (testedMethod != null) {
                ((JavaMethodTester) newMethod).getTestedElements().add(testedMethod);
              }
            }
          }
        }
      }
      List<IMember> classes = JdtHelper.findJavaMembers(type, null, IJavaElement.TYPE, IType.class);
      createJexClasses(classes, depth, javaClass.getMembers());
    }
  }
View Full Code Here

  private List<? extends Member> createJexClasses(List<IMember> classes, int depth, List<? extends Member> results) throws JavaModelException, Exception {
    for (Iterator<IMember> it = classes.iterator(); it.hasNext();) {
      IType type = (IType) it.next();
      if (matchesModifiers(type)) {
        JavaClass newClass = (JavaClass) ensureJexMember(JexPackage.eINSTANCE.getJavaClass(), type, results);
        if (depth != 0) {
          createChildrenFromJavaModel(newClass, type, depth - 1);
        }
        createNamedClass(newClass.getFullName() + TEST_CLASS_NAME_SUFFIX, JexPackage.eINSTANCE.getJavaClassTester(), newClass, depth, results);
      }
    }
    return results;
  }
View Full Code Here

  }

  private JavaClass createNamedClass(String name, EClass eClass, Member testedElement, int depth, List<? extends Member> results) throws JavaModelException, Exception {
    IType type = JdtHelper.findJdtClass(name, JdtHelper.getJavaProject(testedElement.eResource().getURI()));
    if (type != null && matchesModifiers(type)) {
      JavaClass newClass = (JavaClass) ensureJexMember(eClass, type, results);
      if (newClass instanceof TestRunnable) {
        ((TestRunnable) newClass).getTestedElements().add(testedElement);
      }
      if (depth != 0) {
        createChildrenFromJavaModel(newClass, type, depth - 1);
View Full Code Here

    jexMember.setModifiers(jdtMember.getFlags());
    if (jexMember instanceof JavaClass) {
      if (! (jdtMember instanceof IType)) {
        throw new IllegalArgumentException("Cannot init JavaClass from " + jdtMember);
      }
      JavaClass jexClass = (JavaClass) jexMember;
      IType jdtType = (IType) jdtMember;
      ClassKind kind = ClassKind.CLASS_KIND;
      if (jdtType.isInterface()) {
        kind = ClassKind.INTERFACE_KIND;
      } else if (jdtType.isEnum()) {
        kind = ClassKind.ENUM_KIND;
      }
      jexClass.setClassKind(kind);
      String superclassName = jdtType.getSuperclassName();
      if (superclassName != null && (! "Object".equals(superclassName))) {
        jexClass.getSuperclasses().add(superclassName);
      }
      jexClass.getSuperclasses().addAll(Arrays.asList(jdtType.getSuperInterfaceNames()));
    } else if (jexMember instanceof JavaMethod) {
      if (! (jdtMember instanceof IMethod)) {
        throw new IllegalArgumentException("Cannot init JavaMethod from " + jdtMember);
      }
      JavaMethod javaMethod = (JavaMethod) jexMember;
View Full Code Here

    TreeIterator<EObject> it = jexRes.getAllContents();
    while (it.hasNext()) {
      Object o = it.next();
      if (o instanceof JavaClass) {
        it.prune();
        JavaClass javaClass = (JavaClass)o;
        if (isResourceClass(javaClass)) {
          addFile(getJavaElementResource(JdtHelper.getJdtElement(javaClass)));
        }
      }
    }
View Full Code Here

    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);
    }
View Full Code Here

    testReq.setJavaElement(javaMethodTester);
    testReq.setTestRunnable(javaMethodTester);
   
    reqParent.getRequirements().add(testReq);

    JavaClass methodParent = null;
    for (Member member : methodParents) {
      if (member instanceof JavaClass) {
        methodParent = (JavaClass) member;
        break;
      }
    }
    // add java elements and requirements for the tested elements
    String[] testedElements = testsAnnotation.split(";");
    for (int i = 0; i < testedElements.length; i++) {
      String testedElementName = testedElements[i].trim();
      String returnType = null, modifiers = null;
      for (int j = 0; j < visibilityPrefixes.length; j += 2) {
        String prefix = visibilityPrefixes[j];
        if (testedElementName.startsWith(prefix)) {
          modifiers = visibilityPrefixes[j + 1];
          testedElementName = testedElementName.substring(prefix.length());
          break;
        }
      }
      testReq.setText(testReq.getText() + (i == 0 ? " " : ", ") + testedElementName);
      int pos1 = testedElementName.indexOf('('), pos = testedElementName.lastIndexOf(' ', pos1 >= 0 ? pos1 : testedElementName.length());
      if (pos >= 0) {
        returnType = testedElementName.substring(0, pos);
        pos1 -= pos + 1;
        testedElementName = testedElementName.substring(pos + 1);
      }
      int pos2 = testedElementName.lastIndexOf(')');
      Member testedElement = null;
      if (pos1 >= 0 && pos2 >= 0) {
        String[] params = {}, exceptions = {};
        if (pos2 > pos1 + 2) {
          params = parseTypeList(testedElementName.substring(pos1 + 1, pos2));
        }
        String THROWS_KEYWORD = "throws ";
        int pos3 = testedElementName.indexOf(THROWS_KEYWORD, pos2);
        if (pos3 >= pos2) {
          exceptions = parseTypeList(testedElementName.substring(pos3 + THROWS_KEYWORD.length()));
        }
        testedElementName = testedElementName.substring(0, pos1);
        if (methodParent == null) {
          continue;
        }
        if (testedElementName != methodParent.getName() && returnType == null) {
          returnType = "void";
        }
        JavaMethod javaMethod = (JavaMethod) ensureJavaMethod(testedElementName, returnType, params, exceptions, methodParent.getMembers());
        testedElement = javaMethod;
      } else {
        JavaField javaField = (JavaField) ensureJavaElement(testedElementName, methodParent.getMembers(), JexPackage.eINSTANCE.getJavaField());
        javaField.setType(returnType);
        testedElement = javaField;
      }
      javaMethodTester.getTestedElements().add(testedElement);
      JavaRequirement javaReq = JexFactory.eINSTANCE.createJavaRequirement();
View Full Code Here

   * @NOT generated
   */
  public String toString() {
    if (eIsProxy()) return super.toString();

    JavaClass parent = getOwner();
    return getName() + (parent != null ? " in " + parent : "");
  }
View Full Code Here

  public String getSimpleName() {
    return getSimpleName(getName());
  }
 
  public String getFullName() {
    JavaClass javaClass = (this instanceof JavaClass ? (JavaClass) this : getOwner());
    JavaPack pack = (javaClass != null ? javaClass.getPack() : null);
    String packageName = (pack != null ? pack.getName() : null);
    String className = (packageName != null && packageName.length() > 0 ? packageName + "." : "") + javaClass.getName();
    return (javaClass == null ? getName() : (javaClass == this ? className : className + "." + getName()));
  }
View Full Code Here

TOP

Related Classes of no.hal.jex.JavaClass

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.