mirror of
https://github.com/revanced/smali.git
synced 2025-05-02 23:54:38 +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
|
||||
access_list
|
||||
member_name COLON nonvoid_type_descriptor
|
||||
member_name colon nonvoid_type_descriptor
|
||||
field_initializer?
|
||||
( END_FIELD_DIRECTIVE
|
||||
( end_field_directive
|
||||
| (ANNOTATION_DIRECTIVE)=> ( {annotationsMarker = mark();}
|
||||
((ANNOTATION_DIRECTIVE)=> annotation)+
|
||||
(END_FIELD_DIRECTIVE {classAnnotations = false;})?
|
||||
(end_field_directive {classAnnotations = false;})?
|
||||
)
|
||||
| /*epsilon*/
|
||||
)
|
||||
@ -300,11 +300,19 @@ field
|
||||
}
|
||||
};
|
||||
catch [RecognitionException re] {
|
||||
annotationsMarker.drop();
|
||||
if (annotationsMarker != null) {
|
||||
annotationsMarker.drop();
|
||||
}
|
||||
recover(input, re);
|
||||
reportError(marker, re, false);
|
||||
}
|
||||
|
||||
colon
|
||||
: COLON;
|
||||
|
||||
end_field_directive
|
||||
: END_FIELD_DIRECTIVE;
|
||||
|
||||
field_initializer
|
||||
@init { Marker marker = mark(); }
|
||||
: EQUAL literal
|
||||
|
@ -44,8 +44,6 @@ import org.jf.smalidea.psi.SmaliElementTypes;
|
||||
import org.jf.smalidea.psi.iface.SmaliModifierListOwner;
|
||||
import org.jf.smalidea.psi.stub.SmaliFieldStub;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class SmaliField extends SmaliStubBasedPsiElement<SmaliFieldStub> implements PsiField, SmaliModifierListOwner {
|
||||
public SmaliField(@NotNull SmaliFieldStub stub) {
|
||||
super(stub, SmaliElementTypes.FIELD);
|
||||
@ -55,14 +53,16 @@ public class SmaliField extends SmaliStubBasedPsiElement<SmaliFieldStub> impleme
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Nonnull @Override public String getName() {
|
||||
@Nullable @Override public String getName() {
|
||||
SmaliFieldStub stub = getStub();
|
||||
if (stub != null) {
|
||||
return stub.getName();
|
||||
}
|
||||
|
||||
SmaliMemberName smaliMemberName = findChildByClass(SmaliMemberName.class);
|
||||
assert smaliMemberName != null;
|
||||
if (smaliMemberName == null) {
|
||||
return null;
|
||||
}
|
||||
return smaliMemberName.getText();
|
||||
}
|
||||
|
||||
@ -102,7 +102,11 @@ public class SmaliField extends SmaliStubBasedPsiElement<SmaliFieldStub> impleme
|
||||
return factory.createTypeFromText(type, this);
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -34,20 +34,21 @@ package org.jf.smalidea.psi.stub;
|
||||
import com.intellij.psi.stubs.StubBase;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jf.smalidea.psi.SmaliElementTypes;
|
||||
import org.jf.smalidea.psi.impl.SmaliField;
|
||||
|
||||
public class SmaliFieldStub extends StubBase<SmaliField> {
|
||||
@NotNull private final String name;
|
||||
@Nullable private final String name;
|
||||
@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);
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@NotNull public String getName() {
|
||||
@Nullable public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
@ -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.SmaliField;
|
||||
import org.jf.smalidea.psi.stub.SmaliFieldStub;
|
||||
@ -73,7 +74,13 @@ public class SmaliFieldElementType extends SmaliStubElementType<SmaliFieldStub,
|
||||
|
||||
@NotNull @Override
|
||||
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) {
|
||||
|
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