use of com.intellij.xml.XmlElementDescriptor in project intellij-community by JetBrains.
the class XmlParameterInfoHandler method findElementForParameterInfo.
@Override
public XmlTag findElementForParameterInfo(@NotNull final CreateParameterInfoContext context) {
final XmlTag tag = findXmlTag(context.getFile(), context.getOffset());
final XmlElementDescriptor descriptor = tag != null ? tag.getDescriptor() : null;
if (descriptor == null) {
DaemonCodeAnalyzer.getInstance(context.getProject()).updateVisibleHighlighters(context.getEditor());
return null;
}
context.setItemsToShow(new Object[] { descriptor });
return tag;
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-community by JetBrains.
the class MavenPropertyPsiReference method collectVariants.
protected void collectVariants(final List<Object> result, Set<String> variants) {
int prefixLength = 0;
if (myText.startsWith("pom.")) {
prefixLength = "pom.".length();
} else if (myText.startsWith("project.")) {
prefixLength = "project.".length();
}
MavenProject mavenProject = myMavenProject;
while (myText.startsWith("parent.", prefixLength)) {
MavenId parentId = mavenProject.getParentId();
if (parentId == null)
return;
mavenProject = myProjectsManager.findProject(parentId);
if (mavenProject == null)
return;
prefixLength += "parent.".length();
}
final String prefix = prefixLength == 0 ? null : myText.substring(0, prefixLength);
PsiDirectory baseDir = getBaseDir(mavenProject);
addVariant(result, "basedir", baseDir, prefix, MavenIcons.MavenLogo);
if (prefix == null) {
result.add(createLookupElement(baseDir, "project.baseUri", MavenIcons.MavenLogo));
result.add(createLookupElement(baseDir, "pom.baseUri", MavenIcons.MavenLogo));
result.add(LookupElementBuilder.create(TIMESTAMP_PROP).withIcon(MavenIcons.MavenLogo));
}
processSchema(MavenSchemaProvider.MAVEN_PROJECT_SCHEMA_URL, new SchemaProcessor<Object>() {
@Override
public Object process(@NotNull String property, XmlElementDescriptor descriptor) {
if (property.startsWith("project.")) {
addVariant(result, property.substring("project.".length()), descriptor, prefix, MavenIcons.MavenLogo);
}
return null;
}
});
processSchema(MavenSchemaProvider.MAVEN_SETTINGS_SCHEMA_URL, new SchemaProcessor<Object>() {
@Override
public Object process(@NotNull String property, XmlElementDescriptor descriptor) {
result.add(createLookupElement(descriptor, property, MavenIcons.MavenLogo));
return null;
}
});
collectPropertiesVariants(result, variants);
collectSystemEnvProperties(MavenPropertiesVirtualFileSystem.SYSTEM_PROPERTIES_FILE, null, result, variants);
collectSystemEnvProperties(MavenPropertiesVirtualFileSystem.ENV_PROPERTIES_FILE, "env.", result, variants);
MavenRunnerSettings runnerSettings = MavenRunner.getInstance(myProject).getSettings();
for (String prop : runnerSettings.getMavenProperties().keySet()) {
if (variants.add(prefix)) {
result.add(LookupElementBuilder.create(prop).withIcon(PlatformIcons.PROPERTY_ICON));
}
}
for (String prop : MavenUtil.getPropertiesFromMavenOpts().keySet()) {
if (variants.add(prop)) {
result.add(LookupElementBuilder.create(prop).withIcon(PlatformIcons.PROPERTY_ICON));
}
}
for (Object key : myMavenProject.getProperties().keySet()) {
if (key instanceof String) {
String property = (String) key;
if (variants.add(property)) {
result.add(LookupElementBuilder.create(property).withIcon(PlatformIcons.PROPERTY_ICON));
}
}
}
MavenDomConfiguration pluginCfg = DomUtil.findDomElement(myElement, MavenDomConfiguration.class);
if (pluginCfg != null) {
MavenPluginDescriptor.processDescriptors(descriptor -> {
if (descriptor.properties != null) {
for (MavenPluginDescriptor.ModelProperty property : descriptor.properties) {
if (property.insideConfigurationOnly) {
result.add(LookupElementBuilder.create(property.name).withIcon(PlatformIcons.PROPERTY_ICON));
}
}
}
return true;
}, pluginCfg);
}
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-community by JetBrains.
the class MavenPropertyPsiReference method doProcessSchema.
private static <T> T doProcessSchema(XmlElementDescriptor[] descriptors, String prefix, SchemaProcessor<T> processor, Set<XmlElementDescriptor> recursionGuard) {
for (XmlElementDescriptor each : descriptors) {
if (isCollection(each))
continue;
if (!recursionGuard.add(each))
continue;
try {
String name = each.getName();
if (prefix != null)
name = prefix + "." + name;
T result = processor.process(name, each);
if (result != null)
return result;
result = doProcessSchema(each.getElementsDescriptors(null), name, processor, recursionGuard);
if (result != null)
return result;
} finally {
recursionGuard.remove(each);
}
}
return null;
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-community by JetBrains.
the class XsContentDFA method getPossibleElements.
@Override
public List<XmlElementDescriptor> getPossibleElements() {
final List vector = myContentModel.whatCanGoHere(myState);
ArrayList<XmlElementDescriptor> list = new ArrayList<>();
for (Object o : vector) {
if (o instanceof XSElementDecl) {
final XSElementDecl elementDecl = (XSElementDecl) o;
XmlElementDescriptor descriptor = ContainerUtil.find(myElementDescriptors, elementDescriptor -> elementDecl.getName().equals(elementDescriptor.getName()));
ContainerUtil.addIfNotNull(list, descriptor);
}
}
return list;
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-community by JetBrains.
the class GenerateXmlTagAction method invoke.
@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) {
if (!EditorModificationUtil.checkModificationAllowed(editor))
return;
try {
final XmlTag contextTag = getContextTag(editor, file);
if (contextTag == null) {
throw new CommonRefactoringUtil.RefactoringErrorHintException("Caret should be positioned inside a tag");
}
XmlElementDescriptor currentTagDescriptor = contextTag.getDescriptor();
assert currentTagDescriptor != null;
final XmlElementDescriptor[] descriptors = currentTagDescriptor.getElementsDescriptors(contextTag);
Arrays.sort(descriptors, Comparator.comparing(PsiMetaData::getName));
final JBList list = new JBList(descriptors);
list.setCellRenderer(new MyListCellRenderer());
Runnable runnable = () -> {
final XmlElementDescriptor selected = (XmlElementDescriptor) list.getSelectedValue();
new WriteCommandAction.Simple(project, "Generate XML Tag", file) {
@Override
protected void run() {
if (selected == null)
return;
XmlTag newTag = createTag(contextTag, selected);
PsiElement anchor = getAnchor(contextTag, editor, selected);
if (anchor == null) {
// insert it in the cursor position
int offset = editor.getCaretModel().getOffset();
Document document = editor.getDocument();
document.insertString(offset, newTag.getText());
PsiDocumentManager.getInstance(project).commitDocument(document);
newTag = PsiTreeUtil.getParentOfType(file.findElementAt(offset + 1), XmlTag.class, false);
} else {
newTag = (XmlTag) contextTag.addAfter(newTag, anchor);
}
if (newTag != null) {
generateTag(newTag, editor);
}
}
}.execute();
};
if (ApplicationManager.getApplication().isUnitTestMode()) {
XmlElementDescriptor descriptor = ContainerUtil.find(descriptors, xmlElementDescriptor -> xmlElementDescriptor.getName().equals(TEST_THREAD_LOCAL.get()));
list.setSelectedValue(descriptor, false);
runnable.run();
} else {
JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Choose Tag Name").setItemChoosenCallback(runnable).setFilteringEnabled(o -> ((XmlElementDescriptor) o).getName()).createPopup().showInBestPositionFor(editor);
}
} catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
HintManager.getInstance().showErrorHint(editor, e.getMessage());
}
}
Aggregations