PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 35ms app.codeStats 0ms

/bundles/plugins-trunk/RubyPlugin/src/org/jedit/ruby/cache/MethodToParents.java

#
Java | 66 lines | 35 code | 9 blank | 22 comment | 3 complexity | 23e03092c187d12637020e4a336ee6df MD5 | raw file
 1/*
 2 * MethodToParents.java - 
 3 *
 4 * Copyright 2005 Robert McKinnon
 5 *
 6 * This program is free software; you can redistribute it and/or
 7 * modify it under the terms of the GNU General Public License
 8 * as published by the Free Software Foundation; either version 2
 9 * of the License, or any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 */
20package org.jedit.ruby.cache;
21
22import org.jedit.ruby.ast.Member;
23import org.jedit.ruby.ast.Method;
24
25import java.util.*;
26
27/**
28 * @author robmckinnon at users.sourceforge.net
29 */
30final class MethodToParents {
31
32    private final Map<String, Set<Member>> methodToParentMap = new HashMap<String, Set<Member>>();
33
34    final void add(Method method) {
35        if (method.hasParentMember()) {
36            Member parentMember = method.getParentMember();
37            add(method, parentMember);
38        }
39    }
40
41    final void add(Method method, Member parentMember) {
42        String methodName = method.getName();
43        Set<Member> parentSet = getParentSet(methodName);
44        parentSet.add(parentMember);
45    }
46
47    final List<Member> getParentList(String methodName) {
48        Set<Member> memberSet = getParentSet(methodName);
49        List<Member> members = new ArrayList<Member>(memberSet);
50        if (members.size() > 1) {
51            Collections.sort(members);
52        }
53        return members;
54    }
55
56    final Set<Member> getParentSet(String methodName) {
57        if (!methodToParentMap.containsKey(methodName)) {
58            methodToParentMap.put(methodName, new HashSet<Member>());
59        }
60        return methodToParentMap.get(methodName);
61    }
62
63    final void clear() {
64        methodToParentMap.clear();
65    }
66}