Search in sources :

Example 1 with JavaMacroParamDescriptor

use of ool.intellij.plugin.psi.macro.param.descriptor.JavaMacroParamDescriptor in project oxy-template-support-plugin by mutant-industries.

the class JavaMacroParamSuggestionProvider method getParamsPulledFromParamHelper.

private MacroParamSuggestionSet getParamsPulledFromParamHelper(PsiLocalVariable paramHelper) {
    MacroParamSuggestionSet params = new MacroParamSuggestionSet();
    PsiReferenceExpression methodReference;
    for (PsiReference reference : ReferencesSearch.search(paramHelper).findAll()) {
        if ((methodReference = PsiTreeUtil.getParentOfType(reference.getElement(), PsiReferenceExpression.class)) != null) {
            String parameterName = null;
            boolean required = false;
            boolean notNull = true;
            String type = JSCommonTypeNames.ANY_TYPE_NAME;
            String defaultValue = null;
            while (methodReference != null) {
                if (!(methodReference.getParent() instanceof PsiMethodCallExpression) || methodReference.getReferenceName() == null) {
                    break;
                }
                PsiMethodCallExpression callExpression = (PsiMethodCallExpression) methodReference.getParent();
                PsiExpression[] expressions = callExpression.getArgumentList().getExpressions();
                if (expressions.length == 0) {
                    break;
                }
                switch(methodReference.getReferenceName()) {
                    case "parameter":
                    case "pullParameter":
                        parameterName = getExpressionValue(expressions[0]);
                        if (expressions.length == 2 && expressions[1].getFirstChild() instanceof PsiTypeElement) {
                            type = InnerJsJavaTypeConverter.modifyCollectionType(((PsiTypeElement) expressions[1].getFirstChild()).getType(), paramHelper.getProject());
                        }
                        break;
                    case "pullIntegerValue":
                        parameterName = getExpressionValue(expressions[0]);
                        notNull = expressions.length < 2;
                        required = expressions.length < 2;
                        type = JSCommonTypeNames.NUMBER_TYPE_NAME;
                        if (expressions.length == 2) {
                            defaultValue = getExpressionValue(expressions[1]);
                        }
                        break;
                    case "pullBooleanValue":
                        parameterName = getExpressionValue(expressions[0]);
                        notNull = false;
                        required = false;
                        type = JSCommonTypeNames.BOOLEAN_TYPE_NAME;
                        if (expressions.length == 2) {
                            defaultValue = getExpressionValue(expressions[1]);
                        }
                        break;
                    case "setNonNull":
                        notNull = Boolean.valueOf(expressions[0].getText());
                        break;
                    case "setRequired":
                        required = Boolean.valueOf(expressions[0].getText());
                        break;
                }
                methodReference = PsiTreeUtil.getParentOfType(methodReference, PsiReferenceExpression.class);
            }
            if (parameterName != null) {
                params.add(new JavaMacroParamDescriptor(parameterName, macro, notNull, required, type, defaultValue));
            }
        }
    // TODO the case when object is passed to another method
    }
    return params;
}
Also used : MacroParamSuggestionSet(ool.intellij.plugin.psi.macro.param.MacroParamSuggestionSet) PsiExpression(com.intellij.psi.PsiExpression) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiTypeElement(com.intellij.psi.PsiTypeElement) PsiReference(com.intellij.psi.PsiReference) JavaMacroParamDescriptor(ool.intellij.plugin.psi.macro.param.descriptor.JavaMacroParamDescriptor) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression)

Aggregations

PsiExpression (com.intellij.psi.PsiExpression)1 PsiMethodCallExpression (com.intellij.psi.PsiMethodCallExpression)1 PsiReference (com.intellij.psi.PsiReference)1 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)1 PsiTypeElement (com.intellij.psi.PsiTypeElement)1 MacroParamSuggestionSet (ool.intellij.plugin.psi.macro.param.MacroParamSuggestionSet)1 JavaMacroParamDescriptor (ool.intellij.plugin.psi.macro.param.descriptor.JavaMacroParamDescriptor)1