Search in sources :

Example 1 with SmaliCodeFragmentFactory

use of org.jf.smalidea.debugging.SmaliCodeFragmentFactory in project smali by JesusFreke.

the class SmaliCodeFragmentFactoryTest method assertVariableType.

private void assertVariableType(PsiElement context, String variableName, String expectedType) {
    SmaliCodeFragmentFactory codeFragmentFactory = new SmaliCodeFragmentFactory();
    JavaCodeFragment fragment = codeFragmentFactory.createCodeFragment(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, variableName), context, getProject());
    Editor editor = createEditor(fragment.getVirtualFile());
    editor.getCaretModel().moveToOffset(1);
    PsiElement element = fragment.findElementAt(0);
    Assert.assertTrue(element.getParent() instanceof PsiReferenceExpressionImpl);
    PsiReferenceExpressionImpl reference = (PsiReferenceExpressionImpl) element.getParent();
    Assert.assertEquals(expectedType, reference.getType().getCanonicalText());
}
Also used : SmaliCodeFragmentFactory(org.jf.smalidea.debugging.SmaliCodeFragmentFactory) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl) Editor(com.intellij.openapi.editor.Editor) JavaCodeFragment(com.intellij.psi.JavaCodeFragment) PsiReferenceExpressionImpl(com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl) PsiElement(com.intellij.psi.PsiElement)

Example 2 with SmaliCodeFragmentFactory

use of org.jf.smalidea.debugging.SmaliCodeFragmentFactory in project smali by JesusFreke.

the class SmaliCodeFragmentFactoryTest method assertCompletionContains.

private void assertCompletionContains(String completionText, PsiElement context, String[] expectedItems, String[] disallowedItems) {
    SmaliCodeFragmentFactory codeFragmentFactory = new SmaliCodeFragmentFactory();
    JavaCodeFragment fragment = codeFragmentFactory.createCodeFragment(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, completionText), context, getProject());
    Editor editor = createEditor(fragment.getVirtualFile());
    editor.getCaretModel().moveToOffset(completionText.length());
    new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(getProject(), editor);
    List<LookupElement> elements = LookupManager.getInstance(getProject()).getActiveLookup().getItems();
    HashSet expectedSet = Sets.newHashSet(expectedItems);
    HashSet disallowedSet = Sets.newHashSet(disallowedItems);
    for (LookupElement element : elements) {
        expectedSet.remove(element.toString());
        Assert.assertFalse(disallowedSet.contains(element.toString()));
    }
    Assert.assertTrue(expectedSet.size() == 0);
}
Also used : SmaliCodeFragmentFactory(org.jf.smalidea.debugging.SmaliCodeFragmentFactory) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl) CodeCompletionHandlerBase(com.intellij.codeInsight.completion.CodeCompletionHandlerBase) Editor(com.intellij.openapi.editor.Editor) LookupElement(com.intellij.codeInsight.lookup.LookupElement) JavaCodeFragment(com.intellij.psi.JavaCodeFragment) HashSet(java.util.HashSet)

Aggregations

TextWithImportsImpl (com.intellij.debugger.engine.evaluation.TextWithImportsImpl)2 Editor (com.intellij.openapi.editor.Editor)2 JavaCodeFragment (com.intellij.psi.JavaCodeFragment)2 SmaliCodeFragmentFactory (org.jf.smalidea.debugging.SmaliCodeFragmentFactory)2 CodeCompletionHandlerBase (com.intellij.codeInsight.completion.CodeCompletionHandlerBase)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 PsiElement (com.intellij.psi.PsiElement)1 PsiReferenceExpressionImpl (com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl)1 HashSet (java.util.HashSet)1