Implement initial SmaliAnnotation

This commit is contained in:
Ben Gruver 2014-03-16 15:05:49 -07:00
parent 4a75c556bb
commit 65eecc51b2
5 changed files with 188 additions and 6 deletions

View File

@ -192,20 +192,32 @@ add them to the $smali_file::classAnnotations list*/
field field
@init { @init {
Marker marker = mark(); Marker marker = mark();
Marker annotationsMarker = null;
boolean classAnnotations = true; boolean classAnnotations = true;
} }
: FIELD_DIRECTIVE : FIELD_DIRECTIVE
access_list access_list
member_name COLON nonvoid_type_descriptor (EQUAL literal)? member_name COLON nonvoid_type_descriptor (EQUAL literal)?
( END_FIELD_DIRECTIVE ( END_FIELD_DIRECTIVE
| (ANNOTATION_DIRECTIVE)=> ( ((ANNOTATION_DIRECTIVE)=> annotation)+ | (ANNOTATION_DIRECTIVE)=> ( {annotationsMarker = mark();}
((ANNOTATION_DIRECTIVE)=> annotation)+
(END_FIELD_DIRECTIVE {classAnnotations = false;})? (END_FIELD_DIRECTIVE {classAnnotations = false;})?
) )
| /*epsilon*/ | /*epsilon*/
); );
finally { finally {
if (annotationsMarker != null) {
if (classAnnotations) {
marker.doneBefore(SmaliElementTypes.FIELD, annotationsMarker);
annotationsMarker.drop();
} else {
annotationsMarker.drop();
marker.done(SmaliElementTypes.FIELD); marker.done(SmaliElementTypes.FIELD);
} }
} else {
marker.done(SmaliElementTypes.FIELD);
}
}
method method
@init { Marker marker = mark(); } @init { Marker marker = mark(); }
@ -371,8 +383,10 @@ annotation_element
: simple_name EQUAL literal; : simple_name EQUAL literal;
annotation annotation
@init { Marker marker = mark(); }
: ANNOTATION_DIRECTIVE ANNOTATION_VISIBILITY CLASS_DESCRIPTOR : ANNOTATION_DIRECTIVE ANNOTATION_VISIBILITY CLASS_DESCRIPTOR
annotation_element* END_ANNOTATION_DIRECTIVE; annotation_element* END_ANNOTATION_DIRECTIVE;
finally { marker.done(SmaliElementTypes.ANNOTATION); }
subannotation subannotation
: SUBANNOTATION_DIRECTIVE CLASS_DESCRIPTOR annotation_element* END_SUBANNOTATION_DIRECTIVE; : SUBANNOTATION_DIRECTIVE CLASS_DESCRIPTOR annotation_element* END_SUBANNOTATION_DIRECTIVE;

View File

@ -31,14 +31,12 @@
package org.jf.smalidea.psi; package org.jf.smalidea.psi;
import org.jf.smalidea.psi.stub.element.SmaliClassElementType; import org.jf.smalidea.psi.stub.element.*;
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 class SmaliElementTypes {
public static final SmaliFileElementType FILE = SmaliFileElementType.INSTANCE; public static final SmaliFileElementType FILE = SmaliFileElementType.INSTANCE;
public static final SmaliClassElementType CLASS = SmaliClassElementType.INSTANCE; public static final SmaliClassElementType CLASS = SmaliClassElementType.INSTANCE;
public static final SmaliFieldElementType FIELD = SmaliFieldElementType.INSTANCE; public static final SmaliFieldElementType FIELD = SmaliFieldElementType.INSTANCE;
public static final SmaliMethodElementType METHOD = SmaliMethodElementType.INSTANCE; public static final SmaliMethodElementType METHOD = SmaliMethodElementType.INSTANCE;
public static final SmaliAnnotationElementType ANNOTATION = SmaliAnnotationElementType.INSTANCE;
} }

View File

@ -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.SmaliAnnotationStub;
public class SmaliAnnotation extends SmaliStubBasedPsiElement<SmaliAnnotationStub> {
public SmaliAnnotation(@NotNull SmaliAnnotationStub stub) {
super(stub, SmaliElementTypes.ANNOTATION);
}
public SmaliAnnotation(@NotNull ASTNode node) {
super(node);
}
}

View File

@ -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.SmaliAnnotation;
public class SmaliAnnotationStub extends StubBase<SmaliAnnotation> {
public SmaliAnnotationStub(StubElement parent) {
super(parent, SmaliElementTypes.ANNOTATION);
}
}

View File

@ -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.SmaliAnnotation;
import org.jf.smalidea.psi.stub.SmaliAnnotationStub;
import org.jf.smalidea.psi.stub.SmaliStubElementType;
import java.io.IOException;
public class SmaliAnnotationElementType extends SmaliStubElementType<SmaliAnnotationStub, SmaliAnnotation> {
public static final SmaliAnnotationElementType INSTANCE = new SmaliAnnotationElementType();
private SmaliAnnotationElementType() {
super("ANNOTATION");
}
@NotNull @Override public String getExternalId() {
return "smali.annotation";
}
@Override public SmaliAnnotation createPsi(@NotNull SmaliAnnotationStub stub) {
return new SmaliAnnotation(stub);
}
@Override public SmaliAnnotation createPsi(@NotNull ASTNode node) {
return new SmaliAnnotation(node);
}
@Override public SmaliAnnotationStub createStub(@NotNull SmaliAnnotation psi, StubElement parentStub) {
return new SmaliAnnotationStub(parentStub);
}
@Override
public void serialize(@NotNull SmaliAnnotationStub stub, @NotNull StubOutputStream dataStream) throws IOException {
}
@NotNull @Override
public SmaliAnnotationStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new SmaliAnnotationStub(parentStub);
}
@Override public void indexStub(@NotNull SmaliAnnotationStub stub, @NotNull IndexSink sink) {
}
}