]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/core extension/org/eclipse/jdt/internal/corext/dom/JdtASTMatcher.java
Some talks, mostly identical.
[ifi-stolz-refaktor.git] / case-study / jdt-before / core extension / org / eclipse / jdt / internal / corext / dom / JdtASTMatcher.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2011 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.corext.dom;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.jdt.core.dom.ASTMatcher;
16 import org.eclipse.jdt.core.dom.ASTNode;
17 import org.eclipse.jdt.core.dom.IBinding;
18 import org.eclipse.jdt.core.dom.SimpleName;
19
20 public class JdtASTMatcher extends ASTMatcher {
21
22         @Override
23         public boolean match(SimpleName node, Object other) {
24                 boolean isomorphic= super.match(node, other);
25                 if (! isomorphic || !(other instanceof SimpleName))
26                         return false;
27                 SimpleName name= (SimpleName)other;
28                 IBinding nodeBinding= node.resolveBinding();
29                 IBinding otherBinding= name.resolveBinding();
30                 if (nodeBinding == null) {
31                         if (otherBinding != null) {
32                                 return false;
33                         }
34                 } else {
35                         if (nodeBinding != otherBinding) {
36                                 return false;
37                         }
38                 }
39                 if (node.resolveTypeBinding() != name.resolveTypeBinding())
40                         return false;
41                 return true;
42         }
43
44         public static boolean doNodesMatch(ASTNode one, ASTNode other) {
45                 Assert.isNotNull(one);
46                 Assert.isNotNull(other);
47
48                 return one.subtreeMatch(new JdtASTMatcher(), other);
49         }
50 }