mirror of
https://github.com/revanced/smali.git
synced 2025-06-13 12:37:37 +02:00
Move the return type to the MethodPrototype stub
This commit is contained in:
@ -98,24 +98,13 @@ public class SmaliMethod extends SmaliStubBasedPsiElement<SmaliMethodStub>
|
||||
}
|
||||
|
||||
@Nullable @Override public PsiType getReturnType() {
|
||||
SmaliMethodStub stub = getStub();
|
||||
if (stub != null) {
|
||||
String returnType = stub.getReturnType();
|
||||
if (returnType == null) {
|
||||
return null;
|
||||
}
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||
return factory.createTypeByFQClassName(returnType, getResolveScope());
|
||||
}
|
||||
PsiTypeElement returnTypeElement = getReturnTypeElement();
|
||||
if (returnTypeElement == null) {
|
||||
return null;
|
||||
}
|
||||
return returnTypeElement.getType();
|
||||
if (isConstructor()) return null;
|
||||
return getMethodPrototype().getReturnType();
|
||||
}
|
||||
|
||||
@Nullable @Override public PsiTypeElement getReturnTypeElement() {
|
||||
return getMethodPrototype().getReturnType();
|
||||
if (isConstructor()) return null;
|
||||
return getMethodPrototype().getReturnTypeElement();
|
||||
}
|
||||
|
||||
@NotNull @Override public SmaliMethodParamList getParameterList() {
|
||||
|
@ -32,6 +32,9 @@
|
||||
package org.jf.smalidea.psi.impl;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiElementFactory;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.PsiTypeElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -48,7 +51,25 @@ public class SmaliMethodPrototype extends SmaliStubBasedPsiElement<SmaliMethodPr
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiTypeElement getReturnType() {
|
||||
public PsiType getReturnType() {
|
||||
SmaliMethodPrototypeStub stub = getStub();
|
||||
if (stub != null) {
|
||||
String returnType = stub.getReturnType();
|
||||
if (returnType == null) {
|
||||
return null;
|
||||
}
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||
return factory.createTypeByFQClassName(returnType, getResolveScope());
|
||||
}
|
||||
|
||||
PsiTypeElement returnTypeElement = getReturnTypeElement();
|
||||
if (returnTypeElement == null) {
|
||||
return null;
|
||||
}
|
||||
return returnTypeElement.getType();
|
||||
}
|
||||
|
||||
@Nullable public PsiTypeElement getReturnTypeElement() {
|
||||
return findChildByClass(PsiTypeElement.class);
|
||||
}
|
||||
|
||||
|
@ -34,11 +34,19 @@ 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.SmaliMethodPrototype;
|
||||
|
||||
public class SmaliMethodPrototypeStub extends StubBase<SmaliMethodPrototype> {
|
||||
public SmaliMethodPrototypeStub(@NotNull StubElement parent) {
|
||||
@Nullable private final String returnType;
|
||||
|
||||
public SmaliMethodPrototypeStub(@NotNull StubElement parent, @Nullable String returnType) {
|
||||
super(parent, SmaliElementTypes.METHOD_PROTOTYPE);
|
||||
this.returnType = returnType;
|
||||
}
|
||||
|
||||
@Nullable public String getReturnType() {
|
||||
return returnType;
|
||||
}
|
||||
}
|
||||
|
@ -41,19 +41,13 @@ import javax.annotation.Nullable;
|
||||
|
||||
public class SmaliMethodStub extends StubBase<SmaliMethod> {
|
||||
@Nullable private final String name;
|
||||
@Nullable private final String returnType;
|
||||
|
||||
public SmaliMethodStub(@NotNull StubElement parent, @Nullable String name, @Nullable String returnType) {
|
||||
public SmaliMethodStub(@NotNull StubElement parent, @Nullable String name) {
|
||||
super(parent, SmaliElementTypes.METHOD);
|
||||
this.name = name;
|
||||
this.returnType = returnType;
|
||||
}
|
||||
|
||||
@Nullable public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Nullable public String getReturnType() {
|
||||
return returnType;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,6 @@
|
||||
package org.jf.smalidea.psi.stub.element;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.stubs.IndexSink;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.psi.stubs.StubInputStream;
|
||||
@ -64,29 +63,18 @@ public class SmaliMethodElementType extends SmaliStubElementType<SmaliMethodStub
|
||||
}
|
||||
|
||||
@Override public SmaliMethodStub createStub(@NotNull SmaliMethod psi, StubElement parentStub) {
|
||||
String returnTypeText = null;
|
||||
PsiType returnType = psi.getReturnType();
|
||||
if (returnType != null) {
|
||||
returnTypeText = returnType.getCanonicalText();
|
||||
}
|
||||
return new SmaliMethodStub(parentStub, psi.getName(), returnTypeText);
|
||||
return new SmaliMethodStub(parentStub, psi.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(@NotNull SmaliMethodStub stub, @NotNull StubOutputStream dataStream) throws IOException {
|
||||
dataStream.writeName(stub.getName());
|
||||
dataStream.writeName(stub.getReturnType());
|
||||
}
|
||||
|
||||
@NotNull @Override
|
||||
public SmaliMethodStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
|
||||
StringRef methodNameRef = dataStream.readName();
|
||||
StringRef returnTypeRef = dataStream.readName();
|
||||
String returnType = null;
|
||||
if (returnTypeRef != null) {
|
||||
returnType = returnTypeRef.getString();
|
||||
}
|
||||
return new SmaliMethodStub(parentStub, methodNameRef.getString(), returnType);
|
||||
return new SmaliMethodStub(parentStub, methodNameRef.getString());
|
||||
}
|
||||
|
||||
@Override public void indexStub(@NotNull SmaliMethodStub stub, @NotNull IndexSink sink) {
|
||||
|
@ -32,10 +32,12 @@
|
||||
package org.jf.smalidea.psi.stub.element;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiType;
|
||||
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.SmaliMethodPrototype;
|
||||
import org.jf.smalidea.psi.stub.SmaliMethodPrototypeStub;
|
||||
@ -63,18 +65,30 @@ public class SmaliMethodPrototypeElementType
|
||||
}
|
||||
|
||||
@Override public SmaliMethodPrototypeStub createStub(@NotNull SmaliMethodPrototype psi, StubElement parentStub) {
|
||||
return new SmaliMethodPrototypeStub(parentStub);
|
||||
PsiType returnType = psi.getReturnType();
|
||||
String returnTypeText = null;
|
||||
if (returnType != null) {
|
||||
returnTypeText = returnType.getCanonicalText();
|
||||
}
|
||||
|
||||
return new SmaliMethodPrototypeStub(parentStub, returnTypeText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(@NotNull SmaliMethodPrototypeStub stub, @NotNull StubOutputStream dataStream)
|
||||
throws IOException {
|
||||
dataStream.writeName(stub.getReturnType());
|
||||
}
|
||||
|
||||
@NotNull @Override
|
||||
public SmaliMethodPrototypeStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub)
|
||||
throws IOException {
|
||||
return new SmaliMethodPrototypeStub(parentStub);
|
||||
StringRef returnTypeRef = dataStream.readName();
|
||||
String returnType = null;
|
||||
if (returnTypeRef != null) {
|
||||
returnType = returnTypeRef.getString();
|
||||
}
|
||||
return new SmaliMethodPrototypeStub(parentStub, returnType);
|
||||
}
|
||||
|
||||
@Override public void indexStub(@NotNull SmaliMethodPrototypeStub stub, @NotNull IndexSink sink) {
|
||||
|
Reference in New Issue
Block a user