Search in sources :

Example 31 with JSFunction

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

the class FlexMoveClassProcessor method detectConflicts.

private MultiMap<PsiElement, String> detectConflicts(UsageInfo[] usages) {
    MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    final Collection<PsiElement> filesToMove = Arrays.asList(myElementsToMove);
    JSVisibilityUtil.Options options = new JSVisibilityUtil.Options();
    for (PsiElement file : filesToMove) {
        options.overridePackage(file, myTargetPackage);
    }
    for (UsageInfo usage : usages) {
        final PsiElement element = usage.getElement();
        if (!(element instanceof JSReferenceExpression)) {
            continue;
        }
        if (CommonRefactoringUtil.isAncestor(element, filesToMove)) {
            continue;
        }
        JSReferenceExpression refExpr = (JSReferenceExpression) element;
        final PsiElement resolved = refExpr.resolve();
        if (!(resolved instanceof JSQualifiedNamedElement)) {
            continue;
        }
        PsiElement containingClass = null;
        if (resolved instanceof JSFunction && ((JSFunction) resolved).isConstructor() && myElements.contains(containingClass = resolved.getParent()) || myElements.contains(resolved)) {
            JSRefactoringConflictsUtil.checkAccessibility((JSAttributeListOwner) resolved, (JSClass) containingClass, null, refExpr, conflicts, true, options);
        }
    }
    for (PsiElement fileToMove : filesToMove) {
        JSRefactoringConflictsUtil.checkOutgoingReferencesAccessibility(fileToMove, filesToMove, null, true, conflicts, Conditions.alwaysTrue(), options);
    }
    //JSRefactoringConflictsUtil.analyzeModuleConflicts(myProject, myElements, usages, myTargetDirectory, conflicts);
    return conflicts;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) JSVisibilityUtil(com.intellij.lang.javascript.refactoring.JSVisibilityUtil) PsiElement(com.intellij.psi.PsiElement)

Example 32 with JSFunction

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

the class FlexMoveInnerClassProcessor method findUsages.

@NotNull
@Override
protected UsageInfo[] findUsages() {
    final Collection<UsageInfo> result = Collections.synchronizedCollection(new ArrayList<UsageInfo>());
    ReferencesSearch.search(myElement, new LocalSearchScope(myElement.getContainingFile())).forEach(reference -> {
        final PsiElement element = reference.getElement();
        if (!(element instanceof JSReferenceExpression)) {
            return true;
        }
        if (JSResolveUtil.isSelfReference(element)) {
            return true;
        }
        result.add(new UsageInfo(element));
        return true;
    });
    if (myElement instanceof JSClass) {
        final JSFunction constructor = ((JSClass) myElement).getConstructor();
        if (constructor != null) {
            result.add(new UsageInfo(constructor));
            JSRefactoringUtil.addConstructorUsages((JSClass) myElement, result);
        }
    }
    TextOccurrencesUtil.findNonCodeUsages(myElement, myElement.getName(), mySearchInComments, mySearchTextOccurences, StringUtil.getQualifiedName(myPackageName, myClassName), result);
    return UsageViewUtil.removeDuplicatedUsages(result.toArray(new UsageInfo[result.size()]));
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) NonCodeUsageInfo(com.intellij.refactoring.util.NonCodeUsageInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with JSFunction

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

the class JSChangeSignatureDetector method getRange.

@Nullable
private static TextRange getRange(PsiElement element) {
    JSFunction f = PsiTreeUtil.getParentOfType(element, JSFunction.class, false);
    if (f == null)
        return null;
    ASTNode identifier = f.findNameIdentifier();
    if (identifier == null) {
        return null;
    }
    PsiElement e = f.getReturnTypeElement();
    if (e == null) {
        ASTNode colon = f.getNode().findChildByType(JSTokenTypes.COLON);
        if (colon != null) {
            e = colon.getPsi();
        }
    }
    if (e == null) {
        e = f.getParameterList();
    }
    return new TextRange(identifier.getTextRange().getStartOffset(), e.getTextRange().getEndOffset());
}
Also used : JSFunction(com.intellij.lang.javascript.psi.JSFunction) ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JSFunction (com.intellij.lang.javascript.psi.JSFunction)33 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)13 PsiElement (com.intellij.psi.PsiElement)11 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)8 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)6 Nullable (org.jetbrains.annotations.Nullable)5 ArrayList (java.util.ArrayList)4 JSVariable (com.intellij.lang.javascript.psi.JSVariable)3 Module (com.intellij.openapi.module.Module)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiDirectory (com.intellij.psi.PsiDirectory)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 List (java.util.List)3 NotNull (org.jetbrains.annotations.NotNull)3 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)2 ASTNode (com.intellij.lang.ASTNode)2 JavaScriptSupportLoader (com.intellij.lang.javascript.JavaScriptSupportLoader)2 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)2 FlexUnitSupport (com.intellij.lang.javascript.flex.flexunit.FlexUnitSupport)2