Permalink
Browse files

https://jira.jboss.org/browse/JBIDE-6120

Show superclass properties in code completion


git-svn-id: https://anonsvn.jboss.org/repos/hibernate/tools/trunk@20007 1b8cb986-b30d-0410-93ca-fae66ebed9b2
  • Loading branch information...
1 parent ac13784 commit 9fb59ad664b3fdbfa7324d1a6c2da7d3653761a1 Dmitry Geraskov committed Jul 22, 2010
@@ -171,20 +171,25 @@ private void addPropertiesToList(PersistentClass cmd, String prefix, int cursorP
prefix = "";
}
- EntityPOJOClass pc = new EntityPOJOClass(cmd, new Cfg2JavaTool()); // TODO: we should extract the needed functionallity from this hbm2java class.
-
- Iterator allPropertiesIterator = pc.getAllPropertiesIterator();
- while ( allPropertiesIterator.hasNext() ) {
- Property property = (Property) allPropertiesIterator.next();
- String candidate = property.getName();
- if (prefix.length() == 0 || candidate.toLowerCase().startsWith(prefix.toLowerCase())) {
- HQLCompletionProposal proposal = createStartWithCompletionProposal( prefix, cursorPosition, HQLCompletionProposal.PROPERTY, candidate );
- proposal.setEntityName( cmd.getEntityName() );
- proposal.setProperty( property );
- proposal.setPropertyName( candidate );
- hcc.accept( proposal);
+ // Add superclass's properties too
+ while (cmd != null){
+ EntityPOJOClass pc = new EntityPOJOClass(cmd, new Cfg2JavaTool()); // TODO: we should extract the needed functionallity from this hbm2java class.
+
+ Iterator allPropertiesIterator = pc.getAllPropertiesIterator();
+ while ( allPropertiesIterator.hasNext() ) {
+ Property property = (Property) allPropertiesIterator.next();
+ String candidate = property.getName();
+ if (prefix.length() == 0 || candidate.toLowerCase().startsWith(prefix.toLowerCase())) {
+ HQLCompletionProposal proposal = createStartWithCompletionProposal( prefix, cursorPosition, HQLCompletionProposal.PROPERTY, candidate );
+ proposal.setEntityName( cmd.getEntityName() );
+ proposal.setProperty( property );
+ proposal.setPropertyName( candidate );
+ hcc.accept( proposal);
+ }
}
- }
+ cmd = cmd.getSuperclass();
+ }
+
}
private HQLCompletionProposal createStartWithCompletionProposal(String prefix, int cursorPosition, int kind, String candidate) {
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping package="org.hibernate.tool.ide.completion">
+
+ <class name="City" table="hc_city" abstract="true">
+ <id name="id">
+ <generator class="native"/>
+ </id>
+ <discriminator column="hc_city_type" type="string"/>
+ <property name="name"/>
+ </class>
+
+</hibernate-mapping>
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.tool.ide.completion;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public abstract class City {
+
+ private Long id;
+
+ private String name;
+
+ public City() {
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
@@ -37,7 +37,8 @@ public static Configuration buildConfiguration() {
Model.class.getResourceAsStream("Product.hbm.xml")).
addInputStream(Model.class.getResourceAsStream("Store.hbm.xml")).
addInputStream(Model.class.getResourceAsStream("ProductOwnerAddress.hbm.xml")).
- addInputStream(Model.class.getResourceAsStream("StoreCity.hbm.xml"));
+ addInputStream(Model.class.getResourceAsStream("City.hbm.xml")).
+ addInputStream(Model.class.getResourceAsStream("StoreCity.hbm.xml"));
cfg.buildMappings();
return cfg;
}
@@ -66,7 +66,7 @@ protected void setUp() throws Exception {
public void testGetMappedClasses() {
Collector hcc = new Collector();
cc.getMatchingImports("", hcc);
- assertEquals("Invalid entity names count", 9, hcc.getCompletionProposals().length);
+ assertEquals("Invalid entity names count", 11, hcc.getCompletionProposals().length);
hcc.clear();
cc.getMatchingImports( " ", hcc );
@@ -209,7 +209,7 @@ public void testStoreCity() {
String canonicalPath = cc.getCanonicalPath(visible, "store.city");
cc.getMatchingProperties( canonicalPath, "", hcc );
- doTestFields(hcc.getCompletionProposals(), new String[] {"id", "name"});
+ doTestFields(hcc.getCompletionProposals(), new String[] {"id", "name", "number"});
}
public void testUnaliasedProductQuery() {
@@ -256,7 +256,7 @@ public void testBasicFrom() {
HQLCompletionProposal[] completionProposals = c.getCompletionProposals();
- assertEquals(9, completionProposals.length);
+ assertEquals(11, completionProposals.length);
for (int i = 0; i < completionProposals.length; i++) {
HQLCompletionProposal proposal = completionProposals[i];
assertEquals(HQLCompletionProposal.ENTITY_NAME, proposal.getCompletionKind());
@@ -275,7 +275,7 @@ public void testBasicFrom() {
completionProposals = c.getCompletionProposals();
- assertEquals(9, completionProposals.length);
+ assertEquals(11, completionProposals.length);
}
@@ -293,7 +293,7 @@ public void testFromNonWhitespace() {
caretPosition = getCaretPosition(query);
hqlEval.codeComplete(query, caretPosition, c);
completionProposals = c.getCompletionProposals();
- assertEquals("should get results after a nonwhitespace separator", 9, completionProposals.length);
+ assertEquals("should get results after a nonwhitespace separator", 11, completionProposals.length);
c.clear();
query = "from Store s where ";
@@ -371,7 +371,7 @@ public void testDottedFromPartialEntityName() {
HQLCompletionProposal[] completionProposals = c.getCompletionProposals();
- assertEquals(4, completionProposals.length);
+ assertEquals(5, completionProposals.length);
for (int i = 0; i < completionProposals.length; i++) {
HQLCompletionProposal proposal = completionProposals[i];
assertEquals(HQLCompletionProposal.ENTITY_NAME, proposal.getCompletionKind());
@@ -408,7 +408,7 @@ public void testBadInputAfterCursor() {
HQLCompletionProposal[] completionProposals = c.getCompletionProposals();
- assertEquals(4, completionProposals.length);
+ assertEquals(5, completionProposals.length);
}
@@ -514,7 +514,7 @@ public void testInFromAfterEntityAlias() {
HQLCompletionProposal[] completionProposals = c.getCompletionProposals();
- assertEquals(9, completionProposals.length);
+ assertEquals(11, completionProposals.length);
HQLCompletionProposal proposal = completionProposals[0];
assertEquals(HQLCompletionProposal.ENTITY_NAME, proposal.getCompletionKind());
@@ -3,11 +3,8 @@
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.tool.ide.completion">
- <class name="StoreCity" table="hc_store_city">
- <id name="id">
- <generator class="native"/>
- </id>
- <property name="name"/>
- </class>
+ <subclass name="StoreCity" extends="City" discriminator-value="sc">
+ <property name="number"/>
+ </subclass>
</hibernate-mapping>
@@ -22,27 +22,14 @@
*/
public class StoreCity {
- private Long id;
-
- private String name;
-
- public StoreCity() {
- }
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
+ private int number;
- public String getName() {
- return name;
- }
+ public int getNumber() {
+ return number;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ public void setNumber(int number) {
+ this.number = number;
+ }
}

0 comments on commit 9fb59ad

Please sign in to comment.