use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class XsltDeclarationInspection method buildVisitor.
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
if (!(holder.getFile() instanceof XmlFile))
return PsiElementVisitor.EMPTY_VISITOR;
return new XmlElementVisitor() {
@Override
public void visitXmlTag(final XmlTag tag) {
final XmlAttribute nameAttr = tag.getAttribute("name", null);
if (nameAttr == null || PsiTreeUtil.hasErrorElements(nameAttr))
return;
if (XsltSupport.isVariableOrParam(tag)) {
final XsltNamedElement instance = getXsltElementFactory().wrapElement(tag, XsltNamedElement.class);
checkDeclaration(instance, nameAttr.getValue(), holder);
} else if (XsltSupport.isTemplate(tag)) {
final XsltTemplate tmpl = getXsltElementFactory().wrapElement(tag, XsltTemplate.class);
checkDeclaration(tmpl, nameAttr.getValue(), holder);
}
}
private void checkDeclaration(final XsltNamedElement element, final String name, ProblemsHolder holder) {
final XmlTag tag = element.getTag();
final PsiElement token = element.getNameIdentifier();
if (name == null || name.length() == 0) {
if (token != null) {
holder.registerProblem(token, "Empty name not permitted");
} else {
final XmlAttribute attribute = element.getNameAttribute();
if (attribute != null) {
final XmlAttributeValue e = attribute.getValueElement();
if (e != null) {
holder.registerProblem(e, "Empty name not permitted");
}
}
}
} else if (!isLegalName(name, holder.getManager().getProject())) {
assert token != null;
holder.registerProblem(token, "Illegal name");
} else {
assert token != null;
final XmlFile file = (XmlFile) tag.getContainingFile();
final XmlTag duplicatedSymbol = DeclarationChecker.getInstance(file).getDuplicatedSymbol(tag);
if (duplicatedSymbol != null) {
if (duplicatedSymbol.getContainingFile() == file) {
holder.registerProblem(token, "Duplicate declaration");
} else {
holder.registerProblem(token, "Duplicates declaration from '" + duplicatedSymbol.getContainingFile().getName() + "'");
}
}
}
}
private boolean isLegalName(String value, Project project) {
return getNamesValidator().isIdentifier(value, project);
}
};
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class LinkedToHtmlFilesContributor method fillRelatedFiles.
@Override
public void fillRelatedFiles(@NotNull final XmlFile xmlFile, @NotNull final Set<PsiFile> resultSet) {
HtmlLinkUtil.processLinks(xmlFile, tag -> {
final XmlAttribute attribute = tag.getAttribute("href");
if (attribute == null) {
return true;
}
final XmlAttributeValue link = attribute.getValueElement();
if (link == null) {
return true;
}
for (PsiReference reference : link.getReferences()) {
if (reference instanceof PsiPolyVariantReference) {
final ResolveResult[] results = ((PsiPolyVariantReference) reference).multiResolve(false);
for (ResolveResult result : results) {
final PsiElement resolvedElement = result.getElement();
if (resolvedElement instanceof PsiFile) {
resultSet.add((PsiFile) resolvedElement);
}
}
} else {
final PsiElement resolvedElement = reference.resolve();
if (resolvedElement instanceof PsiFile) {
resultSet.add((PsiFile) resolvedElement);
}
}
}
return true;
});
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class XmlDuplicatedIdInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
return new XmlElementVisitor() {
@Override
public void visitXmlAttributeValue(final XmlAttributeValue value) {
if (value.getTextRange().isEmpty()) {
return;
}
final PsiFile file = value.getContainingFile();
if (!(file instanceof XmlFile)) {
return;
}
PsiFile baseFile = PsiUtilCore.getTemplateLanguageFile(file);
if (baseFile != file && !(baseFile instanceof XmlFile)) {
return;
}
final XmlRefCountHolder refHolder = XmlRefCountHolder.getRefCountHolder((XmlFile) file);
if (refHolder == null)
return;
final PsiElement parent = value.getParent();
if (!(parent instanceof XmlAttribute))
return;
final XmlTag tag = (XmlTag) parent.getParent();
if (tag == null)
return;
checkValue(value, (XmlFile) file, refHolder, tag, holder);
}
};
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class RngRefImpl method getPattern.
@Override
public Define getPattern() {
final XmlAttributeValue value = getName().getXmlAttributeValue();
if (value == null)
return null;
final String name = getReferencedName();
if (name == null) {
return null;
}
final RngGrammar scope = getScope();
if (scope == null) {
return null;
}
final Set<Define> defines = DefinitionResolver.resolve(scope, name);
// TODO: honor combine & return virtual element if defines.size() > 1
return defines != null && defines.size() > 0 ? defines.iterator().next() : null;
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.
the class SpellcheckingStrategy method getTokenizer.
@NotNull
public Tokenizer getTokenizer(PsiElement element) {
if (element instanceof PsiWhiteSpace) {
return EMPTY_TOKENIZER;
}
if (element instanceof PsiLanguageInjectionHost && InjectedLanguageUtil.hasInjections((PsiLanguageInjectionHost) element)) {
return EMPTY_TOKENIZER;
}
if (element instanceof PsiNameIdentifierOwner)
return new PsiIdentifierOwnerTokenizer();
if (element instanceof PsiComment) {
if (SuppressionUtil.isSuppressionComment(element)) {
return EMPTY_TOKENIZER;
}
return myCommentTokenizer;
}
if (element instanceof XmlAttributeValue)
return myXmlAttributeTokenizer;
if (element instanceof PsiPlainText) {
PsiFile file = element.getContainingFile();
FileType fileType = file == null ? null : file.getFileType();
if (fileType instanceof CustomSyntaxTableFileType) {
return new CustomFileTypeTokenizer(((CustomSyntaxTableFileType) fileType).getSyntaxTable());
}
return TEXT_TOKENIZER;
}
if (element instanceof XmlToken) {
if (((XmlToken) element).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) {
PsiElement injection = InjectedLanguageManager.getInstance(element.getProject()).findInjectedElementAt(element.getContainingFile(), element.getTextOffset());
if (injection == null) {
return TEXT_TOKENIZER;
}
}
}
return EMPTY_TOKENIZER;
}
Aggregations