mirror of
https://github.com/revanced/smali.git
synced 2025-05-12 04:14:27 +02:00
Implement initial SmaliAnnotation
This commit is contained in:
parent
4a75c556bb
commit
65eecc51b2
@ -192,19 +192,31 @@ add them to the $smali_file::classAnnotations list*/
|
||||
field
|
||||
@init {
|
||||
Marker marker = mark();
|
||||
Marker annotationsMarker = null;
|
||||
boolean classAnnotations = true;
|
||||
}
|
||||
: FIELD_DIRECTIVE
|
||||
access_list
|
||||
member_name COLON nonvoid_type_descriptor (EQUAL literal)?
|
||||
( END_FIELD_DIRECTIVE
|
||||
| (ANNOTATION_DIRECTIVE)=> ( ((ANNOTATION_DIRECTIVE)=> annotation)+
|
||||
| (ANNOTATION_DIRECTIVE)=> ( {annotationsMarker = mark();}
|
||||
((ANNOTATION_DIRECTIVE)=> annotation)+
|
||||
(END_FIELD_DIRECTIVE {classAnnotations = false;})?
|
||||
)
|
||||
| /*epsilon*/
|
||||
);
|
||||
finally {
|
||||
marker.done(SmaliElementTypes.FIELD);
|
||||
if (annotationsMarker != null) {
|
||||
if (classAnnotations) {
|
||||
marker.doneBefore(SmaliElementTypes.FIELD, annotationsMarker);
|
||||
annotationsMarker.drop();
|
||||
} else {
|
||||
annotationsMarker.drop();
|
||||
marker.done(SmaliElementTypes.FIELD);
|
||||
}
|
||||
} else {
|
||||
marker.done(SmaliElementTypes.FIELD);
|
||||
}
|
||||
}
|
||||
|
||||
method
|
||||
@ -371,8 +383,10 @@ annotation_element
|
||||
: simple_name EQUAL literal;
|
||||
|
||||
annotation
|
||||
@init { Marker marker = mark(); }
|
||||
: ANNOTATION_DIRECTIVE ANNOTATION_VISIBILITY CLASS_DESCRIPTOR
|
||||
annotation_element* END_ANNOTATION_DIRECTIVE;
|
||||
finally { marker.done(SmaliElementTypes.ANNOTATION); }
|
||||
|
||||
subannotation
|
||||
: SUBANNOTATION_DIRECTIVE CLASS_DESCRIPTOR annotation_element* END_SUBANNOTATION_DIRECTIVE;
|
||||
|
@ -31,14 +31,12 @@
|
||||
|
||||
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;
|
||||
import org.jf.smalidea.psi.stub.element.*;
|
||||
|
||||
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;
|
||||
public static final SmaliAnnotationElementType ANNOTATION = SmaliAnnotationElementType.INSTANCE;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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) {
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user