Search in sources :

Example 61 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass 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 62 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class ExpressionBinding method writeCallExpression.

private static void writeCallExpression(JSCallExpression expression, PrimitiveAmfOutputStream out, BaseWriter writer, ValueReferenceResolver valueReferenceResolver) throws InvalidPropertyException {
    final JSReferenceExpression methodExpression = (JSReferenceExpression) expression.getMethodExpression();
    final PsiElement psiElement = resolveReferenceExpression(methodExpression, true);
    final JSExpression[] arguments;
    if (psiElement instanceof JSClass) {
        // IDEA-74060, {Number('20')}
        arguments = expression.getArguments();
        assert arguments.length == 1;
        writeExpression(arguments[0], out, writer, valueReferenceResolver);
        return;
    } else if (psiElement instanceof JSReferenceExpression) {
        writeReferenceExpression((JSReferenceExpression) psiElement, out, writer, valueReferenceResolver, false);
        return;
    }
    writeFunction((JSFunction) psiElement, writer, valueReferenceResolver, false, expression, methodExpression);
}
Also used : JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 63 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass 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)

Example 64 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class ExpressionBinding method writeFunction.

private static void writeFunction(JSFunction function, BaseWriter writer, @Nullable ValueReferenceResolver valueReferenceResolver, boolean isBinding, @Nullable JSCallExpression expression, @Nullable JSReferenceExpression methodExpression) throws InvalidPropertyException {
    final PrimitiveAmfOutputStream out = writer.getOut();
    JSExpression[] arguments;
    final int rollbackPosition;
    final int start;
    if (function.isConstructor()) {
        assert expression != null;
        arguments = expression.getArguments();
        final JSClass jsClass = (JSClass) function.getParent();
        // text="{new String('newString')}"
        writer.newInstance(jsClass.getQualifiedName(), arguments.length, true);
        rollbackPosition = out.allocateShort();
        start = out.size();
    } else {
        out.write(ExpressionMessageTypes.CALL);
        rollbackPosition = out.allocateShort();
        start = out.size();
        // text="{resourceManager.getString('core', 'viewSource')}"
        if (methodExpression != null) {
            JSReferenceExpression qualifier = (JSReferenceExpression) methodExpression.getQualifier();
            while (qualifier != null) {
                writer.classOrPropertyName(qualifier.getReferencedName());
                qualifier = (JSReferenceExpression) qualifier.getQualifier();
            }
        }
        out.write(0);
        writer.classOrPropertyName(function.getName());
        if (function.isGetProperty()) {
            out.write(isBinding ? -2 : -1);
            return;
        } else {
            assert expression != null;
            arguments = expression.getArguments();
            out.write(arguments.length);
        }
    }
    for (JSExpression argument : arguments) {
        writeExpression(argument, out, writer, valueReferenceResolver);
    }
    out.putShort(out.size() - start, rollbackPosition);
}
Also used : PrimitiveAmfOutputStream(com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 65 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class CreateFlexUnitTestDialog method doOKAction.

protected void doOKAction() {
    final String superClassFqn = mySuperClassField.getText().trim();
    final PsiElement element = ActionScriptClassResolver.findClassByQNameStatic(superClassFqn, getSuperClassScope(myModule));
    mySuperClass = element instanceof JSClass ? (JSClass) element : null;
    if (myCreateTestSourceFolderCheckBox.isVisible() && myCreateTestSourceFolderCheckBox.isSelected()) {
        myTargetDirectory = createTestSourceFolderAndPackage(myModule, myTestSourceFolderTextField.getText().trim(), getPackageName());
    }
    if (myTargetDirectory == null) {
        myTargetDirectory = JSRefactoringUtil.chooseOrCreateDirectoryForClass(myModule.getProject(), myModule, getTestClassPackageScope(myModule), getPackageName(), getTestClassName(), myExistingTestSourceRoot, ThreeState.YES);
    }
    if (myTargetDirectory != null) {
        if (myCreateTestSourceFolderCheckBox.isVisible()) {
            PropertiesComponent.getInstance(myModule.getProject()).setValue(CREATE_TEST_SOURCE_FOLDER_KEY, myCreateTestSourceFolderCheckBox.isSelected(), true);
        }
        super.doOKAction();
    }
}
Also used : JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)141 PsiElement (com.intellij.psi.PsiElement)65 Nullable (org.jetbrains.annotations.Nullable)27 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)23 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)22 JSFunction (com.intellij.lang.javascript.psi.JSFunction)18 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)18 Module (com.intellij.openapi.module.Module)17 XmlFile (com.intellij.psi.xml.XmlFile)17 Project (com.intellij.openapi.project.Project)16 PsiFile (com.intellij.psi.PsiFile)16 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)15 ArrayList (java.util.ArrayList)14 PsiDirectory (com.intellij.psi.PsiDirectory)11 XmlTag (com.intellij.psi.xml.XmlTag)11 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)8 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)8 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)7