@Override @NotNull public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) { final Pair<XmlTagChild, XmlTagChild> childrenInRange = XmlUtil.findTagChildrenInRange(file, startOffset, endOffset); if (childrenInRange == null) { final PsiElement elementAt = file.findElementAt(startOffset); if (elementAt instanceof XmlToken && ((XmlToken)elementAt).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) { return new PsiElement[] {elementAt}; } return PsiElement.EMPTY_ARRAY; } List<PsiElement> result = new ArrayList<PsiElement>(); PsiElement first = childrenInRange.getFirst(); PsiElement last = childrenInRange.getSecond(); while(true) { result.add(first); if (first == last) break; first = first.getNextSibling(); } return PsiUtilCore.toPsiElementArray(result); }
@Nullable public PsiElement resolve() { PsiElement result = doResolve(); if (result == null) { if (MavenDomUtil.isMavenFile(getElement())) { result = tryResolveToActivationSection(); if (result == null) return null; } } if (result instanceof XmlTag) { XmlTagChild[] children = ((XmlTag)result).getValue().getChildren(); if (children.length != 1 || !(children[0] instanceof Navigatable)) return result; return new MavenPsiElementWrapper(result, (Navigatable)children[0]); } return result; }
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { final PsiElement element = descriptor.getPsiElement(); if (element != null) { final PsiFile containingFile = element.getContainingFile(); LOG.assertTrue(containingFile != null && JavaFxFileTypeFactory.isFxml(containingFile), containingFile == null ? "no containing file found" : "containing file: " + containingFile.getName()); final XmlTag xmlTag = PsiTreeUtil.getParentOfType(element, XmlTag.class); if (xmlTag != null) { final XmlTag parentTag = xmlTag.getParentTag(); final PsiElement[] children = PsiTreeUtil.getChildrenOfType(xmlTag, XmlTagChild.class); if (children != null) { if (!FileModificationService.getInstance().preparePsiElementsForWrite(element)) return; if (children.length > 0) { parentTag.addRange(children[0], children[children.length - 1]); } xmlTag.delete(); CodeStyleManager.getInstance(project).reformat(parentTag); } } } }
@NotNull public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) { final Pair<XmlTagChild, XmlTagChild> childrenInRange = XmlUtil.findTagChildrenInRange(file, startOffset, endOffset); if (childrenInRange == null) { final PsiElement elementAt = file.findElementAt(startOffset); if (elementAt instanceof XmlToken && ((XmlToken)elementAt).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) { return new PsiElement[] {elementAt}; } return PsiElement.EMPTY_ARRAY; } List<PsiElement> result = new ArrayList<PsiElement>(); PsiElement first = childrenInRange.getFirst(); PsiElement last = childrenInRange.getSecond(); while(true) { result.add(first); if (first == last) break; first = first.getNextSibling(); } return PsiUtilCore.toPsiElementArray(result); }
@Override @NotNull public XmlText[] getTextElements() { XmlText[] textElements = myTextElements; if(textElements != null) { return textElements; } final List<XmlText> textElementsList = new ArrayList<XmlText>(); for(final XmlTagChild element : myElements) { if(element instanceof XmlText) { textElementsList.add((XmlText) element); } } return myTextElements = textElementsList.isEmpty() ? XmlText.EMPTY_ARRAY : ContainerUtil.toArray(textElementsList, new XmlText[textElementsList.size()]); }
@Override @NotNull public String getText() { String text = myText; if(text != null) { return text; } final StringBuilder consolidatedText = new StringBuilder(); for(final XmlTagChild element : myElements) { consolidatedText.append(element.getText()); } return myText = consolidatedText.toString(); }
@NotNull public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) { final Pair<XmlTagChild, XmlTagChild> childrenInRange = XmlUtil.findTagChildrenInRange(file, startOffset, endOffset); if (childrenInRange == null) { final PsiElement elementAt = file.findElementAt(startOffset); if (elementAt instanceof XmlToken && ((XmlToken)elementAt).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) { return new PsiElement[] {elementAt}; } return PsiElement.EMPTY_ARRAY; } List<PsiElement> result = new ArrayList<PsiElement>(); PsiElement first = childrenInRange.getFirst(); PsiElement last = childrenInRange.getSecond(); while(true) { result.add(first); if (first == last) break; first = first.getNextSibling(); } return PsiUtilBase.toPsiElementArray(result); }
private void checkClassReferenceInStaticContext(final JSExpression node, @PropertyKey(resourceBundle = JavaScriptBundle.BUNDLE) String key) { PsiElement element = PsiTreeUtil.getParentOfType(node, JSFunction.class, JSFile.class, JSClass.class, JSObjectLiteralExpression.class, XmlTagChild.class); if(element instanceof JSFunction) { final JSFunction function = (JSFunction) element; final JSAttributeList attributeList = function.getAttributeList(); if(attributeList != null && attributeList.hasModifier(JSAttributeList.ModifierType.STATIC)) { myHolder.createErrorAnnotation(node, JavaScriptBundle.message(key)); return; } } PsiElement elementParent; if(node instanceof JSSuperExpression && (element == null || (!((elementParent = element.getParent()) instanceof JSClass) && (!(elementParent instanceof JSFile) || elementParent.getContext() == null)))) { myHolder.createErrorAnnotation(node, JavaScriptBundle.message("javascript.validation.message.super.referenced.without.class.instance.context")); } }
@Override public void visitJSReturnStatement(final JSReturnStatement node) { final PsiElement element = PsiTreeUtil.getParentOfType(node, JSFunction.class, XmlTagChild.class, XmlAttributeValue.class, JSFile.class); if((element instanceof JSFile && !(element.getContext() instanceof PsiLanguageInjectionHost)) || (element instanceof XmlTagChild && !(element .getParent() instanceof XmlAttributeValue))) { myHolder.createErrorAnnotation(node, JavaScriptBundle.message("javascript.validation.message.return.outside.function.definition")); } if(element instanceof JSFunction) { final @NonNls String typeString = ((JSFunction) element).getReturnTypeString(); if(typeString != null && !"void".equals(typeString) && node.getExpression() == null) { myHolder.createErrorAnnotation(node, JavaScriptBundle.message("javascript.validation.message.return.value.of.type.is.required", typeString)); } } }
private static boolean isTerminated(JSStatement statement) { final PsiElement parent = statement.getParent(); if(parent instanceof JSForInStatement || parent instanceof JSForStatement) { return true; } final String text = statement.getText(); if(text == null) { return true; } boolean terminated = text.endsWith(";"); if(!terminated) { PsiElement container = PsiTreeUtil.getNonStrictParentOfType(parent, JSFile.class, XmlAttributeValue.class, XmlTagChild.class); if(container instanceof JSFile) { container = container.getContext(); } terminated = container instanceof XmlAttributeValue; // some inline javascript } return terminated; }
public static PomModelEvent createXmlTagChildChanged(PomModel source, XmlTag context, XmlTagChild treeElement) { final PomModelEvent event = new PomModelEvent(source); final XmlAspectChangeSetImpl xmlAspectChangeSet = new XmlAspectChangeSetImpl(source, PsiTreeUtil.getParentOfType(context, XmlFile.class)); xmlAspectChangeSet.add(new XmlTagChildChangedImpl(context, treeElement)); event.registerChangeSet(source.getModelAspect(XmlAspect.class), xmlAspectChangeSet); return event; }
public static XmlTagValue createXmlTagValue(XmlTag tag) { final List<XmlTagChild> bodyElements = new ArrayList<XmlTagChild>(); tag.processElements(new PsiElementProcessor() { boolean insideBody = false; @Override public boolean execute(@NotNull PsiElement element) { final ASTNode treeElement = element.getNode(); if(insideBody) { if(treeElement != null && treeElement.getElementType() == XmlTokenType.XML_END_TAG_START) { return false; } if(!(element instanceof XmlTagChild)) { return true; } bodyElements.add((XmlTagChild) element); } else if(treeElement != null && treeElement.getElementType() == XmlTokenType.XML_TAG_END) { insideBody = true; } return true; } }, tag); XmlTagChild[] tagChildren = ContainerUtil.toArray(bodyElements, new XmlTagChild[bodyElements.size()]); return new XmlTagValueImpl(tagChildren, tag); }
@Override public XmlTagChild getNextSiblingInTag() { PsiElement nextSibling = getNextSibling(); if(nextSibling instanceof XmlTagChild) { return (XmlTagChild) nextSibling; } return null; }
@Override public XmlTagChild getPrevSiblingInTag() { PsiElement prevSibling = getPrevSibling(); if(prevSibling instanceof XmlTagChild) { return (XmlTagChild) prevSibling; } return null; }
private boolean doInjectTo(final XmlTag tag) { final XmlTagValue value = tag.getValue(); final XmlTagChild[] tagChildren = value.getChildren(); return tagChildren.length == 1 && (tagChildren[0].getNode().getElementType() == XmlElementType.XML_CDATA || !tagChildren[0].textContains('<')); }
public static void processInjectedFileForTag(final @NotNull XmlTag tag, @NotNull JSInjectedFilesVisitor visitor) { for(XmlTagChild child : tag.getValue().getChildren()) { if(child instanceof XmlText) { InjectedLanguageUtil.enumerate(child, visitor); } } }
@Override public XmlTagChild getPrevSiblingInTag() { final PsiElement prevSibling = getPrevSibling(); if(prevSibling instanceof XmlTagChild) { return (XmlTagChild) prevSibling; } return null; }
private PsiElement findNearestClass() { PsiElement elt = element; PsiElement parent; while(!((parent = elt.getParent()) instanceof JSFile) && !(parent instanceof JSPackageStatement)) { if(parent instanceof XmlTagChild) { break; } elt = parent; if(elt == null || elt instanceof JSClass) { break; } } if(parent instanceof XmlTag && XmlBackedJSClassImpl.isInlineComponentTag((XmlTag) parent)) { elt = XmlBackedJSClassImpl.getXmlBackedClass((XmlTag) parent); } if(elt != null && !(elt instanceof JSClass)) { elt = elt.getNextSibling(); if(elt instanceof PsiWhiteSpace) { elt = elt.getNextSibling(); } } return elt; }
@Override @Nullable public XmlTagChild getNextSiblingInTag() { return xmlTag.getNextSiblingInTag(); }
@Override @Nullable public XmlTagChild getPrevSiblingInTag() { return xmlTag.getPrevSiblingInTag(); }
public XmlTagChildChangedImpl(XmlTag context, XmlTagChild treeElement) { myTag = context; myChild = treeElement; }
@Override public XmlTagChild getChild() { return myChild; }
public XmlTagChildAddImpl(XmlTag context, XmlTagChild treeElement) { myTag = context; myChild = treeElement; }
public XmlTagChildRemovedImpl(XmlTag context, XmlTagChild treeElement) { myTag = context; myChild = treeElement; }
@Override public XmlTagChild getNextSiblingInTag() { return null; }
@Override public XmlTagChild getPrevSiblingInTag() { return null; }
@Override public XmlTagChild getNextSiblingInTag() { PsiElement nextSibling = getNextSibling(); if (nextSibling instanceof XmlTagChild) return (XmlTagChild)nextSibling; return null; }
@Override public XmlTagChild getPrevSiblingInTag() { final PsiElement prevSibling = getPrevSibling(); if (prevSibling instanceof XmlTagChild) return (XmlTagChild)prevSibling; return null; }
public XmlTagChild getNextSiblingInTag() { PsiElement nextSibling = getNextSibling(); if(nextSibling instanceof XmlTagChild) return (XmlTagChild)nextSibling; return null; }
public XmlTagChild getPrevSiblingInTag() { final PsiElement prevSibling = getPrevSibling(); if(prevSibling instanceof XmlTagChild) return (XmlTagChild)prevSibling; return null; }