use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class ElementProcessor method processExternalFile.
public void processExternalFile(PsiFile psiFile, XmlTag place) {
final XmlDocument document = ((XmlFile) psiFile).getDocument();
assert document != null;
final XmlTag rootTag = document.getRootTag();
assert rootTag != null;
myInclude++;
try {
rootTag.processElements(new PsiElementProcessor() {
public boolean execute(@NotNull PsiElement element) {
if (element instanceof XmlTag) {
return process((XmlTag) element);
}
return shouldContinue();
}
}, place);
} finally {
myInclude--;
}
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class JavaFxUnusedImportsInspection method checkFile.
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, final boolean isOnTheFly) {
if (!JavaFxFileTypeFactory.isFxml(file))
return null;
final XmlDocument document = ((XmlFile) file).getDocument();
if (document == null)
return null;
final Set<String> usedNames = new HashSet<>();
file.accept(new JavaFxImportsOptimizer.JavaFxUsedClassesVisitor() {
@Override
protected void appendClassName(String fqn) {
usedNames.add(fqn);
final String packageName = StringUtil.getPackageName(fqn);
if (!StringUtil.isEmpty(packageName)) {
usedNames.add(packageName);
}
}
@Override
protected void appendDemandedPackageName(@NotNull String packageName) {
usedNames.add(packageName);
}
});
final InspectionManager inspectionManager = InspectionManager.getInstance(file.getProject());
final List<ProblemDescriptor> problems = new ArrayList<>();
final Collection<XmlProcessingInstruction> instructions = PsiTreeUtil.findChildrenOfType(document.getProlog(), XmlProcessingInstruction.class);
final Map<String, XmlProcessingInstruction> targetProcessingInstructions = new LinkedHashMap<>();
for (XmlProcessingInstruction instruction : instructions) {
final String target = JavaFxPsiUtil.getInstructionTarget("import", instruction);
if (target != null) {
targetProcessingInstructions.put(target, instruction);
}
}
for (String target : targetProcessingInstructions.keySet()) {
final XmlProcessingInstruction instruction = targetProcessingInstructions.get(target);
if (target.endsWith(".*")) {
if (!usedNames.contains(StringUtil.trimEnd(target, ".*"))) {
problems.add(inspectionManager.createProblemDescriptor(instruction, "Unused import", new JavaFxOptimizeImportsFix(), ProblemHighlightType.LIKE_UNUSED_SYMBOL, isOnTheFly));
}
} else if (!usedNames.contains(target) || targetProcessingInstructions.containsKey(StringUtil.getPackageName(target) + ".*")) {
problems.add(inspectionManager.createProblemDescriptor(instruction, "Unused import", new JavaFxOptimizeImportsFix(), ProblemHighlightType.LIKE_UNUSED_SYMBOL, isOnTheFly));
}
}
return problems.isEmpty() ? null : problems.toArray(new ProblemDescriptor[problems.size()]);
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class MavenPropertyPsiReference method processSchema.
@Nullable
private <T> T processSchema(String schema, SchemaProcessor<T> processor) {
VirtualFile file = MavenSchemaProvider.getSchemaFile(schema);
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
if (!(psiFile instanceof XmlFile))
return null;
XmlFile xmlFile = (XmlFile) psiFile;
XmlDocument document = xmlFile.getDocument();
XmlNSDescriptor desc = (XmlNSDescriptor) document.getMetaData();
XmlElementDescriptor[] descriptors = desc.getRootElementsDescriptors(document);
return doProcessSchema(descriptors, null, processor, new THashSet<>());
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class RngNsDescriptor method validate.
@Override
public void validate(@NotNull PsiElement context, @NotNull final ValidationHost host) {
final XmlDocument doc = PsiTreeUtil.getContextOfType(context, XmlDocument.class, false);
if (doc == null) {
return;
}
final XmlTag rootTag = doc.getRootTag();
if (rootTag == null) {
return;
}
// RNG XML itself is validated by parsing it with Jing, so we don't want to schema-validate it
if (!ApplicationLoader.RNG_NAMESPACE.equals(rootTag.getNamespace())) {
XmlInstanceValidator.doValidation(doc, host, getDescriptorFile());
}
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class ConvertSchemaAction method getInputType.
private static SchemaType getInputType(Project project, VirtualFile... files) {
if (files.length == 0)
return null;
final VirtualFile file = files[0];
final FileType type = file.getFileType();
if (type == StdFileTypes.XML) {
final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (psiFile instanceof XmlFile) {
final XmlDocument document = ((XmlFile) psiFile).getDocument();
if (document != null && document.getRootTag() != null) {
final XmlTag rootTag = document.getRootTag();
assert rootTag != null;
final String uri = rootTag.getNamespace();
if (ApplicationLoader.RNG_NAMESPACE.equals(uri) && files.length == 1) {
return SchemaType.RNG;
}
}
}
if (files.length > 1) {
for (VirtualFile virtualFile : files) {
if (virtualFile.getFileType() != StdFileTypes.XML || getInputType(project, virtualFile) != null) {
return null;
}
}
}
return SchemaType.XML;
} else if (type == StdFileTypes.DTD && files.length == 1) {
return SchemaType.DTD;
} else if (type == RncFileType.getInstance() && files.length == 1) {
return SchemaType.RNC;
}
return null;
}
Aggregations