~ubuntu-branches/ubuntu/trusty/aspectj/trusty

« back to all changes in this revision

Viewing changes to org.aspectj/modules/asm/src/org/aspectj/asm/internal/RelationshipMap.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2011-03-15 23:54:31 UTC
  • mfrom: (1.1.5 upstream) (7.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110315235431-7d8cs3gvs4tnqx7t
Tags: 1.6.11+dfsg-1
* New upstream release.
* Updated Standards-Version to 3.9.1 (no changes needed).
* Fix local Javadoc links:
  - d/patches/07_javadoc_links.diff: Use locally installed
   javadoc packages and hyperlink with them.
  - d/control: Add B-D on default-java-doc and libasm3-java-doc.
* d/control: Drop B-D on itself (our new bootstrap infrastructure doesn't need
  that anymore).
* Split packages into :
  - aspectj: only contains CLI tools.
  - libaspectj-java: JAR librairies for /usr/share/java.
  - libaspectj-java-doc: 4 API's Javadoc.
  - aspectj-doc: Programming Guides and SDK Documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* *******************************************************************
2
 
 * Copyright (c) 2003 Contributors.
 
2
 * Copyright (c) 2003,2010 Contributors
3
3
 * All rights reserved. 
4
4
 * This program and the accompanying materials are made available 
5
5
 * under the terms of the Eclipse Public License v1.0 
8
8
 *  
9
9
 * Contributors: 
10
10
 *     Mik Kersten     initial implementation 
 
11
 *     Andy Clement
11
12
 * ******************************************************************/
12
13
 
13
14
package org.aspectj.asm.internal;
18
19
import java.util.List;
19
20
import java.util.Set;
20
21
 
21
 
import org.aspectj.asm.IHierarchy;
22
22
import org.aspectj.asm.IProgramElement;
23
23
import org.aspectj.asm.IRelationship;
 
24
import org.aspectj.asm.IRelationship.Kind;
24
25
import org.aspectj.asm.IRelationshipMap;
25
 
import org.aspectj.asm.IRelationship.Kind;
26
26
 
27
27
/**
28
 
 * TODO: add a remove, and a clear all
29
 
 * 
30
28
 * @author Mik Kersten
31
 
 * 
 
29
 * @author Andy Clement
32
30
 */
33
 
public class RelationshipMap extends HashMap implements IRelationshipMap {
 
31
public class RelationshipMap extends HashMap<String, List<IRelationship>> implements IRelationshipMap {
34
32
 
35
33
        private static final long serialVersionUID = 496638323566589643L;
36
34
 
37
 
        // // As this gets serialized, make the hierarchy transient and
38
 
        // // settable
39
 
        // private transient IHierarchy hierarchy;
40
 
 
41
35
        public RelationshipMap() {
42
36
        }
43
37
 
44
 
        public RelationshipMap(IHierarchy hierarchy) {
45
 
                // this.hierarchy = hierarchy;
46
 
        }
47
 
 
48
 
        public void setHierarchy(IHierarchy hierarchy) {
49
 
                // commented out as field never read !
50
 
                // this.hierarchy = hierarchy;
51
 
        }
52
 
 
53
 
        public List get(String handle) {
54
 
                List relationships = (List) super.get(handle);
 
38
        public List<IRelationship> get(String handle) {
 
39
                List<IRelationship> relationships = super.get(handle);
55
40
                if (relationships == null) {
56
41
                        return null;
57
42
                } else {
59
44
                }
60
45
        }
61
46
 
62
 
        public List get(IProgramElement source) {
 
47
        public List<IRelationship> get(IProgramElement source) {
63
48
                return get(source.getHandleIdentifier());
64
49
        }
65
50
 
66
51
        public IRelationship get(String source, IRelationship.Kind kind, String relationshipName, boolean runtimeTest,
67
52
                        boolean createIfMissing) {
68
 
                List relationships = get(source);
 
53
                List<IRelationship> relationships = get(source);
69
54
                if (relationships == null) {
70
 
                        if (!createIfMissing)
 
55
                        if (!createIfMissing) {
71
56
                                return null;
72
 
                        relationships = new ArrayList();
73
 
                        IRelationship rel = new Relationship(relationshipName, kind, source, new ArrayList(), runtimeTest);
 
57
                        }
 
58
                        relationships = new ArrayList<IRelationship>();
 
59
                        IRelationship rel = new Relationship(relationshipName, kind, source, new ArrayList<String>(), runtimeTest);
74
60
                        relationships.add(rel);
75
61
 
76
62
                        super.put(source, relationships);
77
63
                        return rel;
78
64
                } else {
79
 
                        for (Iterator it = relationships.iterator(); it.hasNext();) {
80
 
                                IRelationship curr = (IRelationship) it.next();
 
65
                        for (Iterator<IRelationship> it = relationships.iterator(); it.hasNext();) {
 
66
                                IRelationship curr = it.next();
81
67
                                if (curr.getKind() == kind && curr.getName().equals(relationshipName) && curr.hasRuntimeTest() == runtimeTest) {
82
68
                                        return curr;
83
69
                                }
85
71
                        if (createIfMissing) {
86
72
                                // At this point we did find some relationships for 'source' but not one that looks like what we are
87
73
                                // after (either the kind or the name or the dynamictests setting don't match)
88
 
                                IRelationship rel = new Relationship(relationshipName, kind, source, new ArrayList(), runtimeTest);
 
74
                                IRelationship rel = new Relationship(relationshipName, kind, source, new ArrayList<String>(), runtimeTest);
89
75
                                relationships.add(rel);
90
76
                                return rel;
91
77
                        }
103
89
        }
104
90
 
105
91
        public boolean remove(String source, IRelationship relationship) {
106
 
                List list = (List) super.get(source);
 
92
                List<IRelationship> list = super.get(source);
107
93
                if (list != null) {
108
94
                        return list.remove(relationship);
109
95
                        // boolean matched = false;
123
109
                super.remove(source);
124
110
        }
125
111
 
126
 
        public Object put(Object o, Object p) {
127
 
 
128
 
                return super.put(o, p);
129
 
        }
130
 
 
131
112
        public void put(String source, IRelationship relationship) {
132
 
 
133
 
                // System.err.println(">> for: " + source + ", put::" + relationship);
134
 
 
135
 
                List list = (List) super.get(source);
136
 
                if (list == null) {
137
 
                        list = new ArrayList();
138
 
                        list.add(relationship);
139
 
 
140
 
                        super.put(source, list);
 
113
                List<IRelationship> existingRelationships = super.get(source);
 
114
                if (existingRelationships == null) {
 
115
                        // new entry
 
116
                        existingRelationships = new ArrayList<IRelationship>();
 
117
                        existingRelationships.add(relationship);
 
118
                        super.put(source, existingRelationships);
141
119
                } else {
142
120
                        boolean matched = false;
143
 
                        for (Iterator it = list.iterator(); it.hasNext();) {
144
 
                                IRelationship curr = (IRelationship) it.next();
145
 
                                if (curr.getName().equals(relationship.getName()) && curr.getKind() == relationship.getKind()) {
146
 
                                        curr.getTargets().addAll(relationship.getTargets());
 
121
                        for (IRelationship existingRelationship : existingRelationships) {
 
122
                                if (existingRelationship.getName().equals(relationship.getName())
 
123
                                                && existingRelationship.getKind() == relationship.getKind()) {
 
124
                                        existingRelationship.getTargets().addAll(relationship.getTargets());
147
125
                                        matched = true;
148
126
                                }
149
127
                        }
151
129
                                // bug?
152
130
                                System.err.println("matched = true");
153
131
                        }
154
 
                        if (matched)
155
 
                                list.add(relationship); // Is this a bug, will it give us double entries?
 
132
                        if (matched) {
 
133
                                existingRelationships.add(relationship); // Is this a bug, will it give us double entries?
 
134
                        }
156
135
                }
157
136
        }
158
137
 
164
143
                super.clear();
165
144
        }
166
145
 
167
 
        public Set getEntries() {
 
146
        public Set<String> getEntries() {
168
147
                return keySet();
169
148
        }
170
149