Search in sources :

Example 1 with InvalidPropertyException

use of com.intellij.flex.uiDesigner.InvalidPropertyException in project intellij-plugins by JetBrains.

the class PropertyProcessor method processClass.

// see ClassProperty test
private void processClass(XmlElementValueProvider valueProvider) throws InvalidPropertyException {
    JSClass jsClass = valueProvider.getJsClass();
    // IDEA-73537, cannot use only valueProvider.getJsClass()
    if (jsClass == null) {
        String trimmed = valueProvider.getTrimmed();
        XmlElement exceptionElement = valueProvider.getElement();
        if (trimmed.isEmpty() && valueProvider.getElement() instanceof XmlTag) {
            // case 1, fx:Class
            final XmlTag propertyTag = (XmlTag) valueProvider.getElement();
            final XmlTag[] propertyTagSubTags = propertyTag.getSubTags();
            if (propertyTagSubTags.length == 1) {
                final XmlTag contentTag = propertyTagSubTags[0];
                exceptionElement = contentTag;
                final XmlElementDescriptor contentTagDescriptor = contentTag.getDescriptor();
                if (contentTagDescriptor instanceof ClassBackedElementDescriptor && AsCommonTypeNames.CLASS.equals(contentTagDescriptor.getQualifiedName())) {
                    trimmed = contentTag.getValue().getTrimmedText();
                }
            }
        }
        if (trimmed.isEmpty()) {
            throw new InvalidPropertyException(exceptionElement, "invalid.class.value");
        }
        final Module module = ModuleUtilCore.findModuleForPsiElement(valueProvider.getElement());
        if (module != null) {
            jsClass = (JSClass) ActionScriptClassResolver.findClassByQNameStatic(trimmed, module.getModuleWithDependenciesAndLibrariesScope(false));
        }
        if (jsClass == null) {
            throw new InvalidPropertyException(exceptionElement, "unresolved.class", trimmed);
        }
    }
    if (InjectionUtil.isProjectComponent(jsClass)) {
        if (ActionScriptClassResolver.isParentClass(jsClass, "spark.components.View")) {
            int projectComponentFactoryId = getProjectComponentFactoryId(jsClass);
            assert projectComponentFactoryId != -1;
            writer.projectClassReference(projectComponentFactoryId);
        } else {
            throw new InvalidPropertyException(valueProvider.getElement(), "class.reference.support.only.skin.class.or.view", jsClass.getQualifiedName());
        }
    } else {
        writer.classReference(jsClass.getQualifiedName());
    }
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) Module(com.intellij.openapi.module.Module) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 2 with InvalidPropertyException

use of com.intellij.flex.uiDesigner.InvalidPropertyException in project intellij-plugins by JetBrains.

the class PropertyProcessor method writeClassFactory.

private void writeClassFactory(XmlElementValueProvider valueProvider) throws InvalidPropertyException {
    if (valueProvider instanceof XmlTagValueProvider) {
        XmlTag tag = ((XmlTagValueProvider) valueProvider).getTag();
        XmlTag[] subTags = tag.getSubTags();
        if (subTags.length > 0) {
            processFxComponent(subTags[0], true);
            return;
        }
    }
    String className = valueProvider.getTrimmed();
    if (writeFxComponentReferenceIfProcessed(className) || writeReferenceIfReferenced(className)) {
        return;
    }
    final JSClass jsClass = valueProvider.getJsClass();
    if (jsClass == null) {
        throw new InvalidPropertyException(valueProvider.getElement(), "unresolved.class", valueProvider.getTrimmed());
    }
    final Trinity<Integer, String, Condition<AnnotationBackedDescriptor>> effectiveClassInfo;
    final PsiElement parent = jsClass.getNavigationElement().getParent();
    if (parent instanceof XmlTag && MxmlUtil.isComponentLanguageTag((XmlTag) parent)) {
        // if referenced by inner class name, but inner fx component is not yet processed
        if (parent.getContainingFile().equals(valueProvider.getElement().getContainingFile())) {
            processFxComponent((XmlTag) parent, false);
            return;
        } else {
            effectiveClassInfo = new Trinity<>(-1, "mx.core.UIComponent", null);
        }
    } else {
        effectiveClassInfo = MxmlUtil.computeEffectiveClass(valueProvider.getElement(), jsClass, mxmlWriter.projectComponentReferenceCounter, false);
    }
    if (effectiveClassInfo.first == -1) {
        if (effectiveClassInfo.second != null) {
            if (effectiveClassInfo.second.equals("mx.core.UIComponent")) {
                PsiMetaData psiMetaData = valueProvider.getPsiMetaData();
                if (psiMetaData != null && psiMetaData.getName().equals("itemRenderer") && MxmlUtil.isPropertyOfSparkDataGroup((AnnotationBackedDescriptor) psiMetaData)) {
                    className = MxmlUtil.UNKNOWN_ITEM_RENDERER_CLASS_NAME;
                } else {
                    className = MxmlUtil.UNKNOWN_COMPONENT_CLASS_NAME;
                }
            } else {
                className = effectiveClassInfo.second;
            }
        }
        writeNonProjectUnreferencedClassFactory(className);
    } else {
        writer.documentFactoryReference(effectiveClassInfo.first);
    }
}
Also used : Condition(com.intellij.openapi.util.Condition) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) PsiMetaData(com.intellij.psi.meta.PsiMetaData) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 3 with InvalidPropertyException

use of com.intellij.flex.uiDesigner.InvalidPropertyException in project intellij-plugins by JetBrains.

the class InjectedPsiVisitor method visit.

@Override
public void visit(@NotNull PsiFile injectedPsi, @NotNull List<Shred> places) {
    // will be called 2 - first for {demandSelectedTO.journalist.nom} and second for {demandSelectedTO.journalist.prenom}
    if (visited) {
        return;
    }
    visited = true;
    assert places.size() == 1;
    assert places.get(0).getHost() == host;
    JSFile jsFile = (JSFile) injectedPsi;
    JSSourceElement[] statements = jsFile.getStatements();
    if (statements.length == 0 && (valueWriter = checkCompilerDirective(jsFile)) != null) {
        return;
    }
    assert statements.length == 1;
    final JSExpression expr = ((JSExpressionStatement) statements[0]).getExpression();
    // <s:Image source="@Embed(source='/Users/develar/Pictures/iChat Ico
    if (!(expr instanceof JSCallExpression)) {
        valueWriter = InjectedASWriter.IGNORE;
        return;
    }
    JSCallExpression expression = (JSCallExpression) expr;
    JSExpression[] arguments = expression.getArguments();
    if (arguments.length != 1) {
        logUnsupported();
        return;
    }
    if (arguments[0] instanceof JSArrayLiteralExpression) {
        if (isUnexpected(JSCommonTypeNames.ARRAY_CLASS_NAME)) {
            return;
        }
        JSArrayLiteralExpression arrayLiteralExpression = (JSArrayLiteralExpression) arguments[0];
        JSExpression[] expressions = arrayLiteralExpression.getExpressions();
        if (expressions.length == 0) {
            valueWriter = InjectedASWriter.IGNORE;
            return;
        }
        // create ExpressionBinding only if expressions contains non-primitive values
        for (JSExpression itemExpression : expressions) {
            if (!(itemExpression instanceof JSLiteralExpression)) {
                binding = new ExpressionBinding(arrayLiteralExpression);
                return;
            }
        }
        valueWriter = new InjectedArrayOfPrimitivesWriter(arrayLiteralExpression);
    } else if (arguments[0] instanceof JSReferenceExpression && arguments[0].getChildren().length == 0) {
        // if propertyName="{CustomSkin}", so, write class, otherwise, it is binding
        JSReferenceExpression referenceExpression = (JSReferenceExpression) arguments[0];
        PsiElement element = referenceExpression.resolve();
        if (element == null) {
            invalidPropertyException = new InvalidPropertyException(expression, "unresolved.variable.or.type", referenceExpression.getReferencedName());
        } else if (element instanceof JSClass) {
            if (isExpectedObjectOrAnyType() || AsCommonTypeNames.CLASS.equals(expectedType)) {
                valueWriter = new ClassValueWriter(((JSClass) element));
            } else {
                invalidPropertyException = new InvalidPropertyException(expression, "implicit.coercion", "Class", expectedType);
            }
        } else if (element instanceof JSVariable) {
            binding = new VariableBinding(((JSVariable) element));
        } else if (element instanceof JSFunction) {
            binding = new ExpressionBinding(((JSFunction) element));
        } else {
            binding = new MxmlObjectBinding(referenceExpression.getReferencedName(), JSCommonTypeNames.ARRAY_CLASS_NAME.equals(expectedType));
        }
    } else {
        binding = new ExpressionBinding(arguments[0]);
    }
}
Also used : InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 4 with InvalidPropertyException

use of com.intellij.flex.uiDesigner.InvalidPropertyException in project intellij-plugins by JetBrains.

the class MxmlUtil method computeEffectiveClass.

static Trinity<Integer, String, Condition<AnnotationBackedDescriptor>> computeEffectiveClass(final PsiElement element, final PsiElement declaration, final ProjectComponentReferenceCounter projectComponentReferenceCounter, final boolean computePropertyFilter) throws InvalidPropertyException {
    PsiFile psiFile = declaration.getContainingFile();
    VirtualFile virtualFile = psiFile.getVirtualFile();
    ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(psiFile.getProject()).getFileIndex();
    LOG.assertTrue(virtualFile != null);
    if (!projectFileIndex.isInSourceContent(virtualFile)) {
        return NON_PROJECT_CLASS;
    }
    if (psiFile instanceof XmlFile) {
        return new Trinity<>(DocumentFactoryManager.getInstance().getId(virtualFile, (XmlFile) psiFile, projectComponentReferenceCounter), null, null);
    }
    final Set<PsiFile> filteredFiles;
    if (computePropertyFilter) {
        filteredFiles = new THashSet<>();
        filteredFiles.add(psiFile);
    } else {
        filteredFiles = null;
    }
    final JSClass aClass = (JSClass) declaration;
    JSClass[] classes;
    while ((classes = aClass.getSuperClasses()).length > 0) {
        JSClass parentClass = classes[0];
        PsiFile containingFile = parentClass.getContainingFile();
        //noinspection ConstantConditions
        if (!projectFileIndex.isInSourceContent(containingFile.getVirtualFile())) {
            return new Trinity<>(-1, parentClass.getQualifiedName(), computePropertyFilter ? new CustomComponentPropertyFilter(filteredFiles) : null);
        } else if (computePropertyFilter) {
            filteredFiles.add(containingFile);
        }
    }
    // well, it must be at least mx.core.UIComponent or spark.primitives.supportClasses.GraphicElement
    throw new InvalidPropertyException(element, "unresolved.class", aClass.getQualifiedName());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Trinity(com.intellij.openapi.util.Trinity) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 5 with InvalidPropertyException

use of com.intellij.flex.uiDesigner.InvalidPropertyException in project intellij-plugins by JetBrains.

the class ExpressionBinding method writeReferenceExpression.

private static void writeReferenceExpression(JSReferenceExpression expression, PrimitiveAmfOutputStream out, BaseWriter writer, ValueReferenceResolver valueReferenceResolver, boolean qualificatorSupportedForMxmlBinding) throws InvalidPropertyException {
    final PsiElement element;
    List<String> qualifiers = null;
    JSExpression expressionQualifier = expression.getQualifier();
    JSReferenceExpression qualifier;
    if (expressionQualifier instanceof JSReferenceExpression) {
        qualifier = (JSReferenceExpression) expressionQualifier;
    } else if (expressionQualifier instanceof JSIndexedPropertyAccessExpression) {
        qualifier = (JSReferenceExpression) ((JSIndexedPropertyAccessExpression) expressionQualifier).getQualifier();
    } else if (expressionQualifier != null && !(expressionQualifier instanceof JSThisExpression)) {
        // we can skip "this."
        throw new UnsupportedOperationException("unknown qualifier " + expressionQualifier.toString() + " " + expression.getText());
    } else {
        qualifier = null;
    }
    if (qualificatorSupportedForMxmlBinding && qualifier != null) {
        JSReferenceExpression topElement;
        qualifiers = new ArrayList<>();
        do {
            qualifiers.add(qualifier.getReferencedName());
            topElement = qualifier;
        } while ((qualifier = (JSReferenceExpression) qualifier.getQualifier()) != null);
        element = resolveReferenceExpression(topElement, true);
    } else {
        element = resolveReferenceExpression(expression, false);
    }
    if (element instanceof JSClass) {
        // {VerticalAlign}
        if (qualifiers == null) {
            writer.classReference(((JSClass) element).getQualifiedName());
        } else {
            // check for {VerticalAlign.MIDDLE}
            PsiElement possibleVariable = resolveReferenceExpression(expression, true);
            if (possibleVariable instanceof JSVariable) {
                JSVariable variable = (JSVariable) possibleVariable;
                if (variable.isConst()) {
                    JSExpression initializer = ((JSVariable) possibleVariable).getInitializer();
                    if (initializer != null) {
                        writeExpression(initializer, out, writer, valueReferenceResolver);
                        return;
                    } else {
                        throw new InvalidPropertyException(expression, "const.without.initializer", expression.getText());
                    }
                }
            }
            throw new UnsupportedOperationException(expression.getText());
        }
    } else if (element instanceof JSVariable) {
        checkQualifier(expression);
        VariableReference valueReference = valueReferenceResolver.getNullableValueReference((JSVariable) element);
        if (valueReference != null) {
            out.write(ExpressionMessageTypes.VARIABLE_REFERENCE);
            // may be already referenced, i.e. VariableReference created for this variable
            valueReference.write(out, writer, valueReferenceResolver);
        } else {
            writeJSVariable(((JSVariable) element), out, writer, valueReferenceResolver);
        }
    } else if (element instanceof JSFunction) {
        writeFunction((JSFunction) element, writer, valueReferenceResolver, true);
    } else {
        final String hostObjectId;
        if (qualifiers == null) {
            out.write(ExpressionMessageTypes.MXML_OBJECT_REFERENCE);
            hostObjectId = expression.getReferencedName();
        } else {
            out.write(ExpressionMessageTypes.MXML_OBJECT_CHAIN);
            writer.classOrPropertyName(expression.getReferencedName());
            for (int i = qualifiers.size() - 2; /* last qualifier is not included to chain, it is host object */
            i >= 0; i--) {
                writer.classOrPropertyName(qualifiers.get(i));
            }
            writer.endObject();
            hostObjectId = qualifiers.get(qualifiers.size() - 1);
        }
        try {
            valueReferenceResolver.getValueReference(hostObjectId).write(out, writer, valueReferenceResolver);
        } catch (IllegalStateException ignored) {
            // getValueReference throws IllegalStateException if value reference is null
            throw new UnsupportedOperationException(expression.getText());
        }
    }
}
Also used : InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Aggregations

InvalidPropertyException (com.intellij.flex.uiDesigner.InvalidPropertyException)13 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)5 PsiElement (com.intellij.psi.PsiElement)5 ClassBackedElementDescriptor (com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor)4 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)4 PropertyKind (com.intellij.flex.uiDesigner.mxml.PropertyProcessor.PropertyKind)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)2 JSAttributeNameValuePair (com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair)2 AccessToken (com.intellij.openapi.application.AccessToken)2 Condition (com.intellij.openapi.util.Condition)2 PrimitiveAmfOutputStream (com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream)1 StateReference (com.intellij.javascript.flex.FlexReferenceContributor.StateReference)1 IProperty (com.intellij.lang.properties.IProperty)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 Module (com.intellij.openapi.module.Module)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 Trinity (com.intellij.openapi.util.Trinity)1 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)1 PsiReference (com.intellij.psi.PsiReference)1