2014-10-13 1 views
0

나는 방법 내에서 변경 사항을 찾아야하는 곳에 플러그인을 만들었습니다. JavaCore.addElementChangedListener를 사용하여 Java 파일에서 발생하는 변경 사항을 수신합니다. 하지만 난 방법 안의 변화를 얻을 수 없습니다. 메서드 내부에서 변경 내용을 가져 오려고합니다. How to capture changes inside methods in an Eclipse plugin을 통과했지만 하위 트리를 가져올 수없고 fileds를 변경할 수 없습니다. 사실 실제 개념을 얻을 수 없습니다. 방법 변경 사항을 알려주십시오.자바 파일 내부의 메소드에서 수정을 식별하는 방법은 무엇입니까?

+0

당신을 찾으려는가요? 그것은 분명 할 수도 있지만, 우리에게 명확하지 않습니다. 로컬 필드에 대한 수정을 의미합니까? 데이터 모델의 일부분에? 다른 것? –

+0

사용자가 메서드 내에서 일부 논리를 변경하면 변경이 발생한 메서드 이름이 필요합니다. –

+0

@AndrzejDoyle : 메서드 이름을 가져 오는 방법은 무엇입니까? 지금 당장 그것을 필요로합니다. 이것으로 나를 도와주세요 –

답변

1

마지막으로 몇 가지 방법을 통해 메서드 내부에서 일어나는 변화를 식별 할 수 있지만 동시에 제공합니다. How to capture changes inside methods in an Eclipse plugin 답변에 지정된대로 해시 맵에 저장하고 IResourceChangeEvent.POST_CHANGE를 사용하여 사용자에게 발생한 변경 사항 콜렉션을 가져올 수 있습니다. 파일을 저장합니다.

public void elementChanged(ElementChangedEvent event) { 
    IJavaElementDelta delta= event.getDelta(); 
     if (delta != null) {    
      delta.getCompilationUnitAST().accept(new ASTVisitor() { 

      @Override 
      public boolean visit(MethodDeclaration node) { 
       String name = ((TypeDeclaration) node.getParent()).getName() 
        .getFullyQualifiedName() + "." + node.getName().getFullyQualifiedName(); 

       boolean changedmethodvalue = false; 

       if (subtrees.containsKey(name)){ 

        changedmethodvalue = !node.subtreeMatch(new ASTMatcher(),subtrees.get(Name)); 

        if(changedmethodvalue){ 

         System.out.println("method changed"+Name+":"+changedmethodvalue); 

         /** 
         * Store the changed method inside the hash map for future reflection. 
         */ 

         changed.put(Name, (IMethod) node.resolveBinding().getJavaElement()); 

         /** 
         * setting up the hash map value each time changes happened. 
         * 
         */ 
         ModificationStore.setChanged(changed); 



         } 
       } 
       else{ 

        // No earlier entry found, definitely changed 
        methodHasChanged = true; 
        System.out.println("A new method is added"); 

       } 

      } 
         /** 
        * updating the subtree structure 
        */ 
         subtrees.put(mName, node); 

         return true; 
        } 
       }); 

     } 
    } 
} 

사용자가 저장 옵션을 호출하면 우리는 메소드 이름의 수집 및 해시 맵

public class InvokeSynchronizer implements IResourceDeltaVisitor{ 

private static HashMap<String, IMethod> methodtoinvoke = new HashMap<String, IMethod>(); 

public boolean visit(IResourceDelta delta) { 

     IResource res = delta.getResource(); 
     switch (delta.getKind()) { 

      case IResourceDelta.ADDED: 
       System.out.println("ADDED: "); 
      break; 
     case IResourceDelta.CHANGED: 
      /** 
       * methodtoinvoke is a hash map values got from the modification store class. 
       */ 
       methodtoinvoke=ModificationStore.getChanged(); 

       Iterator it = methodtoinvoke.entrySet().iterator(); 
       while (it.hasNext()) { 

       Map.Entry pairs = (Map.Entry)it.next(); 
       // System.out.println(pairs.getKey() + " = " + pairs.getValue()); 
        IMethod methods=(IMethod) pairs.getValue(); 

        //IResource resource=(IResource) methods; 

        System.out.println("I resource value"+res); 

        System.out.println("\nlocation of the method:"+methods.getParent().getResource().toString()); 
        System.out.println("\n\nmethod name ::"+methods.getElementName()); 

        it.remove(); // avoids a ConcurrentModificationException 
       }} 
     return true; 
    } 

}에서 자신의 위치를 ​​얻을 수 있습니다 특히, "변경"무엇,

관련 문제