KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > dom > JdtASTMatcher


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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     public boolean match(SimpleName node, Object JavaDoc other) {
23         boolean isomorphic= super.match(node, other);
24         if (! isomorphic || !(other instanceof SimpleName))
25             return false;
26         SimpleName name= (SimpleName)other;
27         IBinding nodeBinding= node.resolveBinding();
28         IBinding otherBinding= name.resolveBinding();
29         if (nodeBinding == null) {
30             if (otherBinding != null) {
31                 return false;
32             }
33         } else {
34             if (nodeBinding != otherBinding) {
35                 return false;
36             }
37         }
38         if (node.resolveTypeBinding() != name.resolveTypeBinding())
39             return false;
40         return true;
41     }
42     
43     public static boolean doNodesMatch(ASTNode one, ASTNode other) {
44         Assert.isNotNull(one);
45         Assert.isNotNull(other);
46         
47         return one.subtreeMatch(new JdtASTMatcher(), other);
48     }
49 }
50
Popular Tags