Add and fix a parser test for a blank file

This commit is contained in:
Ben Gruver
2015-01-24 15:09:38 -08:00
parent a5efca6fe6
commit 2d39ef6337
7 changed files with 122 additions and 3 deletions

View File

@ -25,6 +25,7 @@
<xdebugger.debuggerSupport id="SmaliDebuggerSupport" order="first,before XDebuggerSupport"
implementation="org.jf.smalidea.debugging.SmaliDebuggerSupport"/>
<debugger.codeFragmentFactory implementation="org.jf.smalidea.debugging.SmaliCodeFragmentFactory"/>
<stubElementTypeHolder class="org.jf.smalidea.psi.SmaliElementTypes" />
</extensions>
<application-components>

View File

@ -32,7 +32,6 @@
package org.jf.smalidea.psi.impl;
import com.google.common.collect.Lists;
import com.intellij.extapi.psi.StubBasedPsiElementBase;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiReferenceList;
import com.intellij.psi.StubBasedPsiElement;
@ -43,7 +42,7 @@ import org.jf.smalidea.psi.stub.SmaliBaseReferenceListStub;
import java.util.List;
public abstract class SmaliBaseReferenceList<StubT extends SmaliBaseReferenceListStub>
extends StubBasedPsiElementBase<StubT> implements StubBasedPsiElement<StubT>, PsiReferenceList {
extends SmaliStubBasedPsiElement<StubT> implements StubBasedPsiElement<StubT>, PsiReferenceList {
protected SmaliBaseReferenceList(@NotNull StubT stub, @NotNull IStubElementType nodeType) {
super(stub, nodeType);
}

View File

@ -75,4 +75,8 @@ public abstract class SmaliStubBasedPsiElement<T extends StubElement> extends St
}
return null;
}
public String toString() {
return this.getClass().getSimpleName() + "(" + this.getElementType().toString() + ")";
}
}

View File

@ -36,6 +36,7 @@ import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.stubs.StubInputStream;
import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import org.jf.smalidea.psi.impl.SmaliClass;
import org.jf.smalidea.psi.index.SmaliClassNameIndex;
@ -73,7 +74,12 @@ public class SmaliClassElementType extends SmaliStubElementType<SmaliClassStub,
@NotNull @Override
public SmaliClassStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new SmaliClassStub(parentStub, dataStream.readName().getString());
StringRef nameRef = dataStream.readName();
String name = null;
if (nameRef != null) {
name = nameRef.getString();
}
return new SmaliClassStub(parentStub, name);
}
@Override public void indexStub(@NotNull SmaliClassStub stub, @NotNull IndexSink sink) {

View File

@ -0,0 +1,99 @@
/*
* Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.smalidea;
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
import com.intellij.psi.stubs.*;
import com.intellij.testFramework.LightVirtualFile;
import com.intellij.testFramework.ParsingTestCase;
import org.jf.smalidea.psi.SmaliElementTypes;
import org.jf.smalidea.psi.impl.SmaliFile;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class ParserTest extends ParsingTestCase {
public ParserTest() {
super("", "smalidea", new SmaliParserDefinition());
}
@Override
protected void setUp() throws Exception {
super.setUp();
registerApplicationService(SerializationManager.class, new SerializationManagerImpl());
StubElementTypeHolderEP stubHolder = new StubElementTypeHolderEP();
stubHolder.holderClass = SmaliElementTypes.class.getCanonicalName();
registerExtension(StubElementTypeHolderEP.EP_NAME, stubHolder);
}
@Override
protected String getTestDataPath() {
return "testData";
}
@Override protected void doTest(boolean checkResult) {
String name = getTestName(false);
try {
String text = loadFile(name + "." + myFileExt);
SmaliFile f = (SmaliFile)createPsiFile(name, text);
StubTree stubTree = f.calcStubTree();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SerializationManagerImpl.getInstanceEx().serialize(stubTree.getRoot(), baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
SerializationManagerImpl.getInstanceEx().deserialize(bais);
ensureParsed(f);
assertEquals("light virtual file text mismatch", text,
((LightVirtualFile)f.getVirtualFile()).getContent().toString());
assertEquals("virtual file text mismatch", text, LoadTextUtil.loadText(f.getVirtualFile()));
assertEquals("doc text mismatch", text, f.getViewProvider().getDocument().getText());
assertEquals("psi text mismatch", text, f.getText());
if (checkResult){
checkResult(name, f);
}
else{
toParseTreeText(f, skipSpaces(), includeRanges());
}
}
catch (IOException e) {
throw new RuntimeException(e);
} catch (SerializerNotFoundException e) {
throw new RuntimeException(e);
}
}
public void testEmpty() throws Exception { doTest(true); }
}

View File

View File

@ -0,0 +1,10 @@
smali.FILE
SmaliClass(CLASS)
SmaliModifierList(MODIFIER_LIST)
<empty list>
SmaliExtendsList(EXTENDS_LIST)
<empty list>
SmaliImplementsList(IMPLEMENTS_LIST)
<empty list>
PsiErrorElement:required (...)+ loop did not match anything at input '<EOF>'
<empty list>