Java Code Examples for com.intellij.openapi.fileTypes.FileType#equals()

The following examples show how to use com.intellij.openapi.fileTypes.FileType#equals() . 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: LanguageServiceAccessor.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
public void enableLanguageServerContentType(
        @Nonnull ContentTypeToLanguageServerDefinition contentTypeToLSDefinition,
        @Nonnull Editor[] editors) {
    for (Editor editor : editors) {
        VirtualFile editorFile = LSPIJUtils.getFile(editor.getDocument());
        FileType contentType = contentTypeToLSDefinition.getKey();
        LanguageServersRegistry.LanguageServerDefinition lsDefinition = contentTypeToLSDefinition.getValue();
        FileType contentDesc = editorFile.getFileType();
        if (contentTypeToLSDefinition.isEnabled() && contentType != null && contentDesc != null
                && contentType.equals(contentDesc)
                && lsDefinition != null) {
            try {
                getInitializedLanguageServer(editorFile, lsDefinition, capabilities -> true);
            } catch (IOException e) {
                LOGGER.warn(e.getLocalizedMessage(), e);
            }
        }
    }

}
 
Example 2
Source File: WeaveBreakpointType.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public boolean canPutAt(@NotNull VirtualFile file, int line, @NotNull Project project)
{
    final Document document = FileDocumentManager.getInstance().getDocument(file);
    if (document != null)
    {
        final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
        if (psiFile != null)
        {
            final FileType fileType = psiFile.getFileType();
            if (fileType.equals(WeaveFileType.getInstance()))
            {
                return WeavePsiUtils.getFirstWeaveElement(project, document, line) != null;
            }
        }
    }
    return false;
}
 
Example 3
Source File: FileSetCompileScope.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public VirtualFile[] getFiles(final FileType fileType, boolean inSourceOnly) {
  final List<VirtualFile> files = new ArrayList<VirtualFile>();
  for (Iterator<VirtualFile> it = myRootFiles.iterator(); it.hasNext();) {
    VirtualFile file = it.next();
    if (!file.isValid()) {
      it.remove();
      continue;
    }
    if (file.isDirectory()) {
      addRecursively(files, file, fileType);
    }
    else {
      if (fileType == null || fileType.equals(file.getFileType())) {
        files.add(file);
      }
    }
  }
  return VfsUtilCore.toVirtualFileArray(files);
}
 
Example 4
Source File: AbstractCaseConvertingAction.java    From StringManipulation with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean selectSomethingUnderCaret(Editor editor, DataContext dataContext, SelectionModel selectionModel) {
	try {
		PsiFile psiFile = PsiDocumentManager.getInstance(editor.getProject()).getPsiFile(editor.getDocument());
		if (psiFile == null) {// select whole line in plaintext
			return super.selectSomethingUnderCaret(editor, dataContext, selectionModel);
		}
		FileType fileType = psiFile.getFileType();
		boolean handled = false;
		if (fileType.equals(StdFileTypes.JAVA) && isJavaInstalled()) {
			handled = javaHandling(editor, dataContext, selectionModel, psiFile);
		}
		if (!handled && fileType.equals(StdFileTypes.PROPERTIES)) {
			handled = propertiesHandling(editor, dataContext, selectionModel, psiFile);
		}
		if (!handled && fileType.equals(StdFileTypes.PLAIN_TEXT)) {
			handled = super.selectSomethingUnderCaret(editor, dataContext, selectionModel);
		}
		if (!handled) {
			handled = genericHandling(editor, dataContext, selectionModel, psiFile);
		}
		return handled;
	} catch (Exception e) {
		LOG.error("please report this, so I can fix it :(", e);
		return super.selectSomethingUnderCaret(editor, dataContext, selectionModel);
	}
}
 
Example 5
Source File: GlobalSearchScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean contains(@Nonnull VirtualFile file) {
  if (!super.contains(file)) return false;

  final FileType fileType = file.getFileType();
  for (FileType otherFileType : myFileTypes) {
    if (fileType.equals(otherFileType)) return true;
  }

  return false;
}
 
Example 6
Source File: XQueryCreateFromTemplateHandler.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
@Override
public boolean handlesTemplate(FileTemplate template) {
    FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension());
    return fileType.equals(XQueryFileType.INSTANCE);
}
 
Example 7
Source File: FileContent.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean isUnknown(@Nonnull FileType type) {
  return type.equals(UnknownFileType.INSTANCE);
}
 
Example 8
Source File: FileTemplateUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean canCreateFromTemplate(PsiDirectory[] dirs, FileTemplate template) {
  FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension());
  if (fileType.equals(UnknownFileType.INSTANCE)) return false;
  CreateFromTemplateHandler handler = findHandler(template);
  return handler.canCreate(dirs);
}
 
Example 9
Source File: FileTemplateBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isTemplateOfType(@Nonnull final FileType fType) {
  return fType.equals(FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(getExtension()));
}