private void renameMustFail(String methodName, String newMethodName, String[] signatures)
      throws Exception {
    final Project project = RwRefactoringTestUtils.createMutableProject(getInitialProject());
    project.getProjectLoader().build();

    BinTypeRef aRef = project.findTypeRefForName("p.A");

    BinTypeRef[] params = RenameMethodTest.convertSingature(project, signatures);
    BinMethod m =
        MethodInvocationRules.getMethodDeclaration(aRef.getBinCIType(), aRef, methodName, params);

    String debugString = RenameMethodTest.filesToString(project);

    assertNotNull(m);

    RenameMethod renamer = new RenameMethod(new NullContext(project), m);
    renamer.setNewName(newMethodName);

    RefactoringStatus status = renamer.checkPreconditions();
    status.merge(renamer.checkUserInput());

    status.merge(renamer.apply());

    if (status.isOk()) {
      fail("Should have failed" + debugString);
    }

    /*		IType classA= getType(createCUfromTestFile(getPackageP(), "A"), "A");
        RenameMethodRefactoring ref= RenameMethodRefactoring.createInstance(classA.getMethod(methodName, signatures));
        ref.setNewName(newMethodName);
        RefactoringStatus result= performRefactoring(ref);
        assertNotNull("precondition was supposed to fail", result);
    */
  }
  private void renameMustWork(
      String methodName, String newMethodName, String[] signatures, boolean updateReferences)
      throws Exception {
    final Project project = RwRefactoringTestUtils.createMutableProject(getInitialProject());
    project.getProjectLoader().build();

    BinTypeRef aRef = project.findTypeRefForName("p.A");

    BinTypeRef[] params = RenameMethodTest.convertSingature(project, signatures);
    BinMethod m =
        MethodInvocationRules.getMethodDeclaration(aRef.getBinCIType(), aRef, methodName, params);

    String debugString = RenameMethodTest.filesToString(project);

    assertNotNull(m);

    RenameMethod renamer = new RenameMethod(new NullContext(project), m);
    renamer.setNewName(newMethodName);

    RefactoringStatus status = renamer.checkPreconditions();
    status.merge(renamer.checkUserInput());

    status.merge(renamer.apply());

    if (!status.isOk()) {
      fail("Should have worked" + debugString);
    }
  }
  protected void setUp() throws Exception {
    oldJvmMode = Project.getDefaultOptions().getJvmMode();
    Project.getDefaultOptions().setJvmMode(FastJavaLexer.JVM_50);

    // INIT PROJECT FROM SOURCE AND PATH
    final ProjectMetadata metadata = Utils.getTestProjects().getProject(PROJECT_ID);
    if (metadata == null) {
      fail("Wasn`t able to find project with such id '" + PROJECT_ID + "'");
    }

    project = Utils.createTestRbProject(metadata);
    if (project == null) {
      fail("Failed to create project: " + PROJECT_ID);
    }

    try {
      project.getProjectLoader().build();
    } catch (Exception e) {
      fail("Failed project.load(): " + e);
    }

    assertFalse(
        "Project was not built properly - has errors: "
            + CollectionUtil.toList(
                (project.getProjectLoader().getErrorCollector()).getUserFriendlyErrors()),
        (project.getProjectLoader().getErrorCollector()).hasErrors());
  }
示例#4
0
  public static ClassPath[] collectClassPaths(List projects) {
    ArrayList result = new ArrayList(3);
    for (int i = 0, max = projects.size(); i < max; i++) {
      Project project = (Project) projects.get(i);
      ClassPath cp = project.getPaths().getClassPath();
      if (cp instanceof CompoundClassPath) {
        result.add(((CompoundClassPath) cp).getPaths()[0]);
      } else {
        result.add(cp);
      }
    }

    return (ClassPath[]) result.toArray(new ClassPath[result.size()]);
  }
示例#5
0
  public static SourcePath[] collectSourcePaths(List projects) {
    ArrayList result = new ArrayList(3);
    for (int i = 0, max = projects.size(); i < max; i++) {
      Project project = (Project) projects.get(i);
      SourcePath sp = project.getPaths().getSourcePath();
      if (sp instanceof CompoundSourcePath) {
        result.add(((CompoundSourcePath) sp).getPaths()[0]);
      } else {
        result.add(sp);
      }
    }

    return (SourcePath[]) result.toArray(new SourcePath[result.size()]);
  }
  public void test() {
    String qName = "Test2";

    BinTypeRef ref = project.getTypeRefForName(qName);
    assertNotNull(ref);
    BinCIType type = ref.getBinCIType();

    BinMethod[] methods = type.getDeclaredMethods();
    for (int i = 0; i < methods.length; i++) {

      if (methods[i].getName().equals("main")) {
        MethodVisitor visitor = new MethodVisitor();
        methods[i].accept(visitor);

        for (int j = 0; j < visitor.METHODS.size(); j++) {

          if (((String) visitor.METHODS.get(j)).equals("target2")) {
            String retType = (String) visitor.RETTYPES.get(j);

            //            System.out.println(retType);

            assertTrue("Return type must be String, found: " + retType, retType.equals("String"));
          } else if (((String) visitor.METHODS.get(j)).equals("target")) {
            String retType = (String) visitor.RETTYPES.get(j);

            //            System.out.println(retType);

            assertTrue("Return type must be Integer, found: " + retType, retType.equals("Integer"));
          }
        }
      }
    }
  }
示例#7
0
  public void setUp() {
    if (p == null) {
      try {
        p =
            MinimizeAccessRightsTest.getProjectForTest(
                MinimizeAccessRightsTest.checkPossibleEjbMethodsTest);
      } catch (Exception e) {
        throw new ChainableRuntimeException(e);
      }

      beanRef = p.getTypeRefForName("a.MainBean");
      bean = (BinClass) beanRef.getBinCIType();
      ejbFindAll = bean.getDeclaredMethod("ejbFindAll", BinTypeRef.NO_TYPEREFS);
      ejbSelect = bean.getDeclaredMethod("ejbSelect", BinTypeRef.NO_TYPEREFS);
      toStringMethod = bean.getDeclaredMethod("toString", BinTypeRef.NO_TYPEREFS);
    }
  }
 protected void tearDown() throws Exception {
   Project.getDefaultOptions().setJvmMode(oldJvmMode);
 }
示例#9
0
 public void testIsEntityBean() throws Exception {
   assertTrue(EjbUtil.isEnterpriseBean(bean.getTypeRef()));
   assertFalse(EjbUtil.isEnterpriseBean(p.getObjectRef()));
 }