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);
}
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);
}
}
}
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));
}
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);
}
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);
});
}
Aggregations