use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.
the class AntResolveInspection method checkDomElement.
protected void checkDomElement(DomElement element, DomElementAnnotationHolder holder, DomHighlightingHelper helper) {
if (element instanceof GenericDomValue) {
final XmlElement valueElement = DomUtil.getValueElement(((GenericDomValue) element));
if (valueElement != null) {
checkReferences(valueElement, holder, element);
}
} else if (element instanceof AntDomTypeDef) {
final AntDomTypeDef typeDef = (AntDomTypeDef) element;
final List<String> errors = typeDef.getErrorDescriptions();
if (!errors.isEmpty()) {
final StringBuilder builder = new StringBuilder();
builder.append(AntBundle.message("failed.to.load.types")).append(":");
for (String error : errors) {
builder.append("\n").append(error);
}
holder.createProblem(typeDef, builder.toString());
}
} else if (element instanceof AntDomCustomElement) {
final AntDomCustomElement custom = (AntDomCustomElement) element;
if (custom.getDefinitionClass() == null) {
final AntDomNamedElement declaringElement = custom.getDeclaringElement();
if (declaringElement instanceof AntDomTypeDef) {
String failedMessage = AntBundle.message("using.definition.which.type.failed.to.load");
final String error = custom.getLoadError();
if (error != null) {
failedMessage = failedMessage + ": " + error;
}
holder.createProblem(custom, failedMessage);
}
}
}
}
use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.
the class DependencyConfigFileConverter method fromString.
@Override
public PathReference fromString(@Nullable String s, ConvertContext context) {
final XmlElement element = context.getXmlElement();
final Module module = context.getModule();
if (s == null || element == null || module == null) {
return null;
}
return PathReferenceManager.getInstance().getCustomPathReference(s, module, element, ourProvider);
}
use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.
the class ContextProvider method getQName.
@Nullable
public QName getQName(@NotNull PrefixedName qName, XPathElement context) {
final String prefix = qName.getPrefix();
final NamespaceContext namespaceContext = getNamespaceContext();
if (namespaceContext != null) {
if (prefix != null) {
final XmlElement element = PsiTreeUtil.getContextOfType(context, XmlElement.class, true);
final String namespaceURI = namespaceContext.getNamespaceURI(prefix, element);
return namespaceURI != null && namespaceURI.length() > 0 ? new QName(namespaceURI, qName.getLocalName(), prefix) : null;
} else if (context.getXPathVersion() == XPathVersion.V2) {
if (isDefaultCapableElement(context)) {
final String namespace = namespaceContext.getDefaultNamespace(getContextElement());
if (namespace != null) {
return new QName(namespace, qName.getLocalName());
}
}
}
return new QName(null, qName.getLocalName(), "");
} else if (qName.getPrefix() == null) {
return QName.valueOf(qName.getLocalName());
} else {
return null;
}
}
use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.
the class ShowXPathAction method isEnabledAt.
protected boolean isEnabledAt(XmlFile xmlFile, int offset) {
final PsiElement element = xmlFile.findElementAt(offset);
if (!(element instanceof XmlElement || element instanceof PsiWhiteSpace)) {
return false;
}
final PsiElement node = XPathExpressionGenerator.transformToValidShowPathNode(element);
return node != null;
}
use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.
the class ShowXPathAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
if (editor == null) {
return;
}
final Project project = editor.getProject();
if (project == null) {
return;
}
final PsiDocumentManager docmgr = PsiDocumentManager.getInstance(project);
final Document document = editor.getDocument();
docmgr.commitDocument(document);
final PsiFile psiFile = docmgr.getPsiFile(document);
if (!(psiFile instanceof XmlFile)) {
return;
}
final PsiElement element = psiFile.findElementAt(editor.getCaretModel().getOffset());
if (!(element instanceof XmlElement || element instanceof PsiWhiteSpace)) {
XPathAppComponent.showEditorHint("No suitable context for an XPath-expression selected.", editor);
return;
}
final PsiElement node = XPathExpressionGenerator.transformToValidShowPathNode(element);
if (node == null) {
XPathAppComponent.showEditorHint("No suitable context for an XPath-expression selected.", editor);
return;
}
final Config cfg = XPathAppComponent.getInstance().getConfig();
final RangeHighlighter h = HighlighterUtil.highlightNode(editor, node, cfg.getContextAttributes(), cfg);
final String path = XPathSupport.getInstance().getUniquePath((XmlElement) node, null);
final JTextField label = new JTextField(path);
label.setPreferredSize(new Dimension(label.getPreferredSize().width + new JLabel("M").getPreferredSize().width, label.getPreferredSize().height));
label.setOpaque(false);
label.setEditable(false);
label.setBorder(null);
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
final JPanel p = new NonOpaquePanel(new BorderLayout());
final JLabel l = new JLabel("XPath:");
p.add(l, BorderLayout.WEST);
p.add(label, BorderLayout.CENTER);
InplaceButton copy = new InplaceButton(ActionsBundle.message("action.EditorCopy.text"), PlatformIcons.COPY_ICON, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CopyPasteManager.getInstance().setContents(new StringSelection(path));
}
});
p.add(copy, BorderLayout.EAST);
final LightweightHint hint = new LightweightHint(p) {
public void hide() {
super.hide();
HighlighterUtil.removeHighlighter(editor, h);
}
};
final Point point = editor.visualPositionToXY(editor.getCaretModel().getVisualPosition());
point.y += editor.getLineHeight() / 2;
HintHint hintHint = new HintHint(editor, point).setAwtTooltip(true).setContentActive(true).setExplicitClose(true).setShowImmediately(true);
HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point, HintManager.HIDE_BY_ANY_KEY, 0, false, hintHint);
}
Aggregations