use of org.hibernate.eclipse.jdt.ui.internal.HQLJavaCompletionProposalComputer in project jbosstools-hibernate by jbosstools.
the class JavaHBMQueryTest method testJavaHQLQueryCodeCompletion.
@SuppressWarnings("unused")
public void testJavaHQLQueryCodeCompletion() throws JavaModelException, CoreException, NoSuchFieldException, IllegalAccessException {
IPackageFragment pack = project.getTestClassType().getPackageFragment();
String testCP = "TestCompletionProposals.java";
ICompilationUnit cu = pack.createCompilationUnit(testCP, "", true, // $NON-NLS-1$
null);
cu.createPackageDeclaration(pack.getElementName(), null);
IType type = cu.createType("public class " + testCP + " {}", null, false, // $NON-NLS-1$//$NON-NLS-2$
null);
type.createMethod("public static void main(String[] args){String query = \"from \";}", null, false, // $NON-NLS-1$
null);
IWorkbenchPage p = JavaPlugin.getActivePage();
IEditorPart part = EditorUtility.openInEditor(type, true);
if (part instanceof CompilationUnitEditor) {
CompilationUnitEditor editor = (CompilationUnitEditor) part;
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
HQLJavaCompletionProposalComputer proposalComputer = new HQLJavaCompletionProposalComputer();
ContentAssistInvocationContext context = new JavaContentAssistInvocationContext(editor.getViewer(), 125, editor);
List<ICompletionProposal> computeCompletionProposals = proposalComputer.computeCompletionProposals(context, null);
assertTrue(computeCompletionProposals.size() > 0);
for (ICompletionProposal iCompletionProposal : computeCompletionProposals) {
Class<? extends ICompletionProposal> class1 = iCompletionProposal.getClass();
if (class1.getPackage().getName().indexOf("org.jboss.tools.hibernate") == 0) {
// this is our completion proposal
Field declaredField = class1.getDeclaredField("documentOffset");
declaredField.setAccessible(true);
Integer offset = (Integer) declaredField.get(iCompletionProposal);
Assert.assertTrue(offset > 0);
}
}
} else {
fail("Can't open CompilationUnitEditor");
}
}
Aggregations