Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0210e1d34c996f2a65a97dffabf80720d19cd3f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Copyright (c) 2013 QNX Software Systems and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.eclipse.cdt.internal.qt.core.pdom;

import org.eclipse.cdt.internal.core.index.IIndexBindingConstants;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;

@SuppressWarnings("restriction")
public enum QtPDOMNodeType {

	QObject,
	QEnum,
	QProperty,
	QMethod,
	QGadget;

	public final int Type = IIndexBindingConstants.LAST_CONSTANT + 1 + ordinal();

	/**
	 * The current version of the QtPDOMLinkage.  This can be used to make sure the persisted
	 * data matches what is expected by the implementation.  Care should be taken to make changes
	 * backward compatible when possible.
	 * <p>
	 * The version is needed because ordinals for these enumerators are written to the file.
	 * <p>
	 * This version can be reset when the PDOM's version changes because older Qt linkages will
	 * be dropped (along with everything else in that PDOM).
	 */
	public static final int VERSION = 1;

	public static QtPDOMNodeType forType(int version, int type) {
		// Nothing has been deleted or replaced yet, so the version is ignored.

		for(QtPDOMNodeType node : values())
			if (node.Type == type)
				return node;
		return null;
	}

	// This needs to return PDOMNode so that it can be either QtPDOMNode or QtPDOMBinding.
	public static PDOMNode load(QtPDOMLinkage linkage, int nodeType, long record) throws CoreException {
		QtPDOMNodeType node = QtPDOMNodeType.forType(linkage.getVersion(), nodeType);
		if (node == null)
			return null;

		switch(node) {
		case QObject:
			return new QtPDOMQObject(linkage, record);
		case QEnum:
			return new QtPDOMQEnum(linkage, record);
		case QProperty:
			return new QtPDOMProperty(linkage, record);
		case QMethod:
			return new QtPDOMQMethod(linkage, record);
		case QGadget:
			return new QtPDOMQGadget(linkage, record);
		}

		return null;
	}
}

Back to the top