use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class DomNameSuggestionProvider method getSuggestedNames.
@Override
public SuggestedNameInfo getSuggestedNames(final PsiElement element, final PsiElement nameSuggestionContext, final Set<String> result) {
if (element instanceof PsiMetaOwner) {
final PsiMetaData psiMetaData = ((PsiMetaOwner) element).getMetaData();
if (psiMetaData instanceof DomMetaData) {
final DomMetaData domMetaData = (DomMetaData) psiMetaData;
final GenericDomValue value = domMetaData.getNameElement(domMetaData.getElement());
ContainerUtil.addIfNotNull(result, getNameFromNameValue(value, true));
}
}
return null;
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class TagNameReference method bindToElement.
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
PsiMetaData metaData = null;
if (element instanceof PsiMetaOwner) {
final PsiMetaOwner owner = (PsiMetaOwner) element;
metaData = owner.getMetaData();
if (metaData instanceof XmlElementDescriptor) {
// TODO: need to evaluate new ns prefix
return getTagElement().setName(metaData.getName(getElement()));
}
} else if (element instanceof PsiFile) {
final XmlTag tagElement = getTagElement();
if (tagElement == null || !myStartTagFlag)
return tagElement;
String newElementName = ((PsiFile) element).getName();
final int index = newElementName.lastIndexOf('.');
// TODO: need to evaluate new ns prefix
newElementName = prependNamespacePrefix(newElementName.substring(0, index), tagElement.getNamespacePrefix());
return getTagElement().setName(newElementName);
}
final XmlTag tag = getTagElement();
throw new IncorrectOperationException("Cant bind to not a xml element definition!" + element + "," + metaData + "," + tag + "," + (tag != null ? tag.getDescriptor() : "unknown descriptor"));
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class XmlElementDescriptorImpl method collectAttributeDescriptors.
// Read-only calculation
@Override
protected final XmlAttributeDescriptor[] collectAttributeDescriptors(final XmlTag context) {
final List<XmlAttributeDescriptor> result = new SmartList<>();
for (XmlAttlistDecl attlistDecl : findAttlistDeclarations(getName())) {
for (XmlAttributeDecl attributeDecl : attlistDecl.getAttributeDecls()) {
final PsiMetaData psiMetaData = attributeDecl.getMetaData();
assert psiMetaData instanceof XmlAttributeDescriptor;
result.add((XmlAttributeDescriptor) psiMetaData);
}
}
return result.toArray(new XmlAttributeDescriptor[result.size()]);
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class CreateNSDeclarationIntentionFix method processExternalUrisImpl.
private static void processExternalUrisImpl(final MetaHandler metaHandler, final PsiFile file, final ExternalUriProcessor processor) {
final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
final String searchFor = metaHandler.searchFor();
if (pi != null)
pi.setText(XmlErrorMessages.message("looking.in.schemas"));
final ExternalResourceManager instanceEx = ExternalResourceManager.getInstance();
final String[] availableUrls = instanceEx.getResourceUrls(null, true);
int i = 0;
for (String url : availableUrls) {
if (pi != null) {
pi.setFraction((double) i / availableUrls.length);
pi.setText2(url);
++i;
}
final XmlFile xmlFile = XmlUtil.findNamespace(file, url);
if (xmlFile != null) {
final boolean wordFound = checkIfGivenXmlHasTheseWords(searchFor, xmlFile);
if (!wordFound)
continue;
final XmlDocument document = xmlFile.getDocument();
assert document != null;
final PsiMetaData metaData = document.getMetaData();
if (metaHandler.isAcceptableMetaData(metaData, url)) {
final XmlNSDescriptorImpl descriptor = metaData instanceof XmlNSDescriptorImpl ? (XmlNSDescriptorImpl) metaData : null;
final String defaultNamespace = descriptor != null ? descriptor.getDefaultNamespace() : url;
// Skip rare stuff
if (!XmlUtil.XML_SCHEMA_URI2.equals(defaultNamespace) && !XmlUtil.XML_SCHEMA_URI3.equals(defaultNamespace)) {
processor.process(defaultNamespace, url);
}
}
}
}
}
Aggregations