Java Code Examples for org.jetbrains.yaml.YAMLFileType#YML

The following examples show how to use org.jetbrains.yaml.YAMLFileType#YML . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: YamlElementPatternHelper.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public boolean accepts(@NotNull PsiFile psiFile, ProcessingContext processingContext) {
    if (psiFile.getFileType() != YAMLFileType.YML) {
        return false;
    }

    if (psiFile.getName().matches("(security|config).*\\.(yml|yaml)")) {
        return true;
    }

    // psiFile.virtualFile is empty; check via folder structure
    PsiDirectory containingDirectory = psiFile.getContainingDirectory();
    if (containingDirectory == null) {
        return false;
    }

    if ("packages".equals(containingDirectory.getName())) {
        return true;
    }

    VirtualFile virtualDirectoryFile = containingDirectory.getVirtualFile();

    String relativePath = VfsExUtil.getRelativeProjectPath(psiFile.getProject(), virtualDirectoryFile);
    return relativePath != null && relativePath.contains("config/packages/");
}
 
Example 2
Source File: CaseSensitivityServiceInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    if(!Symfony2ProjectComponent.isEnabled(holder.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new PsiElementVisitor() {
        @Override
        public void visitFile(PsiFile psiFile) {
            if(psiFile.getFileType() == PhpFileType.INSTANCE) {
                phpVisitor(holder, psiFile);
            } else if(psiFile.getFileType() == YAMLFileType.YML) {
                yamlVisitor(holder, psiFile);
            } else if(psiFile.getFileType() == XmlFileType.INSTANCE) {
                xmlVisitor(holder, psiFile);
            }
        }
    };
}
 
Example 3
Source File: YamlServiceTagIntention.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) {

    if(psiElement.getContainingFile().getFileType() != YAMLFileType.YML || !Symfony2ProjectComponent.isEnabled(psiElement.getProject())) {
        return false;
    }

    return YamlHelper.findServiceInContext(psiElement) != null;
}
 
Example 4
Source File: RoutesStubIndex.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public FileBasedIndex.InputFilter getInputFilter() {
    return file -> {
        FileType fileType = file.getFileType();
        return fileType == YAMLFileType.YML || fileType == XmlFileType.INSTANCE || fileType == PhpFileType.INSTANCE;
    };
}
 
Example 5
Source File: DoctrineMetadataFileStubIndex.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public FileBasedIndex.InputFilter getInputFilter() {
    return virtualFile -> {
        FileType fileType = virtualFile.getFileType();
        return
            fileType == XmlFileType.INSTANCE ||
            fileType == PhpFileType.INSTANCE ||
            fileType == YAMLFileType.YML
        ;
    };
}
 
Example 6
Source File: ServicesDefinitionStubIndex.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public FileBasedIndex.InputFilter getInputFilter() {
    return file ->
        file.getFileType() == XmlFileType.INSTANCE || file.getFileType() == YAMLFileType.YML || file.getFileType() == PhpFileType.INSTANCE;
}
 
Example 7
Source File: ServiceActionUtil.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
public static void buildFile(AnActionEvent event, final Project project, String templatePath) {
    String extension = (templatePath.endsWith(".yml") || templatePath.endsWith(".yaml")) ? "yml" : "xml" ;

    String fileName = Messages.showInputDialog(project, "File name (without extension)", String.format("Create %s Service", extension), Symfony2Icons.SYMFONY);
    if(fileName == null || StringUtils.isBlank(fileName)) {
        return;
    }

    FileType fileType = (templatePath.endsWith(".yml") || templatePath.endsWith(".yaml")) ? YAMLFileType.YML : XmlFileType.INSTANCE ;

    if(!fileName.endsWith("." + extension)) {
        fileName = fileName.concat("." + extension);
    }

    DataContext dataContext = event.getDataContext();
    IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view == null) {
        return;
    }

    PsiDirectory[] directories = view.getDirectories();
    if(directories.length == 0) {
        return;
    }

    final PsiDirectory initialBaseDir = directories[0];
    if (initialBaseDir == null) {
        return;
    }

    if(initialBaseDir.findFile(fileName) != null) {
        Messages.showInfoMessage("File exists", "Error");
        return;
    }

    String content;
    try {
        content = StreamUtil.readText(ServiceActionUtil.class.getResourceAsStream(templatePath), "UTF-8").replace("\r\n", "\n");
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    final PsiFileFactory factory = PsiFileFactory.getInstance(project);

    String bundleName = "Acme\\DemoBundle";

    SymfonyBundleUtil symfonyBundleUtil = new SymfonyBundleUtil(project);
    SymfonyBundle symfonyBundle = symfonyBundleUtil.getContainingBundle(initialBaseDir);

    if(symfonyBundle != null) {
        bundleName = StringUtils.strip(symfonyBundle.getNamespaceName(), "\\");
    }

    String underscoreBundle = bundleName.replace("\\", ".").toLowerCase();
    if(underscoreBundle.endsWith("bundle")) {
        underscoreBundle = underscoreBundle.substring(0, underscoreBundle.length() - 6);
    }

    content = content.replace("{{ BundleName }}", bundleName).replace("{{ BundleNameUnderscore }}", underscoreBundle);

    final PsiFile file = factory.createFileFromText(fileName, fileType, content);

    ApplicationManager.getApplication().runWriteAction(() -> {
        CodeStyleManager.getInstance(project).reformat(file);
        initialBaseDir.add(file);
    });

    PsiFile psiFile = initialBaseDir.findFile(fileName);
    if(psiFile != null) {
        view.selectElement(psiFile);
    }

}
 
Example 8
Source File: FileResourcesIndex.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public FileBasedIndex.InputFilter getInputFilter() {
    return virtualFile ->
        virtualFile.getFileType() == XmlFileType.INSTANCE || virtualFile.getFileType() == YAMLFileType.YML;
}
 
Example 9
Source File: ContainerParameterStubIndex.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public FileBasedIndex.InputFilter getInputFilter() {
    return file -> file.getFileType() == XmlFileType.INSTANCE || file.getFileType() == YAMLFileType.YML;
}
 
Example 10
Source File: TranslationStubIndex.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public FileBasedIndex.InputFilter getInputFilter() {
    return file ->
        file.getFileType() == YAMLFileType.YML || "xlf".equalsIgnoreCase(file.getExtension()) || "xliff".equalsIgnoreCase(file.getExtension());
}
 
Example 11
Source File: ServicesTagStubIndex.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public FileBasedIndex.InputFilter getInputFilter() {
    return file ->
        file.getFileType() == XmlFileType.INSTANCE || file.getFileType() == YAMLFileType.YML;
}
 
Example 12
Source File: DefaultContextFileIndex.java    From intellij-neos with GNU General Public License v3.0 4 votes vote down vote up
@NotNull
@Override
public FileBasedIndex.InputFilter getInputFilter() {
    return virtualFile -> virtualFile.getFileType() == YAMLFileType.YML;
}
 
Example 13
Source File: ContainerIdUsagesStubIndex.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public FileBasedIndex.InputFilter getInputFilter() {
    return file -> file.getFileType() == XmlFileType.INSTANCE || file.getFileType() == YAMLFileType.YML;
}
 
Example 14
Source File: ConfigSchemaIndex.java    From idea-php-drupal-symfony2-bridge with MIT License 4 votes vote down vote up
@NotNull
@Override
public FileBasedIndex.InputFilter getInputFilter() {
    return file ->
        file.getFileType() == YAMLFileType.YML || file.getFileType() == XmlFileType.INSTANCE;
}
 
Example 15
Source File: PermissionIndex.java    From idea-php-drupal-symfony2-bridge with MIT License 4 votes vote down vote up
@NotNull
@Override
public FileBasedIndex.InputFilter getInputFilter() {
    return virtualFile -> virtualFile.getFileType() == YAMLFileType.YML;
}
 
Example 16
Source File: MenuIndex.java    From idea-php-drupal-symfony2-bridge with MIT License 4 votes vote down vote up
@NotNull
@Override
public FileBasedIndex.InputFilter getInputFilter() {
    return virtualFile -> virtualFile.getFileType() == YAMLFileType.YML;
}
 
Example 17
Source File: NodeTypesYamlFileIndex.java    From intellij-neos with GNU General Public License v3.0 4 votes vote down vote up
@NotNull
@Override
public FileBasedIndex.InputFilter getInputFilter() {
    return (virtualFile) -> virtualFile.getFileType() == YAMLFileType.YML;
}