diff --git a/smalidea/src/main/antlr3/smalideaParser.g b/smalidea/src/main/antlr3/smalideaParser.g index 00c7d095..823046a5 100644 --- a/smalidea/src/main/antlr3/smalideaParser.g +++ b/smalidea/src/main/antlr3/smalideaParser.g @@ -494,14 +494,24 @@ fixed_literal | bool_literal; annotation_element - @init { Marker marker = mark(); } - : simple_name EQUAL literal; + @init { + Marker marker = mark(); + Marker nameMarker = null; + } + : { nameMarker = mark(); } simple_name { nameMarker.done(SmaliElementTypes.ANNOTATION_ELEMENT_NAME); } + EQUAL literal; finally { marker.done(SmaliElementTypes.ANNOTATION_ELEMENT); } annotation - @init { Marker marker = mark(); } + @init { + Marker marker = mark(); + Marker paramListMarker = null; + } : ANNOTATION_DIRECTIVE ANNOTATION_VISIBILITY class_descriptor - annotation_element* END_ANNOTATION_DIRECTIVE; + { paramListMarker = mark(); } + annotation_element* + { paramListMarker.done(SmaliElementTypes.ANNOTATION_PARAMETER_LIST); } + END_ANNOTATION_DIRECTIVE; finally { marker.done(SmaliElementTypes.ANNOTATION); } fully_qualified_method diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/SmaliElementTypes.java b/smalidea/src/main/java/org/jf/smalidea/psi/SmaliElementTypes.java index 69fa07b3..c4a46c37 100644 --- a/smalidea/src/main/java/org/jf/smalidea/psi/SmaliElementTypes.java +++ b/smalidea/src/main/java/org/jf/smalidea/psi/SmaliElementTypes.java @@ -68,8 +68,12 @@ public class SmaliElementTypes { new SmaliCompositeElementType("FIELD_INITIALIZER", SmaliFieldInitializer.FACTORY); public static final SmaliCompositeElementType INSTRUCTION = new SmaliCompositeElementType("INSTRUCTION", SmaliInstruction.FACTORY); + public static final SmaliCompositeElementType ANNOTATION_PARAMETER_LIST = + new SmaliCompositeElementType("ANNOTATION_PARAMETER_LIST", SmaliAnnotationParameterList.FACTORY); public static final SmaliCompositeElementType ANNOTATION_ELEMENT = new SmaliCompositeElementType("ANNOTATION_ELEMENT", SmaliAnnotationElement.FACTORY); + public static final SmaliCompositeElementType ANNOTATION_ELEMENT_NAME = + new SmaliCompositeElementType("ANNOTATION_ELEMENT_NAME", SmaliAnnotationElementName.FACTORY); public static final SmaliCompositeElementType FIELD_REFERENCE = new SmaliCompositeElementType("FIELD_REFERENCE", SmaliFieldReference.FACTORY); public static final SmaliCompositeElementType METHOD_REFERENCE = diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/impl/LightSmaliClassTypeElement.java b/smalidea/src/main/java/org/jf/smalidea/psi/impl/LightSmaliClassTypeElement.java index 49353420..2186f1c0 100644 --- a/smalidea/src/main/java/org/jf/smalidea/psi/impl/LightSmaliClassTypeElement.java +++ b/smalidea/src/main/java/org/jf/smalidea/psi/impl/LightSmaliClassTypeElement.java @@ -34,6 +34,7 @@ package org.jf.smalidea.psi.impl; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.impl.light.LightElement; +import com.intellij.psi.scope.PsiScopeProcessor; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -41,7 +42,8 @@ import org.jetbrains.annotations.Nullable; import org.jf.smalidea.SmaliLanguage; import org.jf.smalidea.util.NameUtils; -public class LightSmaliClassTypeElement extends LightElement implements PsiTypeElement, PsiReference { +public class LightSmaliClassTypeElement extends LightElement + implements PsiTypeElement, PsiReference, PsiJavaCodeReferenceElement { @NotNull private final String qualifiedName; @@ -58,9 +60,8 @@ public class LightSmaliClassTypeElement extends LightElement implements PsiTypeE return new SmaliClassType(this); } - @Nullable @Override public PsiJavaCodeReferenceElement getInnermostComponentReferenceElement() { - // Not applicable for smali - return null; + @Nullable @Override public LightSmaliClassTypeElement getInnermostComponentReferenceElement() { + return this; } @Override public String getText() { @@ -84,8 +85,6 @@ public class LightSmaliClassTypeElement extends LightElement implements PsiTypeE return facade.findClass(getCanonicalText(), getResolveScope()); } - - @NotNull @Override public String getCanonicalText() { return qualifiedName; } @@ -128,4 +127,55 @@ public class LightSmaliClassTypeElement extends LightElement implements PsiTypeE @NotNull @Override public PsiAnnotation addAnnotation(@NotNull @NonNls String qualifiedName) { throw new UnsupportedOperationException(); } + + // *************************************************************************** + // Below are the PsiJavaCodeReferenceElement-specific methods + + @Override public void processVariants(@NotNull PsiScopeProcessor processor) { + // TODO: maybe just do nothing? + throw new UnsupportedOperationException(); + } + + @Nullable @Override public PsiElement getReferenceNameElement() { + // TODO: implement if needed + throw new UnsupportedOperationException(); + } + + @Nullable @Override public PsiReferenceParameterList getParameterList() { + // TODO: (generics) implement this + return null; + } + + @NotNull @Override public PsiType[] getTypeParameters() { + // TODO: (generics) implement this + return new PsiType[0]; + } + + @Override public boolean isQualified() { + // TODO: should this return false for classes in the top level package? + return true; + } + + @Override public String getQualifiedName() { + return getCanonicalText(); + } + + @NotNull @Override public JavaResolveResult advancedResolve(boolean incompleteCode) { + // TODO: implement this if needed + throw new UnsupportedOperationException(); + } + + @NotNull @Override public JavaResolveResult[] multiResolve(boolean incompleteCode) { + // TODO: implement this if needed + throw new UnsupportedOperationException(); + } + + @Nullable @Override public PsiElement getQualifier() { + // TODO: implement this if needed + throw new UnsupportedOperationException(); + } + + @Nullable @Override public String getReferenceName() { + return getName(); + } } diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliAnnotation.java b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliAnnotation.java index 291f04c2..916a00a3 100644 --- a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliAnnotation.java +++ b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliAnnotation.java @@ -33,6 +33,7 @@ package org.jf.smalidea.psi.impl; import com.intellij.lang.ASTNode; import com.intellij.psi.*; +import com.intellij.psi.impl.PsiImplUtil; import com.intellij.psi.meta.PsiMetaData; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -49,15 +50,19 @@ public class SmaliAnnotation extends SmaliStubBasedPsiElement T setDeclaredAttributeValue(@Nullable @NonNls String attributeName, @Nullable T value) { - return null; + public T setDeclaredAttributeValue( + @Nullable @NonNls String attributeName, @Nullable T value) { + // TODO: implement this + throw new UnsupportedOperationException(); } @Nullable @Override public PsiAnnotationOwner getOwner() { + return (PsiAnnotationOwner)getParent(); + } + + @Nullable @Override public PsiMetaData getMetaData() { + // I have no idea what this is return null; } } diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliAnnotationElement.java b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliAnnotationElement.java index dec1a1a6..6137af0b 100644 --- a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliAnnotationElement.java +++ b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliAnnotationElement.java @@ -31,10 +31,16 @@ package org.jf.smalidea.psi.impl; +import com.intellij.psi.PsiAnnotationMemberValue; +import com.intellij.psi.PsiNameValuePair; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jf.smalidea.psi.SmaliCompositeElementFactory; import org.jf.smalidea.psi.SmaliElementTypes; -public class SmaliAnnotationElement extends SmaliCompositeElement { +public class SmaliAnnotationElement extends SmaliCompositeElement implements PsiNameValuePair { + // TODO: consider making this a stub + public static final SmaliCompositeElementFactory FACTORY = new SmaliCompositeElementFactory() { @Override public SmaliCompositeElement createElement() { return new SmaliAnnotationElement(); @@ -44,4 +50,31 @@ public class SmaliAnnotationElement extends SmaliCompositeElement { public SmaliAnnotationElement() { super(SmaliElementTypes.ANNOTATION_ELEMENT); } + + @Override public String getName() { + SmaliAnnotationElementName identifier = getNameIdentifier(); + if (identifier != null) { + return identifier.getName(); + } + return null; + } + + @Nullable @Override public SmaliAnnotationElementName getNameIdentifier() { + return findChildByClass(SmaliAnnotationElementName.class); + } + + @Nullable @Override public SmaliLiteral getValue() { + // TODO: implement the various psi expression classes that would be expected in the java stuff. Is SmaliLiteral implementing PsiLiteral and PsiExpression enough? What about method/field/enum literals? + return findChildByClass(SmaliLiteral.class); + } + + @NotNull @Override public PsiAnnotationMemberValue setValue(@NotNull PsiAnnotationMemberValue newValue) { + // TODO: implement this + throw new UnsupportedOperationException(); + } + + @Nullable @Override public String getLiteralValue() { + // Not applicable for smali + return null; + } } diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliAnnotationElementName.java b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliAnnotationElementName.java new file mode 100644 index 00000000..1800830c --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliAnnotationElementName.java @@ -0,0 +1,57 @@ +/* + * 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.psi.PsiIdentifier; +import com.intellij.psi.tree.IElementType; +import org.jf.smalidea.psi.SmaliCompositeElementFactory; +import org.jf.smalidea.psi.SmaliElementTypes; + +public class SmaliAnnotationElementName extends SmaliCompositeElement implements PsiIdentifier { + public static final SmaliCompositeElementFactory FACTORY = new SmaliCompositeElementFactory() { + @Override public SmaliCompositeElement createElement() { + return new SmaliAnnotationElementName(); + } + }; + + public SmaliAnnotationElementName() { + super(SmaliElementTypes.ANNOTATION_ELEMENT_NAME); + } + + @Override public IElementType getTokenType() { + return getNode().getElementType(); + } + + @Override public String getName() { + return getText(); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliAnnotationParameterList.java b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliAnnotationParameterList.java new file mode 100644 index 00000000..7feaa9ee --- /dev/null +++ b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliAnnotationParameterList.java @@ -0,0 +1,53 @@ +/* + * 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.psi.PsiAnnotationParameterList; +import org.jetbrains.annotations.NotNull; +import org.jf.smalidea.psi.SmaliCompositeElementFactory; +import org.jf.smalidea.psi.SmaliElementTypes; + +public class SmaliAnnotationParameterList extends SmaliCompositeElement implements PsiAnnotationParameterList { + public static final SmaliCompositeElementFactory FACTORY = new SmaliCompositeElementFactory() { + @Override public SmaliCompositeElement createElement() { + return new SmaliAnnotationParameterList(); + } + }; + + public SmaliAnnotationParameterList() { + super(SmaliElementTypes.ANNOTATION_PARAMETER_LIST); + } + + @NotNull @Override public SmaliAnnotationElement[] getAttributes() { + return findChildrenByClass(SmaliAnnotationElement.class); + } +} diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliBaseReferenceList.java b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliBaseReferenceList.java index baf090e5..686be4a7 100644 --- a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliBaseReferenceList.java +++ b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliBaseReferenceList.java @@ -34,7 +34,6 @@ package org.jf.smalidea.psi.impl; import com.google.common.collect.Lists; import com.intellij.extapi.psi.StubBasedPsiElementBase; import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiJavaCodeReferenceElement; import com.intellij.psi.PsiReferenceList; import com.intellij.psi.StubBasedPsiElement; import com.intellij.psi.stubs.IStubElementType; @@ -59,7 +58,7 @@ public abstract class SmaliBaseReferenceList { - public SmaliAnnotationStub(StubElement parent) { + @Nullable + private final String annotationType; + + public SmaliAnnotationStub(StubElement parent, @Nullable String annotationType) { super(parent, SmaliElementTypes.ANNOTATION); + this.annotationType = annotationType; + } + + @Nullable + public String getAnnotationType() { + return annotationType; } } diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/stub/element/SmaliAnnotationElementType.java b/smalidea/src/main/java/org/jf/smalidea/psi/stub/element/SmaliAnnotationElementType.java index bdeb8cec..86f8a7c1 100644 --- a/smalidea/src/main/java/org/jf/smalidea/psi/stub/element/SmaliAnnotationElementType.java +++ b/smalidea/src/main/java/org/jf/smalidea/psi/stub/element/SmaliAnnotationElementType.java @@ -62,16 +62,17 @@ public class SmaliAnnotationElementType extends SmaliStubElementType