Search in sources :

Example 91 with JSClass

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

the class FlexRenameTest method testRenameFlexClassReferencedInCss.

public void testRenameFlexClassReferencedInCss() throws Exception {
    final String name = getTestName(false);
    doTest(name + "Renamed", name + "_after.css", name + ".css", name + ".as");
    final PsiReference newReference = myFile.findReferenceAt(myEditor.getCaretModel().getOffset());
    final PsiElement newResolve = newReference == null ? null : newReference.resolve();
    assertTrue(newResolve instanceof JSClass && "bar.RenameFlexClassReferencedInCssRenamed".equals(((JSClass) newResolve).getQualifiedName()));
}
Also used : PsiReference(com.intellij.psi.PsiReference) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 92 with JSClass

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

the class FlexValue method computeChildren.

@Override
public void computeChildren(@NotNull final XCompositeNode node) {
    final int i = myResult.indexOf(OBJECT_MARKER);
    if (i == -1)
        super.computeChildren(node);
    final String typeFromFlexValueResult = getTypeAndAdditionalInfo(myResult).first;
    final String expression;
    try {
        expression = referenceObjectBase(i, OBJECT_MARKER);
    } catch (StringIndexOutOfBoundsException e) {
        FlexDebugProcess.log(new Exception(myResult, e));
        node.addChildren(XValueChildrenList.EMPTY, true);
        return;
    }
    final FlexStackFrame.EvaluateCommand command = myFlexStackFrame.new EvaluateCommand(expression, null) {

        @Override
        CommandOutputProcessingMode doOnTextAvailable(@NonNls final String resultS) {
            StringTokenizer tokenizer = new StringTokenizer(resultS, "\r\n");
            // skip first token; it contains $-prefix followed by myResult: $6 = [Object 30860193, class='__AS3__.vec::Vector.<String>']
            tokenizer.nextToken();
            final LinkedHashMap<String, FlexValue> fieldNameToFlexValueMap = new LinkedHashMap<>(tokenizer.countTokens());
            final NodeClassInfo nodeClassInfo = DumbService.getInstance(myDebugProcess.getSession().getProject()).runReadActionInSmartMode(() -> {
                final Project project = myDebugProcess.getSession().getProject();
                final JSClass jsClass = mySourcePosition == null ? null : findJSClass(project, ModuleUtilCore.findModuleForFile(mySourcePosition.getFile(), project), typeFromFlexValueResult);
                return jsClass == null ? null : NodeClassInfo.getNodeClassInfo(jsClass);
            });
            while (tokenizer.hasMoreElements()) {
                final String s = tokenizer.nextToken().trim();
                if (s.length() == 0)
                    continue;
                final int delimIndex = s.indexOf(FlexStackFrame.DELIM);
                if (delimIndex == -1) {
                    FlexDebugProcess.log("Unrecognized string:" + s);
                    continue;
                }
                final String fieldName = s.substring(0, delimIndex);
                final String result = s.substring(delimIndex + FlexStackFrame.DELIM.length());
                if (result.startsWith("[Setter ")) {
                    // [Setter 78]
                    continue;
                }
                String evaluatedPath = myExpression;
                if (fieldName.length() > 0 && Character.isDigit(fieldName.charAt(0))) {
                    evaluatedPath += "[\"" + fieldName + "\"]";
                } else {
                    evaluatedPath += "." + fieldName;
                }
                // either parameter of static function from scopechain or a field. Static functions from scopechain look like following:
                // // [Object 52571545, class='Main$/staticFunction']
                final ValueType valueType = typeFromFlexValueResult != null && typeFromFlexValueResult.indexOf('/') > -1 ? ValueType.Parameter : ValueType.Field;
                final FlexValue flexValue = new FlexValue(myFlexStackFrame, myDebugProcess, mySourcePosition, fieldName, evaluatedPath, result, FlexValue.this.myResult, valueType);
                addValueCheckingDuplicates(flexValue, fieldNameToFlexValueMap);
            }
            addChildren(node, fieldNameToFlexValueMap, nodeClassInfo);
            return CommandOutputProcessingMode.DONE;
        }
    };
    myDebugProcess.sendCommand(command);
}
Also used : NonNls(org.jetbrains.annotations.NonNls) Project(com.intellij.openapi.project.Project) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 93 with JSClass

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

the class FlexValue method computeTypeSourcePosition.

public void computeTypeSourcePosition(@NotNull final XNavigatable navigatable) {
    if (mySourcePosition == null) {
        navigatable.setSourcePosition(null);
        return;
    }
    final boolean isObject = myResult.contains(OBJECT_MARKER);
    if (isObject) {
        final Pair<String, String> typeAndAdditionalInfo = getTypeAndAdditionalInfo(myResult);
        final String typeFromFlexValueResult = typeAndAdditionalInfo.first;
        if (typeFromFlexValueResult != null) {
            final Project project = myDebugProcess.getSession().getProject();
            final JSClass jsClass = findJSClass(project, ModuleUtilCore.findModuleForFile(mySourcePosition.getFile(), project), typeFromFlexValueResult);
            navigatable.setSourcePosition(DebuggerSupportUtils.calcSourcePosition(jsClass));
            return;
        }
    }
    navigatable.setSourcePosition(null);
}
Also used : Project(com.intellij.openapi.project.Project) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 94 with JSClass

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

the class FlexQualifiedNameLocationProvider method findElement.

@Nullable
private static JSElement findElement(String link, Project project) {
    String moduleName = link.substring(0, link.indexOf(":"));
    Module module = ModuleManager.getInstance(project).findModuleByName(moduleName);
    link = link.substring(link.indexOf(":") + 1);
    final JavaScriptIndex index = JavaScriptIndex.getInstance(project);
    PsiElement element = ActionScriptClassResolver.findClassByQName(link, index, module);
    if (element instanceof JSClass) {
        return (JSElement) element;
    }
    if (element == null && link.contains(".") && link.endsWith("()")) {
        String qname = link.substring(0, link.lastIndexOf('.'));
        element = ActionScriptClassResolver.findClassByQName(qname, index, module);
        if (element instanceof JSClass) {
            String methodName = link.substring(link.lastIndexOf('.') + 1, link.length() - 2);
            return ((JSClass) element).findFunctionByNameAndKind(methodName, JSFunction.FunctionKind.SIMPLE);
        }
    }
    return null;
}
Also used : JavaScriptIndex(com.intellij.lang.javascript.index.JavaScriptIndex) JSElement(com.intellij.lang.javascript.psi.JSElement) Module(com.intellij.openapi.module.Module) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 95 with JSClass

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

the class FlexValue method computeSourcePosition.

@Override
public void computeSourcePosition(@NotNull final XNavigatable navigatable) {
    if (mySourcePosition == null) {
        navigatable.setSourcePosition(null);
        return;
    }
    XSourcePosition result = null;
    final Project project = myDebugProcess.getSession().getProject();
    if (myValueType == ValueType.Variable) {
        final PsiElement contextElement = XDebuggerUtil.getInstance().findContextElement(mySourcePosition.getFile(), mySourcePosition.getOffset(), project, true);
        final JSFunction jsFunction = PsiTreeUtil.getParentOfType(contextElement, JSFunction.class);
        if (jsFunction != null) {
            final Ref<JSVariable> varRef = new Ref<>();
            jsFunction.accept(new JSElementVisitor() {

                @Override
                public void visitJSElement(final JSElement node) {
                    if (varRef.isNull()) {
                        node.acceptChildren(this);
                    }
                }

                @Override
                public void visitJSVariable(final JSVariable node) {
                    if (myName.equals(node.getName())) {
                        varRef.set(node);
                    }
                    super.visitJSVariable(node);
                }
            });
            if (!varRef.isNull()) {
                result = DebuggerSupportUtils.calcSourcePosition(varRef.get());
            }
        }
    } else if (myValueType == ValueType.Parameter) {
        final PsiElement contextElement = XDebuggerUtil.getInstance().findContextElement(mySourcePosition.getFile(), mySourcePosition.getOffset(), project, true);
        final JSFunction jsFunction = PsiTreeUtil.getParentOfType(contextElement, JSFunction.class);
        final JSParameter[] parameters = jsFunction == null ? JSParameter.EMPTY_ARRAY : jsFunction.getParameterVariables();
        for (final JSParameter parameter : parameters) {
            if (myName.equals(parameter.getName())) {
                result = DebuggerSupportUtils.calcSourcePosition(parameter);
                break;
            }
        }
    } else if (myValueType == ValueType.Field && myParentResult != null) {
        final String typeFromFlexValueResult = getTypeAndAdditionalInfo(myParentResult).first;
        final JSClass jsClass = findJSClass(project, ModuleUtilCore.findModuleForFile(mySourcePosition.getFile(), project), typeFromFlexValueResult);
        if (jsClass != null) {
            final Ref<PsiElement> fieldRef = new Ref<>();
            fieldRef.set(JSInheritanceUtil.findMember(myName, jsClass, JSInheritanceUtil.SearchedMemberType.FieldsAndMethods, JSFunction.FunctionKind.GETTER, true));
            if (fieldRef.isNull() && jsClass instanceof MxmlJSClass) {
                final PsiFile file = jsClass.getContainingFile();
                final XmlFile xmlFile = file instanceof XmlFile ? (XmlFile) file : null;
                final XmlTag rootTag = xmlFile == null ? null : xmlFile.getRootTag();
                if (rootTag != null) {
                    NodeClassInfo.processSubtagsRecursively(rootTag, tag -> {
                        final XmlAttribute idAttr = tag.getAttribute("id");
                        final String id = idAttr == null ? null : idAttr.getValue();
                        if (id != null && id.equals(myName)) {
                            fieldRef.set(idAttr);
                        }
                        return !MxmlJSClass.isTagThatAllowsAnyXmlContent(tag);
                    });
                }
            }
            result = DebuggerSupportUtils.calcSourcePosition(fieldRef.get());
        }
    }
    navigatable.setSourcePosition(result);
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) PsiFile(com.intellij.psi.PsiFile) XSourcePosition(com.intellij.xdebugger.XSourcePosition) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

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