Search in sources :

Example 6 with LightMethodBuilder

use of com.intellij.psi.impl.light.LightMethodBuilder in project smali by JesusFreke.

the class SmaliMethodReference method resolve.

@Nullable
@Override
public PsiElement resolve() {
    PsiClass containingClass = getContainingClass();
    if (containingClass == null) {
        return null;
    }
    SmaliMemberName memberName = getMemberName();
    if (memberName == null) {
        return null;
    }
    LightMethodBuilder pattern = new LightMethodBuilder(getManager(), SmaliLanguage.INSTANCE, memberName.getText());
    for (PsiType type : getParameterTypes()) {
        pattern.addParameter("", type);
    }
    SmaliTypeElement returnTypeElement = getReturnType();
    if (returnTypeElement == null) {
        return null;
    }
    pattern.setMethodReturnType(returnTypeElement.getType());
    // TODO: what about static constructor?
    pattern.setConstructor(memberName.getText().equals("<init>"));
    return containingClass.findMethodBySignature(pattern, true);
}
Also used : LightMethodBuilder(com.intellij.psi.impl.light.LightMethodBuilder) PsiClass(com.intellij.psi.PsiClass) PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with LightMethodBuilder

use of com.intellij.psi.impl.light.LightMethodBuilder in project intellij-community by JetBrains.

the class TransformationContextImpl method doAddMethod.

private void doAddMethod(@NotNull PsiMethod method, boolean prepend) {
    if (method instanceof GrLightMethodBuilder) {
        ((GrLightMethodBuilder) method).setContainingClass(myCodeClass);
    } else if (method instanceof LightMethodBuilder) {
        ((LightMethodBuilder) method).setContainingClass(myCodeClass);
    }
    MethodSignature signature = method.getSignature(PsiSubstitutor.EMPTY);
    Set<MethodSignature> signatures = mySignaturesCache.get(method.getName());
    if (signatures.add(signature)) {
        if (prepend) {
            myMethods.addFirst(method);
        } else {
            myMethods.addLast(method);
        }
    }
}
Also used : MethodSignature(com.intellij.psi.util.MethodSignature) LightMethodBuilder(com.intellij.psi.impl.light.LightMethodBuilder) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)

Example 8 with LightMethodBuilder

use of com.intellij.psi.impl.light.LightMethodBuilder in project intellij-community by JetBrains.

the class BaseScriptTransformationSupport method applyTransformation.

@Override
public void applyTransformation(@NotNull TransformationContext context) {
    if (!(context.getCodeClass() instanceof GroovyScriptClass))
        return;
    GroovyScriptClass scriptClass = (GroovyScriptClass) context.getCodeClass();
    LightMethodBuilder mainMethod = new LightMethodBuilder(scriptClass.getManager(), GroovyLanguage.INSTANCE, "main").setMethodReturnType(PsiType.VOID).addParameter("args", new PsiArrayType(PsiType.getJavaLangString(scriptClass.getManager(), scriptClass.getResolveScope()))).addModifiers(PsiModifier.PUBLIC, PsiModifier.STATIC);
    LightMethodBuilder runMethod = new LightMethodBuilder(scriptClass.getManager(), GroovyLanguage.INSTANCE, "run").setMethodReturnType(TypesUtil.getJavaLangObject(scriptClass)).addModifier(PsiModifier.PUBLIC);
    context.addMethod(runMethod, true);
    context.addMethod(mainMethod, true);
    context.setSuperType(getBaseClassType(scriptClass));
}
Also used : GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) LightMethodBuilder(com.intellij.psi.impl.light.LightMethodBuilder) PsiArrayType(com.intellij.psi.PsiArrayType)

Example 9 with LightMethodBuilder

use of com.intellij.psi.impl.light.LightMethodBuilder in project intellij-community by JetBrains.

the class BindableTransformationSupport method applyTransformation.

@Override
public void applyTransformation(@NotNull TransformationContext context) {
    GrTypeDefinition clazz = context.getCodeClass();
    if (!isApplicable(clazz))
        return;
    final PsiManager manager = clazz.getManager();
    final GlobalSearchScope scope = clazz.getResolveScope();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(clazz.getProject());
    final PsiType pclType = facade.getElementFactory().createTypeByFQClassName(PCL_FQN, scope);
    final PsiArrayType pclArrayType = new PsiArrayType(pclType);
    final PsiType stringType = PsiType.getJavaLangString(manager, scope);
    final PsiType objectType = PsiType.getJavaLangObject(manager, scope);
    final List<LightMethodBuilder> methods = ContainerUtil.newArrayList();
    methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "addPropertyChangeListener").setMethodReturnType(PsiType.VOID).addParameter("listener", pclType));
    methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "addPropertyChangeListener").setMethodReturnType(PsiType.VOID).addParameter("name", stringType).addParameter("listener", pclType));
    methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "removePropertyChangeListener").setMethodReturnType(PsiType.VOID).addParameter("listener", pclType));
    methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "removePropertyChangeListener").setMethodReturnType(PsiType.VOID).addParameter("name", stringType).addParameter("listener", pclType));
    methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "firePropertyChange").setMethodReturnType(PsiType.VOID).addParameter("name", stringType).addParameter("oldValue", objectType).addParameter("newValue", objectType));
    methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "getPropertyChangeListeners").setMethodReturnType(pclArrayType));
    methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "getPropertyChangeListeners").setMethodReturnType(pclArrayType).addParameter("name", stringType));
    for (LightMethodBuilder method : methods) {
        method.addModifier(PsiModifier.PUBLIC);
        method.setOriginInfo(ORIGIN_INFO);
        method.putUserData(DOCUMENTATION_DELEGATE_FQN, PCS_FQN);
    }
    context.addMethods(methods);
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) LightMethodBuilder(com.intellij.psi.impl.light.LightMethodBuilder)

Example 10 with LightMethodBuilder

use of com.intellij.psi.impl.light.LightMethodBuilder in project intellij-community by JetBrains.

the class GrEnumTypeDefinitionImpl method getDefEnumMethods.

private PsiMethod[] getDefEnumMethods() {
    return CachedValuesManager.getCachedValue(this, () -> {
        PsiMethod[] defMethods = new PsiMethod[4];
        final PsiManagerEx manager = getManager();
        final PsiElementFactory factory = JavaPsiFacade.getElementFactory(getProject());
        defMethods[0] = new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "values").setMethodReturnType(factory.createTypeFromText(CommonClassNames.JAVA_UTIL_COLLECTION + "<" + getName() + ">", this)).setContainingClass(this).addModifier(PsiModifier.PUBLIC).addModifier(PsiModifier.STATIC);
        defMethods[1] = new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "next").setMethodReturnType(factory.createType(this)).setContainingClass(this).addModifier(PsiModifier.PUBLIC);
        defMethods[2] = new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "previous").setMethodReturnType(factory.createType(this)).setContainingClass(this).addModifier(PsiModifier.PUBLIC);
        defMethods[3] = new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "valueOf").setMethodReturnType(factory.createType(this)).setContainingClass(this).addParameter("name", CommonClassNames.JAVA_LANG_STRING).addModifier(PsiModifier.PUBLIC).addModifier(PsiModifier.STATIC);
        return CachedValueProvider.Result.create(defMethods, this);
    });
}
Also used : LightMethodBuilder(com.intellij.psi.impl.light.LightMethodBuilder) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Aggregations

LightMethodBuilder (com.intellij.psi.impl.light.LightMethodBuilder)12 NotNull (org.jetbrains.annotations.NotNull)3 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)2 GroovyScriptClass (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass)2 ReflectedProject (com.intellij.lang.ant.ReflectedProject)1 Project (com.intellij.openapi.project.Project)1 PsiArrayType (com.intellij.psi.PsiArrayType)1 PsiClass (com.intellij.psi.PsiClass)1 PsiType (com.intellij.psi.PsiType)1 PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 MethodSignature (com.intellij.psi.util.MethodSignature)1 IOException (java.io.IOException)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1 Nullable (org.jetbrains.annotations.Nullable)1 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)1 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)1 GrAnnotationMemberValue (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue)1 GrLightMethodBuilder (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)1