Search in sources :

Example 81 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class NoNamespaceSchemaProvider method getSchema.

@Override
@Nullable
public XmlFile getSchema(@NotNull @NonNls String url, @Nullable Module module, @NotNull PsiFile baseFile) {
    if ("".equals(url)) {
        final Project project = baseFile.getProject();
        final VirtualFile file = NoNamespaceConfig.getInstance(project).getMappedFile(baseFile);
        if (file == null)
            return null;
        final PsiFile f = PsiManager.getInstance(project).findFile(file);
        if (f instanceof XmlFile) {
            return (XmlFile) f;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 82 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class ResolvingVisitor method processInclude.

private void processInclude(XmlFile xmlFile, XmlAttribute attribute) {
    final Set<XmlFile> set = myProcessingContext.get(VISITED_KEY);
    if (set.contains(xmlFile)) {
        return;
    }
    set.add(xmlFile);
    final XmlDocument document = xmlFile.getDocument();
    if (document == null)
        return;
    final XmlTag rootTag = document.getRootTag();
    if (rootTag == null)
        return;
    rootTag.processElements(this, attribute);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlTag(com.intellij.psi.xml.XmlTag)

Example 83 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class AntBuildModelImpl method getTargetListImpl.

// todo: return list of dependent psi files as well
private static Pair<List<AntBuildTargetBase>, Collection<Object>> getTargetListImpl(final AntBuildModelBase model) {
    final List<AntBuildTargetBase> list = new ArrayList<>();
    final Set<Object> dependencies = new HashSet<>();
    final AntDomProject project = model.getAntProject();
    if (project != null) {
        final AntBuildFile buildFile = model.getBuildFile();
        final XmlFile xmlFile = buildFile.getAntFile();
        dependencies.add(xmlFile != null ? xmlFile : PsiModificationTracker.MODIFICATION_COUNT);
        final VirtualFile sourceFile = buildFile.getVirtualFile();
        new Object() {

            private boolean myIsImported = false;

            private final Set<VirtualFile> myProcessed = new HashSet<>();

            private AntDomTarget myDefaultTarget = null;

            private void fillTargets(List<AntBuildTargetBase> list, AntBuildModelBase model, AntDomProject project, VirtualFile sourceFile) {
                if (myProcessed.contains(sourceFile)) {
                    return;
                }
                myProcessed.add(sourceFile);
                if (!myIsImported) {
                    final TargetResolver.Result result = project.getDefaultTarget().getValue();
                    if (result != null) {
                        final Pair<AntDomTarget, String> targetWithName = result.getResolvedTarget(project.getDefaultTarget().getRawText());
                        myDefaultTarget = targetWithName != null ? targetWithName.getFirst() : null;
                    }
                }
                for (final AntDomTarget target : project.getDeclaredTargets()) {
                    list.add(new AntBuildTargetImpl(target, model, sourceFile, myIsImported, target.equals(myDefaultTarget)));
                }
                myIsImported = true;
                final Iterable<AntDomIncludingDirective> allIncludes = ContainerUtil.concat((Iterable<AntDomImport>) project.getDeclaredImports(), (Iterable<? extends AntDomInclude>) project.getDeclaredIncludes());
                for (AntDomIncludingDirective incl : allIncludes) {
                    final PsiFileSystemItem includedFile = incl.getFile().getValue();
                    if (includedFile instanceof PsiFile) {
                        final PsiFile included = includedFile.getContainingFile().getOriginalFile();
                        dependencies.add(included);
                        final AntDomProject includedProject = AntSupport.getAntDomProject((PsiFile) includedFile);
                        if (includedProject != null) {
                            fillTargets(list, model, includedProject, included.getVirtualFile());
                        }
                    } else {
                        if (includedFile == null) {
                            // if not resolved yet, it's possible that the file will be created later,
                            // thus we need to recalculate the cached value
                            dependencies.add(PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
                        }
                    }
                }
            }
        }.fillTargets(list, model, project, sourceFile);
    }
    if (dependencies.isEmpty()) {
        dependencies.add(PsiModificationTracker.MODIFICATION_COUNT);
    }
    return new Pair<>(list, dependencies);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) PsiFile(com.intellij.psi.PsiFile) Pair(com.intellij.openapi.util.Pair)

Example 84 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class AntConfigurationImpl method addBuildFileImpl.

private AntBuildFileBase addBuildFileImpl(final VirtualFile file) throws AntNoFileException {
    PsiFile xmlFile = myPsiManager.findFile(file);
    if (!(xmlFile instanceof XmlFile)) {
        throw new AntNoFileException("the file is not an xml file", file);
    }
    AntSupport.markFileAsAntFile(file, xmlFile.getProject(), true);
    if (!AntDomFileDescription.isAntFile(((XmlFile) xmlFile))) {
        throw new AntNoFileException("the file is not recognized as an ANT file", file);
    }
    final AntBuildFileImpl buildFile = new AntBuildFileImpl((XmlFile) xmlFile, this);
    myBuildFiles.add(buildFile);
    return buildFile;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile)

Example 85 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class AntConfigurationImpl method getContextFile.

@Nullable
public XmlFile getContextFile(@Nullable final XmlFile file) {
    if (file == null) {
        return null;
    }
    final VirtualFile context = myAntFileToContextFileMap.get(file.getVirtualFile());
    if (context == null) {
        return null;
    }
    final PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(context);
    if (!(psiFile instanceof XmlFile)) {
        return null;
    }
    final XmlFile xmlFile = (XmlFile) psiFile;
    return AntDomFileDescription.isAntFile(xmlFile) ? xmlFile : null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

XmlFile (com.intellij.psi.xml.XmlFile)409 XmlTag (com.intellij.psi.xml.XmlTag)155 PsiFile (com.intellij.psi.PsiFile)121 VirtualFile (com.intellij.openapi.vfs.VirtualFile)102 Nullable (org.jetbrains.annotations.Nullable)74 Project (com.intellij.openapi.project.Project)69 NotNull (org.jetbrains.annotations.NotNull)66 PsiElement (com.intellij.psi.PsiElement)64 XmlAttribute (com.intellij.psi.xml.XmlAttribute)39 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)34 Module (com.intellij.openapi.module.Module)34 XmlDocument (com.intellij.psi.xml.XmlDocument)32 Result (com.intellij.openapi.application.Result)28 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)23 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)22 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)21 ArrayList (java.util.ArrayList)20 Document (com.intellij.openapi.editor.Document)19 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)18 Editor (com.intellij.openapi.editor.Editor)15