Search in sources :

Example 1 with MacroCall

use of ool.intellij.plugin.psi.MacroCall 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 MacroCall

use of ool.intellij.plugin.psi.MacroCall in project oxy-template-support-plugin by mutant-industries.

the class InnerJsTypeEvaluator method checkForEachDefinition.

// -----------------------------------------------------------------------------------------------------------------
@Nullable
private static JSType checkForEachDefinition(@NotNull final PsiElement element) {
    PsiElement elementLocal = element;
    if (elementLocal.getParent() instanceof JSVarStatement) {
        elementLocal = elementLocal.getParent();
    }
    // repeat macro - var keyword is missing
    if (elementLocal instanceof PsiPackage || !(elementLocal.getFirstChild() instanceof JSVariable)) {
        return null;
    }
    PsiElement elementAt = elementLocal.getContainingFile().getViewProvider().findElementAt(elementLocal.getNode().getStartOffset(), OxyTemplate.INSTANCE);
    assert elementAt != null;
    MacroAttribute attribute = PsiTreeUtil.getParentOfType(elementAt, MacroAttribute.class);
    if (attribute == null || !MacroIndex.REPEAT_MACRO_VARIABLE_DEFINITION.equals(attribute.getMacroParamName().getText())) {
        return null;
    }
    MacroCall macroCall = PsiTreeUtil.getParentOfType(attribute, MacroCall.class);
    assert macroCall != null;
    for (MacroAttribute macroAttribute : macroCall.getMacroAttributeList()) {
        if (MacroIndex.REPEAT_MACRO_LIST_DEFINITION.equals(macroAttribute.getMacroParamName().getText())) {
            MacroParam macroParam;
            if ((macroParam = macroAttribute.getMacroParam()) == null) {
                return null;
            }
            PsiElement list = elementLocal.getContainingFile().getViewProvider().findElementAt(macroParam.getNode().getStartOffset() + macroParam.getTextLength() - 1, OxyTemplateInnerJs.INSTANCE);
            JSReferenceExpression statement = PsiTreeUtil.getParentOfType(list, JSReferenceExpression.class);
            if (statement != null) {
                JSSimpleTypeProcessor typeProcessor = new JSSimpleTypeProcessor();
                JSTypeEvaluator.evaluateTypes(statement, statement.getContainingFile(), typeProcessor);
                if (typeProcessor.getType() instanceof JSArrayTypeImpl) {
                    return ((JSArrayTypeImpl) typeProcessor.getType()).getType();
                }
            }
        }
    }
    return null;
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSArrayTypeImpl(com.intellij.lang.javascript.psi.types.JSArrayTypeImpl) MacroAttribute(ool.intellij.plugin.psi.MacroAttribute) PsiPackage(com.intellij.psi.PsiPackage) JSSimpleTypeProcessor(com.intellij.lang.javascript.psi.resolve.JSSimpleTypeProcessor) JSVarStatement(com.intellij.lang.javascript.psi.JSVarStatement) JSVariable(com.intellij.lang.javascript.psi.JSVariable) PsiElement(com.intellij.psi.PsiElement) MacroCall(ool.intellij.plugin.psi.MacroCall) MacroParam(ool.intellij.plugin.psi.MacroParam) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with MacroCall

use of ool.intellij.plugin.psi.MacroCall in project oxy-template-support-plugin by mutant-industries.

the class OxyTemplatePsiUtil method isClosingTagMacroName.

public static boolean isClosingTagMacroName(@NotNull final MacroName macroName) {
    if (PsiTreeUtil.getParentOfType(macroName, MacroEmptyTag.class) != null) {
        return false;
    }
    MacroCall tag = PsiTreeUtil.getParentOfType(macroName, MacroCall.class);
    MacroName openingTagMacroName;
    return tag != null && (openingTagMacroName = tag.getMacroName()) != null && !openingTagMacroName.isEquivalentTo(macroName);
}
Also used : MacroEmptyTag(ool.intellij.plugin.psi.MacroEmptyTag) MacroCall(ool.intellij.plugin.psi.MacroCall) MacroName(ool.intellij.plugin.psi.MacroName)

Aggregations

MacroCall (ool.intellij.plugin.psi.MacroCall)3 Nullable (org.jetbrains.annotations.Nullable)2 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)1 JSVarStatement (com.intellij.lang.javascript.psi.JSVarStatement)1 JSVariable (com.intellij.lang.javascript.psi.JSVariable)1 JSSimpleTypeProcessor (com.intellij.lang.javascript.psi.resolve.JSSimpleTypeProcessor)1 JSArrayTypeImpl (com.intellij.lang.javascript.psi.types.JSArrayTypeImpl)1 PsiElement (com.intellij.psi.PsiElement)1 PsiPackage (com.intellij.psi.PsiPackage)1 MacroAttribute (ool.intellij.plugin.psi.MacroAttribute)1 MacroEmptyTag (ool.intellij.plugin.psi.MacroEmptyTag)1 MacroName (ool.intellij.plugin.psi.MacroName)1 MacroParam (ool.intellij.plugin.psi.MacroParam)1 MacroParamDescriptor (ool.intellij.plugin.psi.macro.param.descriptor.MacroParamDescriptor)1