Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 287907 | Differences between
and this patch

Collapse All | Expand All

(-)parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java (-2 / +2 lines)
Lines 119-128 Link Here
119
	}
119
	}
120
	
120
	
121
	@Override
121
	@Override
122
	public void addChild(PDOMNode member) throws CoreException {
122
	public final void addChild(PDOMNode member) throws CoreException {
123
		getPDOM().removeCachedResult(record + PDOMCPPLinkage.CACHE_MEMBERS);
124
		PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + MEMBERLIST);
123
		PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + MEMBERLIST);
125
		list.addMember(member);
124
		list.addMember(member);
125
		PDOMCPPClassScope.updateCache(this, member);
126
	}
126
	}
127
	
127
	
128
	@Override
128
	@Override
(-)parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassScope.java (-26 / +45 lines)
Lines 50-61 Link Here
50
import org.eclipse.cdt.internal.core.pdom.PDOM;
50
import org.eclipse.cdt.internal.core.pdom.PDOM;
51
import org.eclipse.cdt.internal.core.pdom.dom.BindingCollector;
51
import org.eclipse.cdt.internal.core.pdom.dom.BindingCollector;
52
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
52
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
53
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
53
import org.eclipse.core.runtime.CoreException;
54
import org.eclipse.core.runtime.CoreException;
54
55
55
/**
56
/**
56
 * Represents the class scope for a class stored in the index.
57
 * Represents the class scope for a class stored in the index.
57
 */
58
 */
58
class PDOMCPPClassScope implements ICPPClassScope, IIndexScope {
59
class PDOMCPPClassScope implements ICPPClassScope, IIndexScope {
60
	private static final class PopulateMap implements IPDOMVisitor {
61
		private final CharArrayMap<List<PDOMBinding>> fResult;
62
		private PopulateMap(CharArrayMap<List<PDOMBinding>> result) {
63
			fResult = result;
64
		}
65
66
		public boolean visit(IPDOMNode node) throws CoreException {
67
			if (node instanceof PDOMBinding) {
68
				final PDOMBinding binding= (PDOMBinding) node;
69
				final char[] nchars = binding.getNameCharArray();
70
				List<PDOMBinding> list= fResult.get(nchars);
71
				if (list == null) {
72
					list= new ArrayList<PDOMBinding>();
73
					fResult.put(nchars, list);
74
				}
75
				list.add(binding);
76
				try {
77
					if (binding instanceof ICompositeType && ((ICompositeType) binding).isAnonymous()) {
78
						return true; // visit children
79
					}
80
				} catch (DOMException e) {
81
				}
82
			}
83
			return false;
84
		}
85
86
		public void leave(IPDOMNode node){}
87
	}
88
59
	private static final IndexFilter CONVERSION_FILTER = new DeclaredBindingsFilter(ILinkage.CPP_LINKAGE_ID, true, false) {
89
	private static final IndexFilter CONVERSION_FILTER = new DeclaredBindingsFilter(ILinkage.CPP_LINKAGE_ID, true, false) {
60
		@Override
90
		@Override
61
		public boolean acceptBinding(IBinding binding) throws CoreException {
91
		public boolean acceptBinding(IBinding binding) throws CoreException {
Lines 186-191 Link Here
186
		}
216
		}
187
	}
217
	}
188
218
219
	public static void updateCache(IPDOMCPPClassType ct, PDOMNode member) throws CoreException {
220
		if (member instanceof PDOMBinding) {
221
			final Long key= ct.getRecord() + PDOMCPPLinkage.CACHE_MEMBERS;
222
			final PDOM pdom = ct.getPDOM();
223
			@SuppressWarnings("unchecked")
224
			Reference<CharArrayMap<List<PDOMBinding>>> cached= (Reference<CharArrayMap<List<PDOMBinding>>>) pdom.getCachedResult(key);
225
			CharArrayMap<List<PDOMBinding>> map= cached == null ? null : cached.get();
226
			if (map != null) {
227
				new PopulateMap(map).visit(member);
228
			}
229
		}
230
	}
231
189
	public static CharArrayMap<List<PDOMBinding>> getBindingMap(IPDOMCPPClassType ct) throws CoreException {
232
	public static CharArrayMap<List<PDOMBinding>> getBindingMap(IPDOMCPPClassType ct) throws CoreException {
190
		final Long key= ct.getRecord() + PDOMCPPLinkage.CACHE_MEMBERS;
233
		final Long key= ct.getRecord() + PDOMCPPLinkage.CACHE_MEMBERS;
191
		final PDOM pdom = ct.getPDOM();
234
		final PDOM pdom = ct.getPDOM();
Lines 195-228 Link Here
195
		
238
		
196
		if (map == null) {
239
		if (map == null) {
197
			// there is no cache, build it:
240
			// there is no cache, build it:
198
			final CharArrayMap<List<PDOMBinding>> result= new CharArrayMap<List<PDOMBinding>>();
241
			map= new CharArrayMap<List<PDOMBinding>>();
199
			IPDOMVisitor visitor= new IPDOMVisitor() {
242
			IPDOMVisitor visitor= new PopulateMap(map);
200
				public boolean visit(IPDOMNode node) throws CoreException {
201
					if (node instanceof PDOMBinding) {
202
						final PDOMBinding binding= (PDOMBinding) node;
203
						final char[] nchars = binding.getNameCharArray();
204
						List<PDOMBinding> list= result.get(nchars);
205
						if (list == null) {
206
							list= new ArrayList<PDOMBinding>();
207
							result.put(nchars, list);
208
						}
209
						list.add(binding);
210
211
						try {
212
							if (binding instanceof ICompositeType && ((ICompositeType) binding).isAnonymous()) {
213
								return true; // visit children
214
							}
215
						} catch (DOMException e) {
216
						}
217
					}
218
					return false;
219
				}
220
				public void leave(IPDOMNode node){}
221
			};
222
			
223
			visitor.visit(ct);
243
			visitor.visit(ct);
224
			ct.acceptUncached(visitor);
244
			ct.acceptUncached(visitor);
225
			map= result;
226
			pdom.putCachedResult(key, new SoftReference<CharArrayMap<?>>(map));
245
			pdom.putCachedResult(key, new SoftReference<CharArrayMap<?>>(map));
227
		}
246
		}
228
		return map;
247
		return map;

Return to bug 287907