Search in sources :

Example 1 with JSReferenceList

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

the class FlexXmlBackedClassesIndex method getIndexer.

@Override
@NotNull
public DataIndexer<String, Void, FileContent> getIndexer() {
    return new DataIndexer<String, Void, FileContent>() {

        @Override
        @NotNull
        public Map<String, Void> map(@NotNull FileContent inputData) {
            final XmlFile file = (XmlFile) inputData.getPsiFile();
            final Map<String, Void> result = new HashMap<>();
            for (JSClass clazz : XmlBackedJSClassImpl.getClasses(file)) {
                JSReferenceList supers = getSupers(clazz);
                if (supers != null) {
                    final JSExpression[] expressions = supers.getExpressions();
                    for (JSExpression expr : expressions) {
                        String s = expr instanceof JSReferenceExpression ? ((JSReferenceExpression) expr).getReferenceName() : null;
                        if (s != null)
                            result.put(s, null);
                    }
                }
            }
            return result;
        }
    };
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) HashMap(com.intellij.util.containers.HashMap) JSExpression(com.intellij.lang.javascript.psi.JSExpression) NotNull(org.jetbrains.annotations.NotNull) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) JSReferenceList(com.intellij.lang.javascript.psi.ecmal4.JSReferenceList) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JSReferenceList

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

the class FlashUmlDataModel method removeEdge.

@Override
public void removeEdge(DiagramEdge<Object> edge) {
    final Object source = edge.getSource().getIdentifyingElement();
    final Object target = edge.getTarget().getIdentifyingElement();
    final DiagramRelationshipInfo relationship = edge.getRelationship();
    if (!(source instanceof JSClass) || !(target instanceof JSClass) || relationship == DiagramRelationshipInfo.NO_RELATIONSHIP) {
        return;
    }
    final JSClass fromClass = (JSClass) source;
    final JSClass toClass = (JSClass) target;
    if (JSProjectUtil.isInLibrary(fromClass)) {
        return;
    }
    if (fromClass instanceof XmlBackedJSClassImpl && !toClass.isInterface()) {
        Messages.showErrorDialog(fromClass.getProject(), FlexBundle.message("base.component.needed.message"), FlexBundle.message("remove.edge.title"));
        return;
    }
    if (Messages.showYesNoDialog(fromClass.getProject(), FlexBundle.message("remove.inheritance.link.prompt", fromClass.getQualifiedName(), toClass.getQualifiedName()), FlexBundle.message("remove.edge.title"), Messages.getQuestionIcon()) != Messages.YES) {
        return;
    }
    final Runnable runnable = () -> {
        JSReferenceList refList = !fromClass.isInterface() && toClass.isInterface() ? fromClass.getImplementsList() : fromClass.getExtendsList();
        List<FormatFixer> formatters = new ArrayList<>();
        JSRefactoringUtil.removeFromReferenceList(refList, toClass, formatters);
        if (!(fromClass instanceof XmlBackedJSClassImpl) && needsImport(fromClass, toClass)) {
            formatters.addAll(ECMAScriptImportOptimizer.executeNoFormat(fromClass.getContainingFile()));
        }
        FormatFixer.fixAll(formatters);
    };
    DiagramAction.performCommand(getBuilder(), runnable, FlexBundle.message("remove.relationship.command.name"), null, fromClass.getContainingFile());
}
Also used : XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) JSReferenceList(com.intellij.lang.javascript.psi.ecmal4.JSReferenceList) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) JSReferenceList(com.intellij.lang.javascript.psi.ecmal4.JSReferenceList)

Example 3 with JSReferenceList

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

the class CreateJSSubclassIntention method getClassDeclarationTextRange.

public static TextRange getClassDeclarationTextRange(final JSClass jsClass) {
    int start = jsClass.getTextRange().getStartOffset();
    final JSAttributeList attributeList = jsClass.getAttributeList();
    if (attributeList != null) {
        final PsiElement accessTypeElement = attributeList.findAccessTypeElement();
        if (accessTypeElement != null) {
            start = accessTypeElement.getTextRange().getStartOffset();
        } else {
            final ASTNode node = jsClass.getNode();
            final ASTNode classKeyWordNode = node == null ? null : node.findChildByType(JSTokenTypes.CLASS_KEYWORD);
            if (classKeyWordNode != null) {
                start = classKeyWordNode.getTextRange().getStartOffset();
            }
        }
    }
    int end = start;
    JSReferenceList jsReferenceList = jsClass.getImplementsList();
    if (jsReferenceList == null) {
        jsReferenceList = jsClass.getExtendsList();
    }
    if (jsReferenceList != null) {
        end = jsReferenceList.getTextRange().getEndOffset();
    } else {
        final PsiElement nameIdentifier = jsClass.getNameIdentifier();
        if (nameIdentifier != null) {
            end = nameIdentifier.getTextRange().getEndOffset();
        }
    }
    return new TextRange(start, end);
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange) JSReferenceList(com.intellij.lang.javascript.psi.ecmal4.JSReferenceList) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JSReferenceList (com.intellij.lang.javascript.psi.ecmal4.JSReferenceList)3 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)1 ASTNode (com.intellij.lang.ASTNode)1 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)1 JSExpression (com.intellij.lang.javascript.psi.JSExpression)1 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)1 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1 XmlFile (com.intellij.psi.xml.XmlFile)1 HashMap (com.intellij.util.containers.HashMap)1 NotNull (org.jetbrains.annotations.NotNull)1