public void testComponentPropertyNames() { Collector c = new Collector(); IHQLCodeAssist hqlEval = new HQLCodeAssist(sf); String query = "from Product as p where p.owner.|"; int caretPosition = getCaretPosition(query); hqlEval.codeComplete(getCleanQuery(query), caretPosition, c); HQLCompletionProposal[] completionProposals = c.getCompletionProposals(); assertEquals(3, completionProposals.length); assertNotNull(completionProposals[0]); c.clear(); query = "from Product as p where p.owner.address."; caretPosition = getCaretPosition(query); hqlEval.codeComplete(getCleanQuery(query), caretPosition, c); completionProposals = c.getCompletionProposals(); assertEquals(3, completionProposals.length); c.clear(); query = "from Product as p join p.otherOwners o where o."; caretPosition = getCaretPosition(query); hqlEval.codeComplete(getCleanQuery(query), caretPosition, c); completionProposals = c.getCompletionProposals(); assertEquals(3, completionProposals.length); }
public void testGetMappedClasses() { Collector hcc = new Collector(); cc.getMatchingImports("", hcc); assertEquals("Invalid entity names count", 9, hcc.getCompletionProposals().length); hcc.clear(); cc.getMatchingImports(" ", hcc); assertTrue("Space prefix should have no classes", hcc.getCompletionProposals().length == 0); hcc.clear(); cc.getMatchingImports("pro", hcc); assertTrue("Completion should not be case sensitive", hcc.getCompletionProposals().length == 2); hcc.clear(); cc.getMatchingImports("StoreC", hcc); assertEquals("Invalid entity names count", 1, hcc.getCompletionProposals().length); assertEquals( "StoreCity should have been found", "StoreCity", hcc.getCompletionProposals()[0].getSimpleName()); hcc.clear(); cc.getMatchingImports("NotThere", hcc); assertTrue(hcc.getCompletionProposals().length == 0); hcc.clear(); cc.getMatchingImports("Uni", hcc); assertEquals("Universe", hcc.getCompletionProposals()[0].getSimpleName()); }
private void doTestUnaliasedProductQuery(final String query) { Collector hcc = new Collector(); List visible = getVisibleEntityNames(query.toCharArray()); cc.getMatchingProperties(cc.getCanonicalPath(visible, "owner"), "f", hcc); HQLCompletionProposal[] completionProposals = hcc.getCompletionProposals(); // assertEquals(1, completionProposals.length); assertEquals("firstName", completionProposals[0].getSimpleName()); // hcc.clear(); cc.getMatchingProperties(cc.getCanonicalPath(visible, "owner"), "l", hcc); completionProposals = hcc.getCompletionProposals(); assertEquals(1, completionProposals.length); assertEquals("lastName", completionProposals[0].getSimpleName()); // hcc.clear(); cc.getMatchingProperties(cc.getCanonicalPath(visible, "owner"), "", hcc); // firstname, lastname, owner assertEquals(3, hcc.getCompletionProposals().length); // hcc.clear(); cc.getMatchingProperties(cc.getCanonicalPath(visible, "owner"), "g", hcc); assertEquals(0, hcc.getCompletionProposals().length); }
public void testKeywordFunction() { Collector hcc = new Collector(); cc.getMatchingKeywords("f", 2, hcc); HQLCompletionProposal[] completionProposals = hcc.getCompletionProposals(); assertEquals(4, completionProposals.length); assertEquals("alse", completionProposals[0].getCompletion()); hcc.clear(); cc.getMatchingFunctions("ma", 2, hcc); completionProposals = hcc.getCompletionProposals(); assertEquals(1, completionProposals.length); assertEquals("x", completionProposals[0].getCompletion()); hcc.clear(); cc.getMatchingKeywords("FR", 3, hcc); completionProposals = hcc.getCompletionProposals(); assertEquals(1, completionProposals.length); hcc.clear(); cc.getMatchingFunctions("MA", 2, hcc); completionProposals = hcc.getCompletionProposals(); assertEquals(1, completionProposals.length); }
public void testGetStoreFields() { Collector hcc = new Collector(); cc.getMatchingProperties("Store", "", hcc); doTestFields(hcc.getCompletionProposals(), new String[] {"city", "id", "name", "name2"}); hcc.clear(); cc.getMatchingProperties("Store", "name", hcc); doTestFields(hcc.getCompletionProposals(), new String[] {"name", "name2"}); hcc.clear(); cc.getMatchingProperties("Store", "name2", hcc); doTestFields(hcc.getCompletionProposals(), new String[] {"name2"}); hcc.clear(); }
public void testGetProductFields() { Collector hcc = new Collector(); cc.getMatchingProperties("Product", "", hcc); doTestFields( hcc.getCompletionProposals(), new String[] {"id", "otherOwners", "owner", "price", "stores", "version", "weight"}); hcc.clear(); cc.getMatchingProperties("Product", " ", hcc); doTestFields(hcc.getCompletionProposals(), new String[] {}); hcc.clear(); cc.getMatchingProperties("Product", "v", hcc); doTestFields(hcc.getCompletionProposals(), new String[] {"version"}); hcc.clear(); cc.getMatchingProperties("Product", "V", hcc); doTestFields(hcc.getCompletionProposals(), new String[] {"version"}); hcc.clear(); cc.getMatchingProperties("Product", "X", hcc); doTestFields(hcc.getCompletionProposals(), new String[0]); }
public void testProductOwnerAddress() { String query = "select p from Product p where p.owner."; List visible = getVisibleEntityNames(query.toCharArray()); Collector hcc = new Collector(); cc.getMatchingProperties(cc.getCanonicalPath(visible, "p.owner"), "", hcc); doTestFields(hcc.getCompletionProposals(), new String[] {"address", "firstName", "lastName"}); hcc.clear(); query = "select p from Product p where p.owner.address."; visible = getVisibleEntityNames(query.toCharArray()); cc.getMatchingProperties(cc.getCanonicalPath(visible, "p.owner.address"), "", hcc); doTestFields(hcc.getCompletionProposals(), new String[] {"id", "number", "street"}); }
public void parse(CharSequence content, String contentDescription, Collector collector) { Map<String, ConfigurationKey<?>> registeredKeys = ConfigurationKey.registeredKeys(); int lineNumber = 0; Matcher lineMatcher = NEWLINE_FINDER.matcher(content); while (lineMatcher.find()) { CharSequence line = content.subSequence(lineMatcher.start(1), lineMatcher.end(1)); lineNumber++; if (line.length() == 0 || line.charAt(0) == '#') continue; Matcher matcher = LINE.matcher(line); if (!matcher.matches()) { reporter.report(contentDescription, "Invalid line", lineNumber, line); continue; } String operator = null; String keyName = null; String stringValue; if (matcher.group(1) == null) { keyName = matcher.group(2); operator = matcher.group(3); stringValue = matcher.group(4); } else { keyName = matcher.group(1); operator = "clear"; stringValue = null; } ConfigurationKey<?> key = registeredKeys.get(keyName); if (key == null) { reporter.report(contentDescription, "Unknown key '" + keyName + "'", lineNumber, line); continue; } ConfigurationDataType type = key.getType(); boolean listOperator = operator.equals("+=") || operator.equals("-="); if (listOperator && !type.isList()) { reporter.report( contentDescription, "'" + keyName + "' is not a list and doesn't support " + operator + " (only = and clear)", lineNumber, line); continue; } if (operator.equals("=") && type.isList()) { reporter.report( contentDescription, "'" + keyName + "' is a list and cannot be assigned to (use +=, -= and clear instead)", lineNumber, line); continue; } Object value = null; if (stringValue != null) try { value = type.getParser().parse(stringValue); } catch (Exception e) { reporter.report( contentDescription, "Error while parsing the value for '" + keyName + "' value '" + stringValue + "' (should be " + type.getParser().exampleValue() + ")", lineNumber, line); continue; } if (operator.equals("clear")) { collector.clear(key, contentDescription, lineNumber); } else if (operator.equals("=")) { collector.set(key, value, contentDescription, lineNumber); } else if (operator.equals("+=")) { collector.add(key, value, contentDescription, lineNumber); } else { collector.remove(key, value, contentDescription, lineNumber); } } }