Skip to main content
summaryrefslogtreecommitdiffstats
path: root/qt
diff options
context:
space:
mode:
authorAndrew Eidsness2014-01-10 14:11:14 -0500
committerDoug Schaefer2014-01-13 10:54:42 -0500
commit6873bc90019a3dfbdd0df3e520e38293e3ecf165 (patch)
treeb35d8fcc156fe7bb497787cf07e7d1a9495d9cd8 /qt
parent5927d7ea309ea73c16ab953b298a67e44a50f4d2 (diff)
downloadorg.eclipse.cdt-6873bc90019a3dfbdd0df3e520e38293e3ecf165.tar.gz
org.eclipse.cdt-6873bc90019a3dfbdd0df3e520e38293e3ecf165.tar.xz
org.eclipse.cdt-6873bc90019a3dfbdd0df3e520e38293e3ecf165.zip
Bug 422841 QtIndex accessor for QmlRegistrations of an IQObject
This adds an API method to IQObject that will return the list of QML registrations for that type. I've also renamed the previous "QmlRegistered" to "QmlRegistration" because it makes more sense. The main part of this patch is a change to the QtPDOMLinkage. It now maintains an index of the registrations that are keyed by type. The index is a BTree that uses the QObject name as the key and a list of QML registration PDOMNames as the value. The list is created in the linkage's onCreate callback. Old names are removed in the list's onDelete callback. This includes a test case for this scenario and also updates the previous tests to match the new naming. Change-Id: I4b994a51958c848b4e2a3209165e6e6866e22270 Signed-off-by: Andrew Eidsness <eclipse@jfront.com> Reviewed-on: https://git.eclipse.org/r/20527 Tested-by: Hudson CI Reviewed-by: Doug Schaefer <dschaefer@qnx.com> IP-Clean: Doug Schaefer <dschaefer@qnx.com>
Diffstat (limited to 'qt')
-rw-r--r--qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QObject.java12
-rw-r--r--qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QmlRegistration.java (renamed from qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QmlRegistered.java)39
-rw-r--r--qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QtIndexImpl.java18
-rw-r--r--qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QmlTypeRegistration.java10
-rw-r--r--qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMLinkage.java74
-rw-r--r--qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMNameIndex.java155
-rw-r--r--qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMNodeType.java4
-rw-r--r--qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMQmlRegistration.java18
-rw-r--r--qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMQmlUncreatable.java (renamed from qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMQmlUncreatableRegistration.java)6
-rw-r--r--qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/IQObject.java5
-rw-r--r--qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/IQmlRegistration.java (renamed from qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/IQmlRegistered.java)8
-rw-r--r--qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/QtIndex.java2
-rw-r--r--qt/org.eclipse.cdt.qt.tests/src/org/eclipse/cdt/qt/tests/AllQtTests.java2
-rw-r--r--qt/org.eclipse.cdt.qt.tests/src/org/eclipse/cdt/qt/tests/QmlRegisteredTests.java201
-rw-r--r--qt/org.eclipse.cdt.qt.tests/src/org/eclipse/cdt/qt/tests/QmlRegistrationTests.java263
15 files changed, 575 insertions, 242 deletions
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QObject.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QObject.java
index 9c958957ad..3ced0623db 100644
--- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QObject.java
+++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QObject.java
@@ -17,10 +17,12 @@ import org.eclipse.cdt.internal.qt.core.pdom.QtPDOMProperty;
import org.eclipse.cdt.internal.qt.core.pdom.QtPDOMQEnum;
import org.eclipse.cdt.internal.qt.core.pdom.QtPDOMQMethod;
import org.eclipse.cdt.internal.qt.core.pdom.QtPDOMQObject;
+import org.eclipse.cdt.internal.qt.core.pdom.QtPDOMQmlRegistration;
import org.eclipse.cdt.qt.core.index.IQEnum;
import org.eclipse.cdt.qt.core.index.IQMethod;
import org.eclipse.cdt.qt.core.index.IQObject;
import org.eclipse.cdt.qt.core.index.IQProperty;
+import org.eclipse.cdt.qt.core.index.IQmlRegistration;
import org.eclipse.core.runtime.CoreException;
public class QObject implements IQObject {
@@ -32,6 +34,7 @@ public class QObject implements IQObject {
private final IQObject.IMembers<IQMethod> signals;
private final IQObject.IMembers<IQMethod> invokables;
private final IQObject.IMembers<IQProperty> properties;
+ private final List<IQmlRegistration> qmlRegistrations;
private final List<IQEnum> enums;
private final Map<String, String> classInfos;
@@ -90,6 +93,10 @@ public class QObject implements IQObject {
props.add(qProp);
}
this.properties = QObjectMembers.create(props, baseProps);
+
+ this.qmlRegistrations = new ArrayList<IQmlRegistration>();
+ for(QtPDOMQmlRegistration pdom : QtPDOMQmlRegistration.findFor(pdomQObject))
+ this.qmlRegistrations.add(QmlRegistration.create(qtIndex, pdom));
}
@Override
@@ -128,6 +135,11 @@ public class QObject implements IQObject {
}
@Override
+ public Collection<IQmlRegistration> getQmlRegistrations() {
+ return qmlRegistrations;
+ }
+
+ @Override
public String getClassInfo(String key) {
String value = classInfos.get(key);
if (value != null)
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QmlRegistered.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QmlRegistration.java
index 46d3ac7983..674dc8c091 100644
--- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QmlRegistered.java
+++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QmlRegistration.java
@@ -9,15 +9,16 @@ package org.eclipse.cdt.internal.qt.core.index;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.internal.qt.core.pdom.QtPDOMQmlRegistration;
-import org.eclipse.cdt.internal.qt.core.pdom.QtPDOMQmlUncreatableRegistration;
+import org.eclipse.cdt.internal.qt.core.pdom.QtPDOMQmlUncreatable;
import org.eclipse.cdt.qt.core.index.IQObject;
-import org.eclipse.cdt.qt.core.index.IQmlRegistered;
+import org.eclipse.cdt.qt.core.index.IQObject.IMember;
+import org.eclipse.cdt.qt.core.index.IQmlRegistration;
import org.eclipse.core.runtime.CoreException;
-public class QmlRegistered implements IQmlRegistered {
+public class QmlRegistration implements IQmlRegistration {
private final QtIndexImpl qtIndex;
- private final IQmlRegistered.Kind kind;
+ private final IQmlRegistration.Kind kind;
private final String[] ownerName;
private final Long version;
private final String uri;
@@ -27,17 +28,17 @@ public class QmlRegistered implements IQmlRegistered {
private final String reason;
private IQObject qObject;
- public static QmlRegistered create(QtIndexImpl qtIndex, IBinding pdom) throws CoreException {
- if (pdom instanceof QtPDOMQmlUncreatableRegistration)
- return new QmlRegistered(qtIndex, (QtPDOMQmlUncreatableRegistration) pdom);
+ public static QmlRegistration create(QtIndexImpl qtIndex, IBinding pdom) throws CoreException {
+ if (pdom instanceof QtPDOMQmlUncreatable)
+ return new QmlRegistration(qtIndex, (QtPDOMQmlUncreatable) pdom);
if (pdom instanceof QtPDOMQmlRegistration)
- return new QmlRegistered(qtIndex, (QtPDOMQmlRegistration) pdom);
+ return new QmlRegistration(qtIndex, (QtPDOMQmlRegistration) pdom);
return null;
}
- private QmlRegistered(QtIndexImpl qtIndex, QtPDOMQmlRegistration pdom) throws CoreException {
+ private QmlRegistration(QtIndexImpl qtIndex, QtPDOMQmlRegistration pdom) throws CoreException {
this.qtIndex = qtIndex;
- this.kind = IQmlRegistered.Kind.Type;
+ this.kind = IQmlRegistration.Kind.Type;
String qobjName = pdom.getQObjectName();
this.ownerName = qobjName == null ? null : qobjName.split("::");
@@ -50,9 +51,9 @@ public class QmlRegistered implements IQmlRegistered {
this.reason = null;
}
- private QmlRegistered(QtIndexImpl qtIndex, QtPDOMQmlUncreatableRegistration pdom) throws CoreException {
+ private QmlRegistration(QtIndexImpl qtIndex, QtPDOMQmlUncreatable pdom) throws CoreException {
this.qtIndex = qtIndex;
- this.kind = IQmlRegistered.Kind.Uncreatable;
+ this.kind = IQmlRegistration.Kind.Uncreatable;
String qobjName = pdom.getQObjectName();
this.ownerName = qobjName == null ? null : qobjName.split("::");
@@ -66,7 +67,7 @@ public class QmlRegistered implements IQmlRegistered {
}
@Override
- public IQmlRegistered.Kind getKind() {
+ public IQmlRegistration.Kind getKind() {
return kind;
}
@@ -78,6 +79,18 @@ public class QmlRegistered implements IQmlRegistered {
return qObject;
}
+ // TODO remove getQObject from the API
+ @Override
+ public IQObject getOwner() {
+ return getQObject();
+ }
+
+ @Override
+ public boolean isOverride(IMember member) {
+ // TODO I think that qmlRegistrations are never overridden
+ return false;
+ }
+
@Override
public Long getVersion() {
return version;
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QtIndexImpl.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QtIndexImpl.java
index 326b1363de..605c7def83 100644
--- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QtIndexImpl.java
+++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/index/QtIndexImpl.java
@@ -23,7 +23,7 @@ import org.eclipse.cdt.internal.qt.core.pdom.QtPDOMQObject;
import org.eclipse.cdt.qt.core.QtKeywords;
import org.eclipse.cdt.qt.core.index.IQGadget;
import org.eclipse.cdt.qt.core.index.IQObject;
-import org.eclipse.cdt.qt.core.index.IQmlRegistered;
+import org.eclipse.cdt.qt.core.index.IQmlRegistration;
import org.eclipse.cdt.qt.core.index.QtIndex;
import org.eclipse.core.runtime.CoreException;
@@ -63,8 +63,8 @@ public class QtIndexImpl extends QtIndex {
}
@Override
- public Collection<IQmlRegistered> getQmlRegistered() {
- return cdtIndex.get(new QMLRegisteredAccessor());
+ public Collection<IQmlRegistration> getQmlRegistrations() {
+ return cdtIndex.get(new QmlRegistrationAccessor());
}
private class QObjectImplAccessor implements CDTIndex.Accessor<IQObject> {
@@ -110,21 +110,21 @@ public class QtIndexImpl extends QtIndex {
}
}
- private class QMLRegisteredAccessor implements CDTIndex.Accessor<Collection<IQmlRegistered>> {
+ private class QmlRegistrationAccessor implements CDTIndex.Accessor<Collection<IQmlRegistration>> {
@Override
- public Collection<IQmlRegistered> access(IIndex index) throws CoreException {
- Collection<IQmlRegistered> types = null;
+ public Collection<IQmlRegistration> access(IIndex index) throws CoreException {
+ Collection<IQmlRegistration> types = null;
for(IIndexBinding binding : index.findBindings(QmlTypeNameRegex, false, QtLinkageFilter, null)) {
- IQmlRegistered qml = QmlRegistered.create(QtIndexImpl.this, binding);
+ IQmlRegistration qml = QmlRegistration.create(QtIndexImpl.this, binding);
if (qml != null) {
if (types == null)
- types = new ArrayList<IQmlRegistered>();
+ types = new ArrayList<IQmlRegistration>();
types.add(qml);
}
}
- return types == null ? Collections.<IQmlRegistered>emptyList() : types;
+ return types == null ? Collections.<IQmlRegistration>emptyList() : types;
}
}
}
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QmlTypeRegistration.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QmlTypeRegistration.java
index 86358c532d..a7cfd0f647 100644
--- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QmlTypeRegistration.java
+++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QmlTypeRegistration.java
@@ -19,14 +19,14 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.internal.qt.core.ASTUtil;
import org.eclipse.cdt.qt.core.QtKeywords;
-import org.eclipse.cdt.qt.core.index.IQmlRegistered;
+import org.eclipse.cdt.qt.core.index.IQmlRegistration;
import org.eclipse.core.runtime.CoreException;
public class QmlTypeRegistration extends ASTDelegatedName implements IQtASTName {
private final ICPPTemplateInstance functionInstanceBinding;
private final IASTFunctionCallExpression fnCall;
- private final IQmlRegistered.Kind kind;
+ private final IQmlRegistration.Kind kind;
private char[] simpleID;
public QmlTypeRegistration(IASTName ast, ICPPTemplateInstance functionInstanceBinding, IASTFunctionCallExpression fnCall) {
@@ -35,9 +35,9 @@ public class QmlTypeRegistration extends ASTDelegatedName implements IQtASTName
this.fnCall = fnCall;
if (QtKeywords.QML_REGISTER_UNCREATABLE_TYPE.equals(functionInstanceBinding.getName()))
- this.kind = IQmlRegistered.Kind.Uncreatable;
+ this.kind = IQmlRegistration.Kind.Uncreatable;
else
- this.kind = IQmlRegistered.Kind.Type;
+ this.kind = IQmlRegistration.Kind.Type;
}
@Override
@@ -63,7 +63,7 @@ public class QmlTypeRegistration extends ASTDelegatedName implements IQtASTName
case Type:
return new QtPDOMQmlRegistration(linkage, this, delegate);
case Uncreatable:
- return new QtPDOMQmlUncreatableRegistration(linkage, this, delegate);
+ return new QtPDOMQmlUncreatable(linkage, this, delegate);
}
return null;
}
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMLinkage.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMLinkage.java
index ccf88398c7..bf438eb328 100644
--- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMLinkage.java
+++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMLinkage.java
@@ -7,6 +7,9 @@
*/
package org.eclipse.cdt.internal.qt.core.pdom;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -22,7 +25,9 @@ import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
import org.eclipse.cdt.internal.core.pdom.dom.FindBinding;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
+import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
+import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.qt.core.QtPlugin;
import org.eclipse.core.runtime.CoreException;
@@ -32,13 +37,16 @@ public class QtPDOMLinkage extends PDOMLinkage {
private static int offsetInitializer = PDOMLinkage.RECORD_SIZE;
private static enum Field {
- Version(Database.INT_SIZE),
- Last(0);
+ Version(Database.INT_SIZE, 0),
+ QmlRegistrationIndex(Database.PTR_SIZE, 3),
+ Last(0, 0);
private final int offset;
+ public final int version;
- private Field(int sizeof) {
+ private Field(int sizeof, int version) {
this.offset = offsetInitializer;
+ this.version = version;
offsetInitializer += sizeof;
}
@@ -64,6 +72,15 @@ public class QtPDOMLinkage extends PDOMLinkage {
// Initialize the version with whatever is current.
version = QtPDOMNodeType.VERSION;
pdom.getDB().putInt(Field.Version.getRecord(record), version);
+
+ // Initialize all BTree's to 0.
+ if (version >= Field.QmlRegistrationIndex.version)
+ pdom.getDB().putRecPtr(Field.QmlRegistrationIndex.getRecord(record), 0);
+ }
+
+ @Override
+ protected int getRecordSize() {
+ return Field.Last.offset;
}
public int getVersion() {
@@ -195,6 +212,57 @@ public class QtPDOMLinkage extends PDOMLinkage {
}
@Override
+ public void onCreateName(PDOMFile file, IASTName name, PDOMName pdomName) throws CoreException {
+ super.onCreateName(file, name, pdomName);
+
+ // If the new name was created for a QmlRegistration, then put it into the index.
+ if (name instanceof QmlTypeRegistration) {
+ String qobjName = ((QmlTypeRegistration) name).getQObjectName();
+ QtPDOMNameIndex index = getQmlRegistrationIndex();
+ if (index != null)
+ index.add(qobjName, pdomName);
+ }
+ }
+
+ @Override
+ public void onDeleteName(PDOMName name) throws CoreException {
+ // If this is a name for a QML registration, then the registration must be removed
+ // from the index.
+ PDOMBinding binding = name.getBinding();
+ if (binding instanceof QtPDOMQmlRegistration) {
+ QtPDOMNameIndex index = getQmlRegistrationIndex();
+ if (index != null)
+ index.remove(((QtPDOMQmlRegistration) binding).getQObjectName(), name);
+ }
+
+ super.onDeleteName(name);
+ }
+
+ public Collection<QtPDOMQmlRegistration> getQmlRegistrations(String qobjName) throws CoreException {
+ QtPDOMNameIndex index = getQmlRegistrationIndex();
+ if (index == null)
+ return Collections.emptyList();
+
+ Collection<PDOMName> names = index.get(qobjName);
+ if (names.isEmpty())
+ return Collections.emptyList();
+
+ ArrayList<QtPDOMQmlRegistration> registrations = new ArrayList<QtPDOMQmlRegistration>();
+ for (PDOMName name : names) {
+ PDOMBinding binding = name.getBinding();
+ if (binding instanceof QtPDOMQmlRegistration)
+ registrations.add((QtPDOMQmlRegistration) binding);
+ }
+ return registrations;
+ }
+
+ private QtPDOMNameIndex getQmlRegistrationIndex() throws CoreException {
+ return version >= Field.QmlRegistrationIndex.version
+ ? new QtPDOMNameIndex(this, Field.QmlRegistrationIndex.getRecord(record))
+ : null;
+ }
+
+ @Override
public int getBindingType(IBinding binding) {
return binding instanceof QtPDOMBinding ? ((QtPDOMBinding) binding).getNodeType() : 0;
}
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMNameIndex.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMNameIndex.java
new file mode 100644
index 0000000000..2f37216084
--- /dev/null
+++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMNameIndex.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2014 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 java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.cdt.internal.core.pdom.db.BTree;
+import org.eclipse.cdt.internal.core.pdom.db.Database;
+import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
+import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
+import org.eclipse.cdt.internal.core.pdom.db.IString;
+import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * A data structure for storing lists of PDOMNames that are indexed by a String key.
+ * This is equivalent to the java type Map<String, List<PDOMName>>.
+ */
+@SuppressWarnings("restriction")
+public class QtPDOMNameIndex {
+ private final QtPDOMLinkage qtLinkage;
+ private final Database db;
+ private final BTree btree;
+
+ // Entries in the index look like:
+ // struct Entry {
+ // record key;
+ // record head;
+ // };
+ //
+ // Elements in the list for each entry look like:
+ // struct ListNode {
+ // record pdomName;
+ // record next;
+ // };
+
+ public QtPDOMNameIndex(QtPDOMLinkage qtLinkage, long ptr) throws CoreException {
+ this.qtLinkage = qtLinkage;
+ this.db = qtLinkage.getDB();
+ this.btree = new BTree(db, ptr, new StringKeyComparator());
+ }
+
+ public Collection<PDOMName> get(String key) throws CoreException {
+ Finder finder = new Finder(key);
+ btree.accept(finder);
+ if (finder.headRec == 0)
+ return Collections.emptyList();
+
+ List<PDOMName> names = new ArrayList<PDOMName>();
+ for(long node = db.getRecPtr(finder.headRec); node != 0; node = db.getRecPtr(node + Database.PTR_SIZE))
+ names.add(new PDOMName(qtLinkage, db.getRecPtr(node)));
+ return names;
+ }
+
+ public void add(String key, PDOMName name) throws CoreException {
+
+ IString dbKey = db.newString(key);
+
+ // Construct a temporary entry and try to insert it into the tree.
+ long tmpEntry = db.malloc(2 * Database.PTR_SIZE);
+ db.putRecPtr(tmpEntry, dbKey.getRecord());
+ long entry = btree.insert(tmpEntry);
+
+ // If the new entry was inserted into the tree, then we need to allocate new
+ // memory for the list node. If the tree already had an entry for this key, then
+ // we need to release the string that was provisionally allocated as the key, but
+ // can reuse the memory for the list node.
+ long node = 0;
+ if (entry == tmpEntry)
+ node = db.malloc(Database.PTR_SIZE);
+ else {
+ dbKey.delete();
+ node = tmpEntry;
+ }
+
+ // The registration can now be put into the new list node.
+ db.putRecPtr(node, name.getRecord());
+
+ // Finally, the new list node should be inserted before the current head.
+ long head = db.getRecPtr(entry + Database.PTR_SIZE);
+ db.putRecPtr(node + Database.PTR_SIZE, head);
+ db.putRecPtr(entry + Database.PTR_SIZE, node);
+ }
+
+ public void remove(String key, PDOMName name) throws CoreException {
+ Finder finder = new Finder(key);
+ btree.accept(finder);
+ if (finder.headRec == 0)
+ return;
+
+ long qmlRec = name.getRecord();
+
+ // Walk the list to find this record. If found then update the previous node to
+ // point to the one after node.
+ long prev = finder.headRec;
+ for(long node = db.getRecPtr(prev); node != 0; node = db.getRecPtr(prev)) {
+ long rec = db.getRecPtr(node);
+ if (rec == qmlRec) {
+ long next = db.getRecPtr(node + Database.PTR_SIZE);
+ db.putRecPtr(prev, next);
+ db.free(node);
+ break;
+ }
+
+ prev = node + Database.PTR_SIZE;
+ }
+
+ // The lifetime of the binding is managed elsewhere so don't delete it here. We
+ // are just maintaining the consistency of this index.
+ }
+
+ private class StringKeyComparator implements IBTreeComparator {
+ @Override
+ public int compare(long record1, long record2) throws CoreException {
+ long lhsRec = db.getRecPtr(record1);
+ long rhsRec = db.getRecPtr(record2);
+
+ IString lhs = lhsRec == 0 ? null : db.getString(lhsRec);
+ IString rhs = rhsRec == 0 ? null : db.getString(rhsRec);
+
+ if (lhs == null)
+ return rhs == null ? 0 : -1;
+ return rhs == null ? 1 : lhs.compare(rhs, true);
+ }
+ }
+
+ private class Finder implements IBTreeVisitor {
+ private final String key;
+ public Long headRec = 0L;
+
+ public Finder(String key) {
+ this.key = key;
+ }
+
+ @Override
+ public int compare(long rhsRecord) throws CoreException {
+ long keyRec = db.getRecPtr(rhsRecord);
+ return keyRec == 0 ? 1 : db.getString(keyRec).compare(key, true);
+ }
+
+ @Override
+ public boolean visit(long record) throws CoreException {
+ headRec = record + Database.PTR_SIZE;
+ return false;
+ }
+ }
+}
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMNodeType.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMNodeType.java
index 52f468f4f4..64d8d25f45 100644
--- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMNodeType.java
+++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMNodeType.java
@@ -34,7 +34,7 @@ public enum QtPDOMNodeType {
* 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 = 2;
+ public static final int VERSION = 3;
public static QtPDOMNodeType forType(int version, int type) {
// Nothing has been deleted or replaced yet, so the version is ignored.
@@ -65,7 +65,7 @@ public enum QtPDOMNodeType {
case QmlTypeRegistration:
return new QtPDOMQmlRegistration(linkage, record);
case QmlUncreatableRegistration:
- return new QtPDOMQmlUncreatableRegistration(linkage, record);
+ return new QtPDOMQmlUncreatable(linkage, record);
}
return null;
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMQmlRegistration.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMQmlRegistration.java
index fb4db6d124..56632b4a81 100644
--- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMQmlRegistration.java
+++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMQmlRegistration.java
@@ -7,8 +7,12 @@
*/
package org.eclipse.cdt.internal.qt.core.pdom;
+import java.util.Collection;
+import java.util.Collections;
+
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.internal.core.pdom.db.Database;
+import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.core.runtime.CoreException;
@SuppressWarnings("restriction")
@@ -48,6 +52,20 @@ public class QtPDOMQmlRegistration extends QtPDOMBinding {
putStringOrNull(Field.QmlName.offset, qmlTypeReg.getQmlName());
}
+ public static Collection<QtPDOMQmlRegistration> findFor(QtPDOMQObject qobj) throws CoreException {
+ PDOMLinkage linkage = qobj.getLinkage();
+ if (linkage == null
+ || !(linkage instanceof QtPDOMLinkage))
+ return Collections.emptyList();
+
+ String name = qobj.getName();
+ if (name == null)
+ return Collections.emptyList();
+
+ QtPDOMLinkage qtLinkage = (QtPDOMLinkage) linkage;
+ return qtLinkage.getQmlRegistrations(qobj.getName());
+ }
+
@Override
protected int getRecordSize() {
return Field.Last.offset;
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMQmlUncreatableRegistration.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMQmlUncreatable.java
index 4f06883266..7d35e12a1e 100644
--- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMQmlUncreatableRegistration.java
+++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/pdom/QtPDOMQmlUncreatable.java
@@ -12,7 +12,7 @@ import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.core.runtime.CoreException;
@SuppressWarnings("restriction")
-public class QtPDOMQmlUncreatableRegistration extends QtPDOMQmlRegistration {
+public class QtPDOMQmlUncreatable extends QtPDOMQmlRegistration {
private static int offsetInitializer = QtPDOMQmlRegistration.Field.Last.offset;
protected static enum Field {
@@ -27,11 +27,11 @@ public class QtPDOMQmlUncreatableRegistration extends QtPDOMQmlRegistration {
}
}
- public QtPDOMQmlUncreatableRegistration(QtPDOMLinkage linkage, long record) {
+ public QtPDOMQmlUncreatable(QtPDOMLinkage linkage, long record) {
super(linkage, record);
}
- public QtPDOMQmlUncreatableRegistration(QtPDOMLinkage linkage, QmlTypeRegistration qmlTypeReg, IASTName cppName) throws CoreException {
+ public QtPDOMQmlUncreatable(QtPDOMLinkage linkage, QmlTypeRegistration qmlTypeReg, IASTName cppName) throws CoreException {
super(linkage, qmlTypeReg, cppName);
putStringOrNull(Field.Reason.offset, qmlTypeReg.getReason());
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/IQObject.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/IQObject.java
index 53ad1e9edb..26fd590c77 100644
--- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/IQObject.java
+++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/IQObject.java
@@ -107,6 +107,11 @@ public interface IQObject extends IQElement {
public IMembers<IQProperty> getProperties();
/**
+ * Returns the methods that have been tagged with Q_INVOKABLE. Does not return null.
+ */
+ public Collection<IQmlRegistration> getQmlRegistrations();
+
+ /**
* Examines the Q_CLASSINFO expansions to return the value associated with the given
* key. Returns null if there isn't a Q_CLASSINFO for the given key.
*/
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/IQmlRegistered.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/IQmlRegistration.java
index 23353ea82a..b3ff7520fa 100644
--- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/IQmlRegistered.java
+++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/IQmlRegistration.java
@@ -19,13 +19,13 @@ package org.eclipse.cdt.qt.core.index;
* Registers Q in the QML system with the name "Q", in the library imported from "uri"
* having the version number 1.0.
*/
-public interface IQmlRegistered {
+public interface IQmlRegistration extends IQObject.IMember {
/**
* Identifies the kind of qmlRegister* function that was used to register the
* type. Qt 4.8 only defines two kinds, but in 5.0 there several more.
* <p>
* If a type has been registered more than once, then there will be several
- * entries for it in the collection returned by {@link QtIndex#getQmlRegistered()}.
+ * entries for it in the collection returned by {@link QtIndex#getQmlRegistrations()}.
*/
public enum Kind {
/**
@@ -49,10 +49,10 @@ public interface IQmlRegistered {
* It is possible for the same type to be registered in different ways, although
* this generally indicates a problem in the client code.
*/
- public IQmlRegistered.Kind getKind();
+ public IQmlRegistration.Kind getKind();
/**
- * Returns QObject to which this registration applies. In the sample at {@link IQmlRegistered}
+ * Returns QObject to which this registration applies. In the sample at {@link IQmlRegistration}
* this would return the IQObject for Q.
*/
public IQObject getQObject();
diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/QtIndex.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/QtIndex.java
index c8636146d1..996b2adc25 100644
--- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/QtIndex.java
+++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/index/QtIndex.java
@@ -80,5 +80,5 @@ public abstract class QtIndex {
* qmlRegisterType<Q>( "uri", 1, 2, "Qv1.2" );
* </pre>
*/
- public abstract Collection<IQmlRegistered> getQmlRegistered();
+ public abstract Collection<IQmlRegistration> getQmlRegistrations();
}
diff --git a/qt/org.eclipse.cdt.qt.tests/src/org/eclipse/cdt/qt/tests/AllQtTests.java b/qt/org.eclipse.cdt.qt.tests/src/org/eclipse/cdt/qt/tests/AllQtTests.java
index 4282134d05..dc3ff0d447 100644
--- a/qt/org.eclipse.cdt.qt.tests/src/org/eclipse/cdt/qt/tests/AllQtTests.java
+++ b/qt/org.eclipse.cdt.qt.tests/src/org/eclipse/cdt/qt/tests/AllQtTests.java
@@ -22,6 +22,6 @@ public class AllQtTests extends TestSuite {
QtContentAssistantTests.class,
QtIndexTests.class,
QtRegressionTests.class,
- QmlRegisteredTests.class);
+ QmlRegistrationTests.class);
}
}
diff --git a/qt/org.eclipse.cdt.qt.tests/src/org/eclipse/cdt/qt/tests/QmlRegisteredTests.java b/qt/org.eclipse.cdt.qt.tests/src/org/eclipse/cdt/qt/tests/QmlRegisteredTests.java
deleted file mode 100644
index b7e85d9fd5..0000000000
--- a/qt/org.eclipse.cdt.qt.tests/src/org/eclipse/cdt/qt/tests/QmlRegisteredTests.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Copyright (c) 2014 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.qt.tests;
-
-import java.util.Collection;
-
-import org.eclipse.cdt.qt.core.index.IQObject;
-import org.eclipse.cdt.qt.core.index.IQmlRegistered;
-import org.eclipse.cdt.qt.core.index.QtIndex;
-
-public class QmlRegisteredTests extends BaseQtTestCase {
-
- // #include "junit-QObject.hh"
- // class B : public QObject
- // {
- // Q_OBJECT
- // };
- //
- // class D : public B
- // {
- // Q_OBJECT
- // };
- //
- // static void func()
- // {
- // qmlRegisterType<B>( "b-uri", 1, 2, "B" );
- // qmlRegisterType<B>( "b-uri.34", 3, 4, "B34" );
- //
- // const char * uri = "d-uri";
- // int maj = 2, min = 3;
- // const char * qmlName = "D1";
- // qmlRegisterType<D, 1>( uri, maj, min, qmlName );
- // }
- public void testQMLRegisterType() throws Exception {
- loadComment("qmlregistertype.hh");
-
- QtIndex qtIndex = QtIndex.getIndex(fProject);
- assertNotNull(qtIndex);
-
- IQObject b_qobj = qtIndex.findQObject(new String[]{ "B" });
- if (!isIndexOk("B", b_qobj))
- return;
- assertNotNull(b_qobj);
-
- Collection<IQmlRegistered> qmlRegistereds = qtIndex.getQmlRegistered();
- assertNotNull(qmlRegistereds);
- assertEquals(3, qmlRegistereds.size());
-
- for(IQmlRegistered qmlRegistered : qmlRegistereds) {
- IQObject qobj = qmlRegistered.getQObject();
- assertNotNull(qobj);
-
- // all values of B should be fully resolved, except for Revision, which was not provided
- if (qobj.getName().equals("B")) {
- assertNull(qmlRegistered.getVersion());
- String qmlName = qmlRegistered.getQmlName();
- assertNotNull(qmlName);
- if ("B".equals(qmlName)) {
- assertEquals(IQmlRegistered.Kind.Type, qmlRegistered.getKind());
- assertEquals("b-uri", qmlRegistered.getURI());
- assertEquals(Long.valueOf(1), qmlRegistered.getMajor());
- assertEquals(Long.valueOf(2), qmlRegistered.getMinor());
- assertNull(qmlRegistered.getReason());
- } else if ("B34".equals(qmlName)) {
- assertEquals(IQmlRegistered.Kind.Type, qmlRegistered.getKind());
- assertEquals("b-uri.34", qmlRegistered.getURI());
- assertEquals(Long.valueOf(3), qmlRegistered.getMajor());
- assertEquals(Long.valueOf(4), qmlRegistered.getMinor());
- assertNull(qmlRegistered.getReason());
- } else {
- fail("unexpected uri for B " + qmlName);
- }
-
- // the values for D are not expected to be resolved (yet), but it does have a Revision
- } else if (qobj.getName().equals("D")) {
- assertEquals(IQmlRegistered.Kind.Type, qmlRegistered.getKind());
- assertEquals(Long.valueOf(1), qmlRegistered.getVersion());
- assertNull(qmlRegistered.getURI());
- assertNull(qmlRegistered.getMajor());
- assertNull(qmlRegistered.getMinor());
- assertNull(qmlRegistered.getQmlName());
- assertNull(qmlRegistered.getReason());
-
- } else {
- fail("unexpected qmlRegistered " + qobj.getName());
- }
- }
- }
-
- // class T;
- //
- // static void func()
- // {
- // qmlRegisterType<T>( "t-uri", 3, 4, "qml-T" );
- // }
- public void testQMLRegisterFwdDecl() throws Exception {
- loadComment("qmlregistertype.hh");
-
- QtIndex qtIndex = QtIndex.getIndex(fProject);
- assertNotNull(qtIndex);
-
- Collection<IQmlRegistered> qmlRegistereds = qtIndex.getQmlRegistered();
- assertNotNull(qmlRegistereds);
- assertEquals(1, qmlRegistereds.size());
-
- IQmlRegistered qml = qmlRegistereds.iterator().next();
- assertNotNull(qml);
- assertEquals(IQmlRegistered.Kind.Type, qml.getKind());
- assertEquals("t-uri", qml.getURI());
- assertEquals(Long.valueOf(3), qml.getMajor());
- assertEquals(Long.valueOf(4), qml.getMinor());
- assertEquals("qml-T", qml.getQmlName());
- assertNull(qml.getReason());
-
- // The QObject has not been defined, so it cannot be found.
- assertNull(qml.getQObject());
- }
-
- // #include "junit-QObject.hh"
- // class B : public QObject
- // {
- // Q_OBJECT
- // };
- //
- // class D : public B
- // {
- // Q_OBJECT
- // };
- //
- // static void func()
- // {
- // qmlRegisterUncreatableType<B>( "b-uri", 1, 2, "B", QString( "msg1" ) );
- // qmlRegisterUncreatableType<B>( "b-uri.34", 3, 4, "B34", QString( "msg2" ) );
- //
- // const char * uri = "d-uri";
- // int maj = 2, min = 3;
- // const char * qmlName = "D1";
- // const QString msg( "msg3" );
- // qmlRegisterUncreatableType<D>( uri, maj, min, qmlName, msg );
- // }
- public void testQMLRegisterUncreatableType() throws Exception {
- loadComment("qmlregistereduncreatabletype.hh");
-
- QtIndex qtIndex = QtIndex.getIndex(fProject);
- assertNotNull(qtIndex);
-
- IQObject b_qobj = qtIndex.findQObject(new String[]{ "B" });
- if (!isIndexOk("B", b_qobj))
- return;
- assertNotNull(b_qobj);
-
- Collection<IQmlRegistered> qmlRegistereds = qtIndex.getQmlRegistered();
- assertNotNull(qmlRegistereds);
- assertEquals(3, qmlRegistereds.size());
-
- for(IQmlRegistered qmlRegistered : qmlRegistereds) {
- IQObject qobj = qmlRegistered.getQObject();
- assertNotNull(qobj);
-
- // all values of B should be fully resolved, except for Revision, which was not provided
- if (qobj.getName().equals("B")) {
- assertNull(qmlRegistered.getVersion());
- String qmlName = qmlRegistered.getQmlName();
- assertNotNull(qmlName);
- if ("B".equals(qmlName)) {
- assertEquals(IQmlRegistered.Kind.Uncreatable, qmlRegistered.getKind());
- assertEquals("b-uri", qmlRegistered.getURI());
- assertEquals(Long.valueOf(1), qmlRegistered.getMajor());
- assertEquals(Long.valueOf(2), qmlRegistered.getMinor());
- assertEquals(null/*"msg1"*/, qmlRegistered.getReason());
- } else if ("B34".equals(qmlName)) {
- assertEquals(IQmlRegistered.Kind.Uncreatable, qmlRegistered.getKind());
- assertEquals("b-uri.34", qmlRegistered.getURI());
- assertEquals(Long.valueOf(3), qmlRegistered.getMajor());
- assertEquals(Long.valueOf(4), qmlRegistered.getMinor());
- assertEquals(null/*"msg2"*/, qmlRegistered.getReason());
- } else {
- fail("unexpected uri for B " + qmlName);
- }
-
- // the values for D are not expected to be resolved (yet), but it does have a Revision
- } else if (qobj.getName().equals("D")) {
- assertEquals(IQmlRegistered.Kind.Uncreatable, qmlRegistered.getKind());
- assertNull(qmlRegistered.getVersion());
- assertNull(qmlRegistered.getURI());
- assertNull(qmlRegistered.getMajor());
- assertNull(qmlRegistered.getMinor());
- assertNull(qmlRegistered.getQmlName());
- assertNull(qmlRegistered.getReason());
-
- } else {
- fail("unexpected qmlRegistered " + qobj.getName());
- }
- }
- }
-}
diff --git a/qt/org.eclipse.cdt.qt.tests/src/org/eclipse/cdt/qt/tests/QmlRegistrationTests.java b/qt/org.eclipse.cdt.qt.tests/src/org/eclipse/cdt/qt/tests/QmlRegistrationTests.java
new file mode 100644
index 0000000000..f75212ff78
--- /dev/null
+++ b/qt/org.eclipse.cdt.qt.tests/src/org/eclipse/cdt/qt/tests/QmlRegistrationTests.java
@@ -0,0 +1,263 @@
+/*
+ * Copyright (c) 2014 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.qt.tests;
+
+import java.util.Collection;
+
+import org.eclipse.cdt.qt.core.index.IQObject;
+import org.eclipse.cdt.qt.core.index.IQmlRegistration;
+import org.eclipse.cdt.qt.core.index.QtIndex;
+
+public class QmlRegistrationTests extends BaseQtTestCase {
+
+ // #include "junit-QObject.hh"
+ // class B : public QObject
+ // {
+ // Q_OBJECT
+ // };
+ //
+ // class D : public B
+ // {
+ // Q_OBJECT
+ // };
+ //
+ // static void func()
+ // {
+ // qmlRegisterType<B>( "b-uri", 1, 2, "B" );
+ // qmlRegisterType<B>( "b-uri.34", 3, 4, "B34" );
+ //
+ // const char * uri = "d-uri";
+ // int maj = 2, min = 3;
+ // const char * qmlName = "D1";
+ // qmlRegisterType<D, 1>( uri, maj, min, qmlName );
+ // }
+ public void testQmlRegisterType() throws Exception {
+ loadComment("qmlregistertype.hh");
+
+ QtIndex qtIndex = QtIndex.getIndex(fProject);
+ assertNotNull(qtIndex);
+
+ IQObject b_qobj = qtIndex.findQObject(new String[]{ "B" });
+ if (!isIndexOk("B", b_qobj))
+ return;
+ assertNotNull(b_qobj);
+
+ Collection<IQmlRegistration> qmlRegistrations = qtIndex.getQmlRegistrations();
+ assertNotNull(qmlRegistrations);
+ assertEquals(3, qmlRegistrations.size());
+
+ for(IQmlRegistration qmlRegistration : qmlRegistrations) {
+ IQObject qobj = qmlRegistration.getQObject();
+ assertNotNull(qobj);
+
+ // all values of B should be fully resolved, except for Revision, which was not provided
+ if (qobj.getName().equals("B")) {
+ assertNull(qmlRegistration.getVersion());
+ String qmlName = qmlRegistration.getQmlName();
+ assertNotNull(qmlName);
+ if ("B".equals(qmlName)) {
+ assertEquals(IQmlRegistration.Kind.Type, qmlRegistration.getKind());
+ assertEquals("b-uri", qmlRegistration.getURI());
+ assertEquals(Long.valueOf(1), qmlRegistration.getMajor());
+ assertEquals(Long.valueOf(2), qmlRegistration.getMinor());
+ assertNull(qmlRegistration.getReason());
+ } else if ("B34".equals(qmlName)) {
+ assertEquals(IQmlRegistration.Kind.Type, qmlRegistration.getKind());
+ assertEquals("b-uri.34", qmlRegistration.getURI());
+ assertEquals(Long.valueOf(3), qmlRegistration.getMajor());
+ assertEquals(Long.valueOf(4), qmlRegistration.getMinor());
+ assertNull(qmlRegistration.getReason());
+ } else {
+ fail("unexpected uri for B " + qmlName);
+ }
+
+ // the values for D are not expected to be resolved (yet), but it does have a Revision
+ } else if (qobj.getName().equals("D")) {
+ assertEquals(IQmlRegistration.Kind.Type, qmlRegistration.getKind());
+ assertEquals(Long.valueOf(1), qmlRegistration.getVersion());
+ assertNull(qmlRegistration.getURI());
+ assertNull(qmlRegistration.getMajor());
+ assertNull(qmlRegistration.getMinor());
+ assertNull(qmlRegistration.getQmlName());
+ assertNull(qmlRegistration.getReason());
+
+ } else {
+ fail("unexpected qmlRegistration " + qobj.getName());
+ }
+ }
+ }
+
+ // class T;
+ //
+ // static void func()
+ // {
+ // qmlRegisterType<T>( "t-uri", 3, 4, "qml-T" );
+ // }
+ public void testQmlRegisterFwdDecl() throws Exception {
+ loadComment("qmlregistertype.hh");
+ waitForIndexer(fCProject);
+
+ QtIndex qtIndex = QtIndex.getIndex(fProject);
+ assertNotNull(qtIndex);
+
+ Collection<IQmlRegistration> qmlRegistrations = qtIndex.getQmlRegistrations();
+ assertNotNull(qmlRegistrations);
+ assertEquals(1, qmlRegistrations.size());
+
+ IQmlRegistration qmlRegistration = qmlRegistrations.iterator().next();
+ assertNotNull(qmlRegistration);
+ assertEquals(IQmlRegistration.Kind.Type, qmlRegistration.getKind());
+ assertEquals("t-uri", qmlRegistration.getURI());
+ assertEquals(Long.valueOf(3), qmlRegistration.getMajor());
+ assertEquals(Long.valueOf(4), qmlRegistration.getMinor());
+ assertEquals("qml-T", qmlRegistration.getQmlName());
+ assertNull(qmlRegistration.getReason());
+
+ // The QObject has not been defined, so it cannot be found.
+ assertNull(qmlRegistration.getQObject());
+ }
+
+ // #include "junit-QObject.hh"
+ // class B : public QObject
+ // {
+ // Q_OBJECT
+ // };
+ //
+ // class D : public B
+ // {
+ // Q_OBJECT
+ // };
+ //
+ // static void func()
+ // {
+ // qmlRegisterUncreatableType<B>( "b-uri", 1, 2, "B", QString( "msg1" ) );
+ // qmlRegisterUncreatableType<B>( "b-uri.34", 3, 4, "B34", QString( "msg2" ) );
+ //
+ // const char * uri = "d-uri";
+ // int maj = 2, min = 3;
+ // const char * qmlName = "D1";
+ // const QString msg( "msg3" );
+ // qmlRegisterUncreatableType<D>( uri, maj, min, qmlName, msg );
+ // }
+ public void testQmlRegisterUncreatableType() throws Exception {
+ loadComment("qmlregisteruncreatabletype.hh");
+
+ QtIndex qtIndex = QtIndex.getIndex(fProject);
+ assertNotNull(qtIndex);
+
+ IQObject b_qobj = qtIndex.findQObject(new String[]{ "B" });
+ if (!isIndexOk("B", b_qobj))
+ return;
+ assertNotNull(b_qobj);
+
+ Collection<IQmlRegistration> qmlRegistrations = qtIndex.getQmlRegistrations();
+ assertNotNull(qmlRegistrations);
+ assertEquals(3, qmlRegistrations.size());
+
+ for(IQmlRegistration qmlRegistration : qmlRegistrations) {
+ IQObject qobj = qmlRegistration.getQObject();
+ assertNotNull(qobj);
+
+ // all values of B should be fully resolved, except for Revision, which was not provided
+ if (qobj.getName().equals("B")) {
+ assertNull(qmlRegistration.getVersion());
+ String qmlName = qmlRegistration.getQmlName();
+ assertNotNull(qmlName);
+ if ("B".equals(qmlName)) {
+ assertEquals(IQmlRegistration.Kind.Uncreatable, qmlRegistration.getKind());
+ assertEquals("b-uri", qmlRegistration.getURI());
+ assertEquals(Long.valueOf(1), qmlRegistration.getMajor());
+ assertEquals(Long.valueOf(2), qmlRegistration.getMinor());
+ assertEquals(null/*"msg1"*/, qmlRegistration.getReason());
+ } else if ("B34".equals(qmlName)) {
+ assertEquals(IQmlRegistration.Kind.Uncreatable, qmlRegistration.getKind());
+ assertEquals("b-uri.34", qmlRegistration.getURI());
+ assertEquals(Long.valueOf(3), qmlRegistration.getMajor());
+ assertEquals(Long.valueOf(4), qmlRegistration.getMinor());
+ assertEquals(null/*"msg2"*/, qmlRegistration.getReason());
+ } else {
+ fail("unexpected uri for B " + qmlName);
+ }
+
+ // the values for D are not expected to be resolved (yet), but it does have a Revision
+ } else if (qobj.getName().equals("D")) {
+ assertEquals(IQmlRegistration.Kind.Uncreatable, qmlRegistration.getKind());
+ assertNull(qmlRegistration.getVersion());
+ assertNull(qmlRegistration.getURI());
+ assertNull(qmlRegistration.getMajor());
+ assertNull(qmlRegistration.getMinor());
+ assertNull(qmlRegistration.getQmlName());
+ assertNull(qmlRegistration.getReason());
+ } else {
+ fail("unexpected qmlRegistration " + qobj.getName());
+ }
+ }
+ }
+
+ // #include "junit-QObject.hh"
+ // class B : public QObject
+ // {
+ // Q_OBJECT
+ // };
+ //
+ // class D : public B
+ // {
+ // Q_OBJECT
+ // };
+ //
+ // static void func()
+ // {
+ // qmlRegisterType<B>( "b-uri", 1, 2, "B" );
+ // qmlRegisterType<B>( "b-uri.34", 3, 4, "B34" );
+ // qmlRegisterType<D, 1>( "d-uri", 2, 3, "D" );
+ // }
+ public void testAccessFromQObject() throws Exception {
+ loadComment("qmlregistertype_fromqobject.hh");
+
+ QtIndex qtIndex = QtIndex.getIndex(fProject);
+ assertNotNull(qtIndex);
+
+ IQObject b_qobj = qtIndex.findQObject(new String[]{ "B" });
+ if (!isIndexOk("B", b_qobj))
+ return;
+ assertNotNull(b_qobj);
+
+ Collection<IQmlRegistration> b_qmlRegistrations = b_qobj.getQmlRegistrations();
+ assertNotNull(b_qmlRegistrations);
+ assertEquals(2, b_qmlRegistrations.size());
+ for(IQmlRegistration qmlRegistration : b_qmlRegistrations)
+ if ("B".equals(qmlRegistration.getQmlName()))
+ assert_checkQmlRegistration(qmlRegistration, IQmlRegistration.Kind.Type, null, "b-uri", 1L, 2L, null);
+ else if("B34".equals(qmlRegistration.getQmlName()))
+ assert_checkQmlRegistration(qmlRegistration, IQmlRegistration.Kind.Type, null, "b-uri.34", 3L, 4L, null);
+ else
+ fail("unexpected QmlRegistration with qmlName '" + qmlRegistration.getQmlName() + '\'');
+
+ IQObject d_qobj = qtIndex.findQObject(new String[]{ "D" });
+ assertNotNull(d_qobj);
+
+ Collection<IQmlRegistration> d_qmlRegistrations = d_qobj.getQmlRegistrations();
+ assertNotNull(d_qmlRegistrations);
+ assertEquals(1, d_qmlRegistrations.size());
+ for(IQmlRegistration qmlRegistration : d_qmlRegistrations)
+ if("D".equals(qmlRegistration.getQmlName()))
+ assert_checkQmlRegistration(qmlRegistration, IQmlRegistration.Kind.Type, 1L, "d-uri", 2L, 3L, null);
+ else
+ fail("unexpected QmlRegistration with qmlName '" + qmlRegistration.getQmlName() + '\'');
+ }
+
+ private static void assert_checkQmlRegistration(IQmlRegistration qmlRegistration, IQmlRegistration.Kind eKind, Long eVersion, String eUri, Long eMaj, Long eMin, String reason) throws Exception {
+ assertNotNull(qmlRegistration);
+ assertEquals(eKind, qmlRegistration.getKind());
+ assertEquals(eVersion, qmlRegistration.getVersion());
+ assertEquals(eUri, qmlRegistration.getURI());
+ assertEquals(eMaj, qmlRegistration.getMajor());
+ assertEquals(eMin, qmlRegistration.getMinor());
+ assertEquals(reason, qmlRegistration.getReason());
+ }
+}

Back to the top