Exemplo n.º 1
0
 public void test_ExtractMethodFromClosure() throws Exception {
   this.addNodeById("5161277940733600914");
   this.addNodeById("5161277940733600960");
   ExtractMethodRefactoringParameters params =
       ExtractMethodFactory.createParameters(
           ListSequence.fromListAndArray(
               new ArrayList<SNode>(),
               SNodeOperations.cast(
                   this.getNodeById("5161277940733600941"),
                   "jetbrains.mps.baseLanguage.structure.LocalVariableDeclarationStatement"),
               SNodeOperations.cast(
                   this.getNodeById("5161277940733600950"),
                   "jetbrains.mps.baseLanguage.structure.ExpressionStatement")));
   params.setName("foo");
   MethodParameter p0 = ListSequence.fromList(params.getParameters()).getElement(0);
   MethodParameter p1 = ListSequence.fromList(params.getParameters()).getElement(1);
   if (SNodeOperations.isInstanceOf(
       p0.getDeclaration(), "jetbrains.mps.baseLanguage.structure.LocalVariableDeclaration")) {
     ListSequence.fromList(params.getParameters()).setElement(0, p1);
     ListSequence.fromList(params.getParameters()).setElement(1, p0);
   }
   ExtractMethodRefactoring ref = ExtractMethodFactory.createRefactoring(params);
   ref.doRefactor();
   Assert.assertEquals(
       null,
       NodesMatcher.matchNodes(
           ListSequence.fromListAndArray(
               new ArrayList<SNode>(),
               SNodeOperations.cast(
                   this.getNodeById("5161277940733600919"),
                   "jetbrains.mps.baseLanguage.structure.ClassConcept")),
           ListSequence.fromListAndArray(
               new ArrayList<SNode>(),
               SNodeOperations.cast(
                   this.getNodeById("5161277940733600997"),
                   "jetbrains.mps.baseLanguage.structure.ClassConcept"))));
 }
 public void test_extractExpression() throws Exception {
   this.addNodeById("1230052684510");
   this.addNodeById("1230052684520");
   this.addNodeById("1230052684528");
   this.addNodeById("1230052684538");
   SLinkOperations.setTarget(
       SNodeOperations.cast(
           this.getNodeById("1230052684533"),
           "jetbrains.mps.baseLanguage.structure.StaticMethodCall"),
       "classConcept",
       SNodeOperations.cast(
           this.getNodeById("1230052684539"),
           "jetbrains.mps.baseLanguage.structure.ClassConcept"),
       false);
   SLinkOperations.setTarget(
       SNodeOperations.cast(
           this.getNodeById("1230052684533"),
           "jetbrains.mps.baseLanguage.structure.StaticMethodCall"),
       "baseMethodDeclaration",
       SNodeOperations.cast(
           this.getNodeById("1230052684540"),
           "jetbrains.mps.baseLanguage.structure.StaticMethodDeclaration"),
       false);
   ExtractMethodRefactoringParameters params =
       ExtractMethodFactory.createParameters(
           ListSequence.fromListAndArray(
               new ArrayList<SNode>(),
               SNodeOperations.cast(
                   this.getNodeById("1230052684515"),
                   "jetbrains.mps.baseLanguage.structure.StringLiteral")));
   params.setName("foo");
   params.setVisibilityLevel(VisibilityLevel.PUBLIC);
   ExtractMethodRefactoring ref = ExtractMethodFactory.createRefactoring(params);
   ref.setStaticContainer(
       SNodeOperations.cast(
           this.getNodeById("1230052684521"),
           "jetbrains.mps.baseLanguage.structure.ClassConcept"));
   ref.doRefactor();
   {
     List<SNode> nodesBefore =
         ListSequence.fromListAndArray(
             new ArrayList<SNode>(),
             SNodeOperations.cast(
                 this.getNodeById("1230052684511"),
                 "jetbrains.mps.lang.intentions.structure.IntentionDeclaration"),
             SNodeOperations.cast(
                 this.getNodeById("1230052684521"),
                 "jetbrains.mps.baseLanguage.structure.ClassConcept"));
     List<SNode> nodesAfter =
         ListSequence.fromListAndArray(
             new ArrayList<SNode>(),
             SNodeOperations.cast(
                 this.getNodeById("1230052684529"),
                 "jetbrains.mps.lang.intentions.structure.IntentionDeclaration"),
             SNodeOperations.cast(
                 this.getNodeById("1230052684539"),
                 "jetbrains.mps.baseLanguage.structure.ClassConcept"));
     Assert.assertNull(
         "nodes '" + nodesBefore + "' and '" + nodesAfter + "' do not match!",
         NodesMatcher.matchNodes(nodesBefore, nodesAfter));
   }
 }