Search in sources :

Example 1 with MacroParamDescriptor

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

the class MacroParamDocumentationProvider method generateDoc.

@Nullable
@Override
public String generateDoc(PsiElement element, PsiElement originalElement) {
    MacroParamDescriptor macroParamDescriptor;
    MacroCall macroCall;
    if ((macroParamDescriptor = element.getUserData(MACRO_PARAM_DESCRIPTOR_KEY)) == null && element.getNode() != null && element.getNode().getElementType() == OxyTemplateTypes.T_MACRO_PARAM_NAME && (macroCall = PsiTreeUtil.getParentOfType(element, MacroCall.class)) != null) {
        macroParamDescriptor = macroCall.getParamSuggestionSet().getByName(element.getText());
    }
    if (macroParamDescriptor != null) {
        return macroParamDescriptor.generateDoc();
    }
    if (element instanceof FakeDocumentationPsiElement) {
        return generateJsMacroDocumentation(((FakeDocumentationPsiElement) element).getMacro());
    }
    return null;
}
Also used : MacroParamDescriptor(ool.intellij.plugin.psi.macro.param.descriptor.MacroParamDescriptor) MacroCall(ool.intellij.plugin.psi.MacroCall) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with MacroParamDescriptor

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

the class InnerJsTypeEvaluator method getMacroFirstParameterType.

// -------------------------------------------------------------------
@NotNull
private JSType getMacroFirstParameterType(@NotNull JSProperty macro) {
    assert OxyTemplateIndexUtil.isMacro(macro);
    JSTypeSource typeSource = JSTypeSourceFactory.createTypeSource(myContext.targetFile, true);
    List<JSRecordTypeImpl.TypeMember> members = new LinkedList<>();
    for (MacroParamDescriptor paramDescriptor : MacroParamHelper.getJsMacroParamSuggestions(macro, false)) {
        if (!paramDescriptor.isDocumented()) {
            continue;
        }
        JSRecordTypeImpl.PropertySignature signature = new JSRecordTypeImpl.PropertySignatureImpl(paramDescriptor.getName(), paramDescriptor.getType(), !paramDescriptor.isRequired());
        members.add(signature);
    }
    JSRecordTypeImpl type = new JSRecordTypeImpl(typeSource, ImmutableList.copyOf(members));
    type.accept(new SimplifiedClassNameResolver(myContext.targetFile));
    return type;
}
Also used : JSTypeSource(com.intellij.lang.javascript.psi.types.JSTypeSource) MacroParamDescriptor(ool.intellij.plugin.psi.macro.param.descriptor.MacroParamDescriptor) LinkedList(java.util.LinkedList) JSRecordTypeImpl(com.intellij.lang.javascript.psi.types.JSRecordTypeImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with MacroParamDescriptor

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

the class ParamSuggestionProvider method compute.

@Nullable
@Override
public Result<MacroParamSuggestionSet> compute() {
    MacroParamSuggestionSet macroParamSuggestions = getMacroParamSuggestions();
    Set<PsiElement> cacheDependencies = new HashSet<>();
    for (MacroParamDescriptor descriptor : macroParamSuggestions) {
        if (descriptor.getType() == null) {
            continue;
        }
        SimplifiedClassNameResolver simplifiedClassNameResolver = new SimplifiedClassNameResolver(macro.getContainingFile());
        descriptor.getType().accept(simplifiedClassNameResolver);
        cacheDependencies.addAll(simplifiedClassNameResolver.getResolvedClassList());
    }
    cacheDependencies.addAll(this.cacheDependencies);
    return Result.create(macroParamSuggestions, cacheDependencies);
}
Also used : MacroParamSuggestionSet(ool.intellij.plugin.psi.macro.param.MacroParamSuggestionSet) MacroParamDescriptor(ool.intellij.plugin.psi.macro.param.descriptor.MacroParamDescriptor) SimplifiedClassNameResolver(ool.intellij.plugin.psi.reference.innerjs.SimplifiedClassNameResolver) PsiElement(com.intellij.psi.PsiElement) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with MacroParamDescriptor

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

the class MacroParamDocumentationProvider method getDocumentationElementForLookupItem.

@Nullable
@Override
public PsiElement getDocumentationElementForLookupItem(PsiManager psiManager, Object object, PsiElement element) {
    if (object instanceof MacroParamDescriptor) {
        MacroParamDescriptor descriptor = (MacroParamDescriptor) object;
        /**
         * We just need to pass the descriptor attached to some element, that will be ignored by other providers
         */
        element.putUserData(MACRO_PARAM_DESCRIPTOR_KEY, descriptor);
        return element;
    }
    return null;
}
Also used : MacroParamDescriptor(ool.intellij.plugin.psi.macro.param.descriptor.MacroParamDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with MacroParamDescriptor

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

the class MacroParamDocumentationProvider method generateJsMacroDocumentation.

private static String generateJsMacroDocumentation(@NotNull JSProperty macro) {
    JSDocComment comment;
    MacroParamSuggestionSet paramDescriptors = MacroParamHelper.getJsMacroParamSuggestions(macro, false);
    String qualifiedName = OxyTemplateIndexUtil.getMacroFullyQualifiedName(macro);
    assert qualifiedName != null;
    StringBuilder result = new StringBuilder();
    result.append("<PRE><b>").append(qualifiedName).append("</b>(&nbsp;[ optional ] params )\n</PRE> ");
    if ((comment = JSStubBasedPsiTreeUtil.findDocComment(macro)) != null) {
        JSDocPlainCommentBuilder builder = new JSDocPlainCommentBuilder();
        JSDocumentationUtils.processDocumentationTextFromComment(comment.getNode(), builder);
        String doc = builder.getDoc().trim();
        if (doc.length() > 0) {
            result.append(doc).append("<br/>");
        }
    }
    if (paramDescriptors.size() != 0) {
        result.append("<br/><b>").append(I18nSupport.message("macro.param.block.heading")).append("</b><ul>");
        for (MacroParamDescriptor descriptor : paramDescriptors) {
            result.append("<li>").append(descriptor.getName()).append(" ").append(descriptor.generateTypeInfo());
            if (!StringUtil.isEmpty(descriptor.getDocText())) {
                result.append(" - ").append(descriptor.getDocText());
            }
            result.append("</li>");
        }
        result.append("</ul>");
    }
    return result.toString();
}
Also used : JSDocComment(com.intellij.lang.javascript.psi.jsdoc.JSDocComment) MacroParamSuggestionSet(ool.intellij.plugin.psi.macro.param.MacroParamSuggestionSet) MacroParamDescriptor(ool.intellij.plugin.psi.macro.param.descriptor.MacroParamDescriptor)

Aggregations

MacroParamDescriptor (ool.intellij.plugin.psi.macro.param.descriptor.MacroParamDescriptor)5 Nullable (org.jetbrains.annotations.Nullable)3 MacroParamSuggestionSet (ool.intellij.plugin.psi.macro.param.MacroParamSuggestionSet)2 JSDocComment (com.intellij.lang.javascript.psi.jsdoc.JSDocComment)1 JSRecordTypeImpl (com.intellij.lang.javascript.psi.types.JSRecordTypeImpl)1 JSTypeSource (com.intellij.lang.javascript.psi.types.JSTypeSource)1 PsiElement (com.intellij.psi.PsiElement)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 MacroCall (ool.intellij.plugin.psi.MacroCall)1 SimplifiedClassNameResolver (ool.intellij.plugin.psi.reference.innerjs.SimplifiedClassNameResolver)1 NotNull (org.jetbrains.annotations.NotNull)1