use of org.jetbrains.idea.maven.dom.MavenDomProjectModelDescription in project intellij-community by JetBrains.
the class MavenGroovyPomScriptMemberContributor method processDynamicElements.
@Override
public void processDynamicElements(@NotNull PsiType qualifierType, PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) {
PsiElement pomElement = aClass.getContainingFile().getContext();
if (pomElement == null)
return;
PsiFile pomFile = pomElement.getContainingFile();
if (!(pomFile instanceof XmlFile))
return;
DomManager domManager = DomManager.getDomManager(pomElement.getProject());
if (!(domManager.getDomFileDescription((XmlFile) pomFile) instanceof MavenDomProjectModelDescription)) {
return;
}
DynamicMemberUtils.process(processor, false, place, CLASS_SOURCE);
}
use of org.jetbrains.idea.maven.dom.MavenDomProjectModelDescription in project intellij-community by JetBrains.
the class MavenPomXmlCompletionTagListenerContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull final CompletionResultSet result) {
if (TemplateManager.getInstance(parameters.getOriginalFile().getProject()).getActiveTemplate(parameters.getEditor()) != null) {
// Don't brake the template.
return;
}
PsiFile psiFile = parameters.getOriginalFile();
if (!(psiFile instanceof XmlFile))
return;
if (!MavenDomUtil.isProjectFile(psiFile))
return;
DomFileDescription<?> description = DomManager.getDomManager(psiFile.getProject()).getDomFileDescription((XmlFile) psiFile);
if (!(description instanceof MavenDomProjectModelDescription))
return;
result.runRemainingContributors(parameters, r -> {
final LookupElement lookupElement = r.getLookupElement();
if (myHandledTags.contains(lookupElement.getLookupString())) {
LookupElement decorator = LookupElementDecorator.withInsertHandler(lookupElement, new InsertHandler<LookupElementDecorator<LookupElement>>() {
@Override
public void handleInsert(final InsertionContext context, LookupElementDecorator<LookupElement> item) {
lookupElement.handleInsert(context);
Object object = lookupElement.getObject();
if ("dependency".equals(lookupElement.getLookupString()) && object instanceof XmlTag && "maven-4.0.0.xsd".equals(((XmlTag) object).getContainingFile().getName())) {
context.commitDocument();
CaretModel caretModel = context.getEditor().getCaretModel();
PsiElement psiElement = context.getFile().findElementAt(caretModel.getOffset());
XmlTag xmlTag = PsiTreeUtil.getParentOfType(psiElement, XmlTag.class);
if (xmlTag != null) {
DomElement domElement = DomManager.getDomManager(context.getProject()).getDomElement(xmlTag);
if (domElement instanceof MavenDomDependency) {
String s = "\n<groupId></groupId>\n<artifactId></artifactId>\n";
context.getDocument().insertString(caretModel.getOffset(), s);
caretModel.moveToOffset(caretModel.getOffset() + s.length() - "</artifactId>\n".length());
context.commitDocument();
new ReformatCodeProcessor(context.getProject(), context.getFile(), xmlTag.getTextRange(), false).run();
MavenDependencyCompletionUtil.invokeCompletion(context, CompletionType.BASIC);
}
}
}
}
});
r = r.withLookupElement(decorator);
}
result.passResult(r);
});
}
Aggregations