mirror of
https://github.com/revanced/smali.git
synced 2025-05-03 16:14:29 +02:00
Start improving the error resistance of field declarations
This commit is contained in:
parent
70693ff6bb
commit
9423a7d7d0
@ -277,12 +277,12 @@ field
|
|||||||
}
|
}
|
||||||
: FIELD_DIRECTIVE
|
: FIELD_DIRECTIVE
|
||||||
access_list
|
access_list
|
||||||
member_name COLON nonvoid_type_descriptor
|
member_name colon nonvoid_type_descriptor
|
||||||
field_initializer?
|
field_initializer?
|
||||||
( END_FIELD_DIRECTIVE
|
( end_field_directive
|
||||||
| (ANNOTATION_DIRECTIVE)=> ( {annotationsMarker = mark();}
|
| (ANNOTATION_DIRECTIVE)=> ( {annotationsMarker = mark();}
|
||||||
((ANNOTATION_DIRECTIVE)=> annotation)+
|
((ANNOTATION_DIRECTIVE)=> annotation)+
|
||||||
(END_FIELD_DIRECTIVE {classAnnotations = false;})?
|
(end_field_directive {classAnnotations = false;})?
|
||||||
)
|
)
|
||||||
| /*epsilon*/
|
| /*epsilon*/
|
||||||
)
|
)
|
||||||
@ -300,11 +300,19 @@ field
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
catch [RecognitionException re] {
|
catch [RecognitionException re] {
|
||||||
annotationsMarker.drop();
|
if (annotationsMarker != null) {
|
||||||
|
annotationsMarker.drop();
|
||||||
|
}
|
||||||
recover(input, re);
|
recover(input, re);
|
||||||
reportError(marker, re, false);
|
reportError(marker, re, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
colon
|
||||||
|
: COLON;
|
||||||
|
|
||||||
|
end_field_directive
|
||||||
|
: END_FIELD_DIRECTIVE;
|
||||||
|
|
||||||
field_initializer
|
field_initializer
|
||||||
@init { Marker marker = mark(); }
|
@init { Marker marker = mark(); }
|
||||||
: EQUAL literal
|
: EQUAL literal
|
||||||
|
@ -44,8 +44,6 @@ import org.jf.smalidea.psi.SmaliElementTypes;
|
|||||||
import org.jf.smalidea.psi.iface.SmaliModifierListOwner;
|
import org.jf.smalidea.psi.iface.SmaliModifierListOwner;
|
||||||
import org.jf.smalidea.psi.stub.SmaliFieldStub;
|
import org.jf.smalidea.psi.stub.SmaliFieldStub;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class SmaliField extends SmaliStubBasedPsiElement<SmaliFieldStub> implements PsiField, SmaliModifierListOwner {
|
public class SmaliField extends SmaliStubBasedPsiElement<SmaliFieldStub> implements PsiField, SmaliModifierListOwner {
|
||||||
public SmaliField(@NotNull SmaliFieldStub stub) {
|
public SmaliField(@NotNull SmaliFieldStub stub) {
|
||||||
super(stub, SmaliElementTypes.FIELD);
|
super(stub, SmaliElementTypes.FIELD);
|
||||||
@ -55,14 +53,16 @@ public class SmaliField extends SmaliStubBasedPsiElement<SmaliFieldStub> impleme
|
|||||||
super(node);
|
super(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull @Override public String getName() {
|
@Nullable @Override public String getName() {
|
||||||
SmaliFieldStub stub = getStub();
|
SmaliFieldStub stub = getStub();
|
||||||
if (stub != null) {
|
if (stub != null) {
|
||||||
return stub.getName();
|
return stub.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
SmaliMemberName smaliMemberName = findChildByClass(SmaliMemberName.class);
|
SmaliMemberName smaliMemberName = findChildByClass(SmaliMemberName.class);
|
||||||
assert smaliMemberName != null;
|
if (smaliMemberName == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return smaliMemberName.getText();
|
return smaliMemberName.getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +102,11 @@ public class SmaliField extends SmaliStubBasedPsiElement<SmaliFieldStub> impleme
|
|||||||
return factory.createTypeFromText(type, this);
|
return factory.createTypeFromText(type, this);
|
||||||
}
|
}
|
||||||
PsiTypeElement typeElement = getTypeElement();
|
PsiTypeElement typeElement = getTypeElement();
|
||||||
assert typeElement != null;
|
if (typeElement == null) {
|
||||||
|
// If we don't have a type (i.e. syntax error), use Object as a safe-ish fallback
|
||||||
|
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||||
|
return factory.createTypeByFQClassName("java.lang.Object", getResolveScope());
|
||||||
|
}
|
||||||
return getTypeElement().getType();
|
return getTypeElement().getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,20 +34,21 @@ package org.jf.smalidea.psi.stub;
|
|||||||
import com.intellij.psi.stubs.StubBase;
|
import com.intellij.psi.stubs.StubBase;
|
||||||
import com.intellij.psi.stubs.StubElement;
|
import com.intellij.psi.stubs.StubElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jf.smalidea.psi.SmaliElementTypes;
|
import org.jf.smalidea.psi.SmaliElementTypes;
|
||||||
import org.jf.smalidea.psi.impl.SmaliField;
|
import org.jf.smalidea.psi.impl.SmaliField;
|
||||||
|
|
||||||
public class SmaliFieldStub extends StubBase<SmaliField> {
|
public class SmaliFieldStub extends StubBase<SmaliField> {
|
||||||
@NotNull private final String name;
|
@Nullable private final String name;
|
||||||
@NotNull private final String type;
|
@NotNull private final String type;
|
||||||
|
|
||||||
public SmaliFieldStub(StubElement parent, @NotNull String name, @NotNull String type) {
|
public SmaliFieldStub(StubElement parent, @Nullable String name, @NotNull String type) {
|
||||||
super(parent, SmaliElementTypes.FIELD);
|
super(parent, SmaliElementTypes.FIELD);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull public String getName() {
|
@Nullable public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ import com.intellij.psi.stubs.IndexSink;
|
|||||||
import com.intellij.psi.stubs.StubElement;
|
import com.intellij.psi.stubs.StubElement;
|
||||||
import com.intellij.psi.stubs.StubInputStream;
|
import com.intellij.psi.stubs.StubInputStream;
|
||||||
import com.intellij.psi.stubs.StubOutputStream;
|
import com.intellij.psi.stubs.StubOutputStream;
|
||||||
|
import com.intellij.util.io.StringRef;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jf.smalidea.psi.impl.SmaliField;
|
import org.jf.smalidea.psi.impl.SmaliField;
|
||||||
import org.jf.smalidea.psi.stub.SmaliFieldStub;
|
import org.jf.smalidea.psi.stub.SmaliFieldStub;
|
||||||
@ -73,7 +74,13 @@ public class SmaliFieldElementType extends SmaliStubElementType<SmaliFieldStub,
|
|||||||
|
|
||||||
@NotNull @Override
|
@NotNull @Override
|
||||||
public SmaliFieldStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
|
public SmaliFieldStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
|
||||||
return new SmaliFieldStub(parentStub, dataStream.readName().getString(), dataStream.readName().getString());
|
StringRef nameRef = dataStream.readName();
|
||||||
|
String name = null;
|
||||||
|
if (nameRef != null) {
|
||||||
|
name = nameRef.getString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SmaliFieldStub(parentStub, name, dataStream.readName().getString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void indexStub(@NotNull SmaliFieldStub stub, @NotNull IndexSink sink) {
|
@Override public void indexStub(@NotNull SmaliFieldStub stub, @NotNull IndexSink sink) {
|
||||||
|
1
smalidea/testData/InvalidField.smalidea
Normal file
1
smalidea/testData/InvalidField.smalidea
Normal file
@ -0,0 +1 @@
|
|||||||
|
.field
|
16
smalidea/testData/InvalidField.txt
Normal file
16
smalidea/testData/InvalidField.txt
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
smali.FILE
|
||||||
|
SmaliClass(CLASS)
|
||||||
|
SmaliModifierList(MODIFIER_LIST)
|
||||||
|
<empty list>
|
||||||
|
SmaliExtendsList(EXTENDS_LIST)
|
||||||
|
<empty list>
|
||||||
|
SmaliImplementsList(IMPLEMENTS_LIST)
|
||||||
|
<empty list>
|
||||||
|
SmaliField(FIELD)
|
||||||
|
SmaliModifierList(MODIFIER_LIST)
|
||||||
|
<empty list>
|
||||||
|
PsiElement(FIELD_DIRECTIVE)('.field')
|
||||||
|
PsiElement(ACCESS_LIST)
|
||||||
|
<empty list>
|
||||||
|
PsiErrorElement:no viable alternative at input '<EOF>'
|
||||||
|
<empty list>
|
Loading…
x
Reference in New Issue
Block a user