use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.
the class MavenPluginParamInfo method getParamInfoList.
public static ParamInfoList getParamInfoList(@NotNull XmlTag paramTag) {
XmlTag configurationTag = paramTag;
DomElement domElement;
Map m = getMap().get(paramTag.getName());
while (true) {
if (m == null)
return ParamInfoList.EMPTY;
configurationTag = configurationTag.getParentTag();
if (configurationTag == null)
return ParamInfoList.EMPTY;
String tagName = configurationTag.getName();
if ("configuration".equals(tagName)) {
domElement = DomManager.getDomManager(configurationTag.getProject()).getDomElement(configurationTag);
if (domElement instanceof MavenDomConfiguration) {
break;
}
if (domElement != null)
return ParamInfoList.EMPTY;
}
m = (Map) m.get(tagName);
}
Map<Pair<String, String>, Map<String, ParamInfo>> pluginsMap = m;
MavenDomConfiguration domCfg = (MavenDomConfiguration) domElement;
MavenDomPlugin domPlugin = domCfg.getParentOfType(MavenDomPlugin.class, true);
if (domPlugin == null)
return ParamInfoList.EMPTY;
String pluginGroupId = domPlugin.getGroupId().getStringValue();
String pluginArtifactId = domPlugin.getArtifactId().getStringValue();
Map<String, ParamInfo> goalsMap;
if (pluginGroupId == null) {
goalsMap = pluginsMap.get(Pair.create("org.apache.maven.plugins", pluginArtifactId));
if (goalsMap == null) {
goalsMap = pluginsMap.get(Pair.create("org.codehaus.mojo", pluginArtifactId));
}
} else {
goalsMap = pluginsMap.get(Pair.create(pluginGroupId, pluginArtifactId));
}
if (goalsMap == null)
return ParamInfoList.EMPTY;
DomElement parent = domCfg.getParent();
if (parent instanceof MavenDomPluginExecution) {
SmartList<ParamInfo> infos = null;
MavenDomGoals goals = ((MavenDomPluginExecution) parent).getGoals();
for (MavenDomGoal goal : goals.getGoals()) {
ParamInfo info = goalsMap.get(goal.getStringValue());
if (info != null) {
if (infos == null) {
infos = new SmartList<>();
}
infos.add(info);
}
}
if (infos != null) {
ParamInfo defaultInfo = goalsMap.get(null);
if (defaultInfo != null) {
infos.add(defaultInfo);
}
return new ParamInfoList(domCfg, infos);
}
}
ParamInfo defaultInfo = goalsMap.get(null);
if (defaultInfo != null) {
return new ParamInfoList(domCfg, Collections.singletonList(defaultInfo));
}
return ParamInfoList.EMPTY;
}
use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.
the class MavenGroovyPomCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
final PsiElement position = parameters.getPosition();
if (!(position instanceof LeafElement))
return;
Project project = position.getProject();
VirtualFile virtualFile = parameters.getOriginalFile().getVirtualFile();
if (virtualFile == null)
return;
MavenProject mavenProject = MavenProjectsManager.getInstance(project).findProject(virtualFile);
if (mavenProject == null)
return;
List<String> methodCallInfo = MavenGroovyPomUtil.getGroovyMethodCalls(position);
if (methodCallInfo.isEmpty())
return;
StringBuilder buf = new StringBuilder();
for (String s : methodCallInfo) {
buf.append('<').append(s).append('>');
}
for (String s : ContainerUtil.reverse(methodCallInfo)) {
buf.append('<').append(s).append("/>");
}
PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText("pom.xml", XMLLanguage.INSTANCE, buf);
psiFile.putUserData(ORIGINAL_POM_FILE, virtualFile);
List<Object> variants = ContainerUtil.newArrayList();
String lastMethodCall = ContainerUtil.getLastItem(methodCallInfo);
Ref<Boolean> completeDependency = Ref.create(false);
Ref<Boolean> completeVersion = Ref.create(false);
psiFile.accept(new PsiRecursiveElementVisitor(true) {
@Override
public void visitElement(PsiElement element) {
super.visitElement(element);
if (!completeDependency.get() && element.getParent() instanceof XmlTag && "dependency".equals(((XmlTag) element.getParent()).getName())) {
if ("artifactId".equals(lastMethodCall) || "groupId".equals(lastMethodCall)) {
completeDependency.set(true);
} else if ("version".equals(lastMethodCall) || "dependency".equals(lastMethodCall)) {
completeVersion.set(true);
//completeDependency.set(true);
}
}
if (!completeDependency.get() && !completeVersion.get()) {
PsiReference[] references = getReferences(element);
for (PsiReference each : references) {
if (each instanceof GenericDomValueReference) {
Collections.addAll(variants, each.getVariants());
}
}
}
}
});
for (Object variant : variants) {
if (variant instanceof LookupElement) {
result.addElement((LookupElement) variant);
} else {
result.addElement(LookupElementBuilder.create(variant));
}
}
if (completeDependency.get()) {
MavenProjectIndicesManager indicesManager = MavenProjectIndicesManager.getInstance(project);
for (String groupId : indicesManager.getGroupIds()) {
for (String artifactId : indicesManager.getArtifactIds(groupId)) {
LookupElement builder = LookupElementBuilder.create(groupId + ':' + artifactId).withIcon(AllIcons.Nodes.PpLib).withInsertHandler(MavenDependencyInsertHandler.INSTANCE);
result.addElement(builder);
}
}
}
if (completeVersion.get()) {
consumeDependencyElement(position, closableBlock -> {
String groupId = null;
String artifactId = null;
for (GrMethodCall methodCall : PsiTreeUtil.findChildrenOfType(closableBlock, GrMethodCall.class)) {
GroovyPsiElement[] arguments = methodCall.getArgumentList().getAllArguments();
if (arguments.length != 1)
continue;
PsiReference reference = arguments[0].getReference();
if (reference == null)
continue;
String callExpression = methodCall.getInvokedExpression().getText();
String argumentValue = reference.getCanonicalText();
if ("groupId".equals(callExpression)) {
groupId = argumentValue;
} else if ("artifactId".equals(callExpression)) {
artifactId = argumentValue;
}
}
completeVersions(result, project, groupId, artifactId, "");
}, element -> {
if (element.getParent() instanceof PsiLiteral) {
Object value = ((PsiLiteral) element.getParent()).getValue();
if (value == null)
return;
String[] mavenCoordinates = value.toString().split(":");
if (mavenCoordinates.length < 3)
return;
String prefix = mavenCoordinates[0] + ':' + mavenCoordinates[1] + ':';
completeVersions(result, project, mavenCoordinates[0], mavenCoordinates[1], prefix);
}
});
}
}
use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.
the class MavenNavigationUtil method createNavigatableForDependency.
@Nullable
public static Navigatable createNavigatableForDependency(final Project project, final VirtualFile file, final MavenArtifact artifact) {
return new NavigatableAdapter() {
public void navigate(boolean requestFocus) {
if (!file.isValid())
return;
MavenDomProjectModel projectModel = MavenDomUtil.getMavenDomProjectModel(project, file);
if (projectModel == null)
return;
MavenDomDependency dependency = findDependency(projectModel, artifact.getGroupId(), artifact.getArtifactId());
if (dependency == null)
return;
XmlTag artifactId = dependency.getArtifactId().getXmlTag();
if (artifactId == null)
return;
navigate(project, artifactId.getContainingFile().getVirtualFile(), artifactId.getTextOffset() + artifactId.getName().length() + 2, requestFocus);
}
};
}
use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.
the class UndeclaredTestInspection method checkClass.
@Nullable
public ProblemDescriptor[] checkClass(@NotNull final PsiClass aClass, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
if (TestNGUtil.hasTest(aClass) && PsiClassUtil.isRunnableClass(aClass, true)) {
final Project project = aClass.getProject();
final String qName = aClass.getQualifiedName();
if (qName == null)
return null;
final String packageQName = StringUtil.getPackageName(qName);
final List<String> names = new ArrayList<>();
for (int i = 0; i < qName.length(); i++) {
if (qName.charAt(i) == '.') {
names.add(qName.substring(0, i));
}
}
names.add(qName);
Collections.reverse(names);
for (final String name : names) {
final boolean isFullName = qName.equals(name);
final boolean[] found = new boolean[] { false };
PsiSearchHelper.SERVICE.getInstance(project).processUsagesInNonJavaFiles(name, (file, startOffset, endOffset) -> {
if (file.findReferenceAt(startOffset) != null) {
if (!isFullName) {
//special package tag required
final XmlTag tag = PsiTreeUtil.getParentOfType(file.findElementAt(startOffset), XmlTag.class);
if (tag == null || !tag.getName().equals("package")) {
return true;
}
final XmlAttribute attribute = tag.getAttribute("name");
if (attribute == null)
return true;
final String value = attribute.getValue();
if (value == null)
return true;
if (!value.endsWith(".*") && !value.equals(packageQName))
return true;
}
found[0] = true;
return false;
}
return true;
}, new TestNGSearchScope(project));
if (found[0])
return null;
}
final PsiIdentifier nameIdentifier = aClass.getNameIdentifier();
LOG.assertTrue(nameIdentifier != null);
return new ProblemDescriptor[] { manager.createProblemDescriptor(nameIdentifier, "Undeclared test \'" + aClass.getName() + "\'", isOnTheFly, new LocalQuickFix[] { new RegisterClassFix(aClass), new CreateTestngFix() }, ProblemHighlightType.GENERIC_ERROR_OR_WARNING) };
}
return null;
}
use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.
the class HtmlUnknownBooleanAttributeInspectionBase method checkAttribute.
@Override
protected void checkAttribute(@NotNull final XmlAttribute attribute, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
if (attribute.getValueElement() == null) {
final XmlTag tag = attribute.getParent();
if (tag instanceof HtmlTag) {
XmlElementDescriptor elementDescriptor = tag.getDescriptor();
if (elementDescriptor == null || elementDescriptor instanceof AnyXmlElementDescriptor) {
return;
}
XmlAttributeDescriptor attributeDescriptor = elementDescriptor.getAttributeDescriptor(attribute);
if (attributeDescriptor != null && !(attributeDescriptor instanceof AnyXmlAttributeDescriptor)) {
String name = attribute.getName();
if (!HtmlUtil.isBooleanAttribute(attributeDescriptor, null) && (!isCustomValuesEnabled() || !isCustomValue(name))) {
final boolean html5 = HtmlUtil.isHtml5Context(tag);
LocalQuickFix[] quickFixes = !html5 ? new LocalQuickFix[] { new AddCustomHtmlElementIntentionAction(BOOLEAN_ATTRIBUTE_KEY, name, XmlBundle.message("add.custom.html.boolean.attribute", name)), XmlQuickFixFactory.getInstance().addAttributeValueFix(attribute), new RemoveAttributeIntentionAction(name) } : new LocalQuickFix[] { XmlQuickFixFactory.getInstance().addAttributeValueFix(attribute) };
String error = null;
if (html5) {
if (attributeDescriptor instanceof XmlEnumerationDescriptor && ((XmlEnumerationDescriptor) attributeDescriptor).getValueDeclaration(attribute, "") == null) {
error = XmlErrorMessages.message("wrong.value", "attribute");
}
} else {
error = XmlErrorMessages.message("attribute.is.not.boolean", attribute.getName());
}
if (error != null) {
registerProblemOnAttributeName(attribute, error, holder, quickFixes);
}
}
}
}
}
}
Aggregations