diff --git a/smalidea/src/main/antlr3/smalideaParser.g b/smalidea/src/main/antlr3/smalideaParser.g index 1bf0e867..462e293b 100644 --- a/smalidea/src/main/antlr3/smalideaParser.g +++ b/smalidea/src/main/antlr3/smalideaParser.g @@ -37,6 +37,7 @@ package org.jf.smalidea; import com.intellij.lang.PsiBuilder; import com.intellij.lang.PsiBuilder.Marker; +import org.jf.smalidea.psi.SmaliElementTypes; } @@ -190,6 +191,7 @@ the annotations. If it turns out that they are field annotations, we include the add them to the $smali_file::classAnnotations list*/ field @init { + Marker marker = mark(); boolean classAnnotations = true; } : FIELD_DIRECTIVE @@ -201,10 +203,15 @@ field ) | /*epsilon*/ ); + finally { + marker.done(SmaliElementTypes.FIELD); + } method + @init { Marker marker = mark(); } : METHOD_DIRECTIVE access_list member_name method_prototype statements_and_directives END_METHOD_DIRECTIVE; + finally { marker.done(SmaliElementTypes.METHOD); } statements_and_directives : ( diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/SmaliElementTypes.java b/smalidea/src/main/java/org/jf/smalidea/psi/SmaliElementTypes.java index b9eea561..22acaef6 100644 --- a/smalidea/src/main/java/org/jf/smalidea/psi/SmaliElementTypes.java +++ b/smalidea/src/main/java/org/jf/smalidea/psi/SmaliElementTypes.java @@ -32,9 +32,13 @@ package org.jf.smalidea.psi; import org.jf.smalidea.psi.stub.element.SmaliClassElementType; +import org.jf.smalidea.psi.stub.element.SmaliFieldElementType; import org.jf.smalidea.psi.stub.element.SmaliFileElementType; +import org.jf.smalidea.psi.stub.element.SmaliMethodElementType; public class SmaliElementTypes { public static final SmaliFileElementType FILE = SmaliFileElementType.INSTANCE; public static final SmaliClassElementType CLASS = SmaliClassElementType.INSTANCE; + public static final SmaliFieldElementType FIELD = SmaliFieldElementType.INSTANCE; + public static final SmaliMethodElementType METHOD = SmaliMethodElementType.INSTANCE; } diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliField.java b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliField.java new file mode 100644 index 00000000..aefaae74 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliField.java @@ -0,0 +1,47 @@ +/* + * Copyright 2014, 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.psi.impl; + +import com.intellij.lang.ASTNode; +import org.jetbrains.annotations.NotNull; +import org.jf.smalidea.psi.SmaliElementTypes; +import org.jf.smalidea.psi.stub.SmaliFieldStub; + +public class SmaliField extends SmaliStubBasedPsiElement { + public SmaliField(@NotNull SmaliFieldStub stub) { + super(stub, SmaliElementTypes.FIELD); + } + + public SmaliField(@NotNull ASTNode node) { + super(node); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliMethod.java b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliMethod.java new file mode 100644 index 00000000..4dd9e934 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliMethod.java @@ -0,0 +1,47 @@ +/* + * Copyright 2014, 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.psi.impl; + +import com.intellij.lang.ASTNode; +import org.jetbrains.annotations.NotNull; +import org.jf.smalidea.psi.SmaliElementTypes; +import org.jf.smalidea.psi.stub.SmaliMethodStub; + +public class SmaliMethod extends SmaliStubBasedPsiElement { + public SmaliMethod(@NotNull SmaliMethodStub stub) { + super(stub, SmaliElementTypes.METHOD); + } + + public SmaliMethod(@NotNull ASTNode node) { + super(node); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/stub/SmaliFieldStub.java b/smalidea/src/main/java/org/jf/smalidea/psi/stub/SmaliFieldStub.java new file mode 100644 index 00000000..21b054f0 --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/psi/stub/SmaliFieldStub.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.psi.stub; + +import com.intellij.psi.stubs.StubBase; +import com.intellij.psi.stubs.StubElement; +import org.jf.smalidea.psi.SmaliElementTypes; +import org.jf.smalidea.psi.impl.SmaliField; + +public class SmaliFieldStub extends StubBase { + public SmaliFieldStub(StubElement parent) { + super(parent, SmaliElementTypes.FIELD); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/stub/SmaliMethodStub.java b/smalidea/src/main/java/org/jf/smalidea/psi/stub/SmaliMethodStub.java new file mode 100644 index 00000000..6f56b2fa --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/psi/stub/SmaliMethodStub.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014, 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.psi.stub; + +import com.intellij.psi.stubs.StubBase; +import com.intellij.psi.stubs.StubElement; +import org.jf.smalidea.psi.SmaliElementTypes; +import org.jf.smalidea.psi.impl.SmaliMethod; + +public class SmaliMethodStub extends StubBase { + public SmaliMethodStub(StubElement parent) { + super(parent, SmaliElementTypes.METHOD); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/stub/element/SmaliFieldElementType.java b/smalidea/src/main/java/org/jf/smalidea/psi/stub/element/SmaliFieldElementType.java new file mode 100644 index 00000000..2344bf4a --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/psi/stub/element/SmaliFieldElementType.java @@ -0,0 +1,80 @@ +/* + * Copyright 2014, 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.psi.stub.element; + +import com.intellij.lang.ASTNode; +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 org.jetbrains.annotations.NotNull; +import org.jf.smalidea.psi.impl.SmaliField; +import org.jf.smalidea.psi.stub.SmaliFieldStub; +import org.jf.smalidea.psi.stub.SmaliStubElementType; + +import java.io.IOException; + +public class SmaliFieldElementType extends SmaliStubElementType { + public static final SmaliFieldElementType INSTANCE = new SmaliFieldElementType(); + + private SmaliFieldElementType() { + super("FIELD"); + } + + @NotNull @Override public String getExternalId() { + return "smali.field"; + } + + @Override public SmaliField createPsi(@NotNull SmaliFieldStub stub) { + return new SmaliField(stub); + } + + @Override public SmaliField createPsi(@NotNull ASTNode node) { + return new SmaliField(node); + } + + @Override public SmaliFieldStub createStub(@NotNull SmaliField psi, StubElement parentStub) { + return new SmaliFieldStub(parentStub); + } + + @Override + public void serialize(@NotNull SmaliFieldStub stub, @NotNull StubOutputStream dataStream) throws IOException { + } + + @NotNull @Override + public SmaliFieldStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { + return new SmaliFieldStub(parentStub); + } + + @Override public void indexStub(@NotNull SmaliFieldStub stub, @NotNull IndexSink sink) { + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/stub/element/SmaliMethodElementType.java b/smalidea/src/main/java/org/jf/smalidea/psi/stub/element/SmaliMethodElementType.java new file mode 100644 index 00000000..cdbac2fb --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/psi/stub/element/SmaliMethodElementType.java @@ -0,0 +1,80 @@ +/* + * Copyright 2014, 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.psi.stub.element; + +import com.intellij.lang.ASTNode; +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 org.jetbrains.annotations.NotNull; +import org.jf.smalidea.psi.impl.SmaliMethod; +import org.jf.smalidea.psi.stub.SmaliMethodStub; +import org.jf.smalidea.psi.stub.SmaliStubElementType; + +import java.io.IOException; + +public class SmaliMethodElementType extends SmaliStubElementType { + public static final SmaliMethodElementType INSTANCE = new SmaliMethodElementType(); + + private SmaliMethodElementType() { + super("METHOD"); + } + + @NotNull @Override public String getExternalId() { + return "smali.method"; + } + + @Override public SmaliMethod createPsi(@NotNull SmaliMethodStub stub) { + return new SmaliMethod(stub); + } + + @Override public SmaliMethod createPsi(@NotNull ASTNode node) { + return new SmaliMethod(node); + } + + @Override public SmaliMethodStub createStub(@NotNull SmaliMethod psi, StubElement parentStub) { + return new SmaliMethodStub(parentStub); + } + + @Override + public void serialize(@NotNull SmaliMethodStub stub, @NotNull StubOutputStream dataStream) throws IOException { + } + + @NotNull @Override + public SmaliMethodStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { + return new SmaliMethodStub(parentStub); + } + + @Override public void indexStub(@NotNull SmaliMethodStub stub, @NotNull IndexSink sink) { + } +}