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);
    }
  }
  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);
    */
  }
  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"));
          }
        }
      }
    }
  }
Ejemplo n.º 4
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);
    }
  }
Ejemplo n.º 5
0
  // FIXME migrate algorithm to BinMethodFormatter?
  // FIXME better use BinItemFormatter!!!
  String getCorrectTypeName(BinTypeRef aTypeRef) {
    if (aTypeRef.isPrimitiveType()) {
      return aTypeRef.getName();
    }

    if (aTypeRef.isArray()) {
      BinArrayType at = (BinArrayType) aTypeRef.getBinType();
      return getCorrectTypeName(at.getArrayType()) + at.getDimensionString();
    }

    String name =
        TypeUtil.getShortestUnderstandableName(
            aTypeRef.getBinCIType(), getField().getOwner().getBinCIType());
    if ("".equals(name)) {
      name = aTypeRef.getName();
    }

    return name;
  }