本文整理匯總了Java中com.intellij.openapi.fileTypes.FileType.getDefaultExtension方法的典型用法代碼示例。如果您正苦於以下問題:Java FileType.getDefaultExtension方法的具體用法?Java FileType.getDefaultExtension怎麽用?Java FileType.getDefaultExtension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.openapi.fileTypes.FileType
的用法示例。
在下文中一共展示了FileType.getDefaultExtension方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: configureByText
import com.intellij.openapi.fileTypes.FileType; //導入方法依賴的package包/類
@Override
public PsiFile configureByText(@NotNull final FileType fileType, @NotNull @NonNls final String text) {
assertInitialized();
final String extension = fileType.getDefaultExtension();
final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
if (fileTypeManager.getFileTypeByExtension(extension) != fileType) {
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Exception {
fileTypeManager.associateExtension(fileType, extension);
}
}.execute();
}
final String fileName = "aaa." + extension;
return configureByText(fileName, text);
}
示例2: createPatternTree
import com.intellij.openapi.fileTypes.FileType; //導入方法依賴的package包/類
@NotNull
@Override
public PsiElement[] createPatternTree(@NotNull String text,
@NotNull PatternTreeContext context,
@NotNull FileType fileType,
@Nullable Language language,
String contextName, @Nullable String extension,
@NotNull Project project,
boolean physical) {
final String ext = extension != null ? extension : fileType.getDefaultExtension();
String text1 = context == PatternTreeContext.File ? text : "<QQQ>" + text + "</QQQ>";
final PsiFile fileFromText = PsiFileFactory.getInstance(project)
.createFileFromText("dummy." + ext, fileType, text1, LocalTimeCounter.currentTime(), physical, true);
final XmlDocument document = HtmlUtil.getRealXmlDocument(((XmlFile)fileFromText).getDocument());
if (context == PatternTreeContext.File) {
return new PsiElement[]{document};
}
return document.getRootTag().getValue().getChildren();
}
示例3: createPatternTree
import com.intellij.openapi.fileTypes.FileType; //導入方法依賴的package包/類
@NotNull
public PsiElement[] createPatternTree(@NotNull String text,
@NotNull PatternTreeContext context,
@NotNull FileType fileType,
@Nullable Language language,
@Nullable String contextName,
@Nullable String extension,
@NotNull Project project,
boolean physical) {
final String ext = extension != null ? extension : fileType.getDefaultExtension();
final String name = "__dummy." + ext;
final PsiFileFactory factory = PsiFileFactory.getInstance(project);
final PsiFile file = language == null
? factory.createFileFromText(name, fileType, text, LocalTimeCounter.currentTime(), physical, true)
: factory.createFileFromText(name, language, text, physical, true);
return file != null ? file.getChildren() : PsiElement.EMPTY_ARRAY;
}
示例4: remove
import com.intellij.openapi.fileTypes.FileType; //導入方法依賴的package包/類
@Nonnull
@CheckReturnValue
public static String remove(@Nonnull String fileName, @Nonnull FileType fileType) {
final String extension = fileType.getDefaultExtension();
if (fileName.endsWith(DELIMITER + extension)) {
return fileName.substring(0, fileName.length() - (extension.length() + 1));
}
return fileName;
}
示例5: append
import com.intellij.openapi.fileTypes.FileType; //導入方法依賴的package包/類
@Nonnull
@CheckReturnValue
public static String append(@Nonnull String fileName, @Nonnull FileType fileType) {
final String extension = fileType.getDefaultExtension();
if (fileName.endsWith(DELIMITER + extension)) {
return fileName;
}
return fileName + DELIMITER + extension;
}
示例6: getFileName
import com.intellij.openapi.fileTypes.FileType; //導入方法依賴的package包/類
@NotNull
public static String getFileName(@Nullable String title, @Nullable String windowTitle, @Nullable FileType fileType) {
String prefix = "";
if (title != null && windowTitle != null) {
prefix = title + "_" + windowTitle;
}
else if (title != null || windowTitle != null) {
prefix = title != null ? title : windowTitle;
}
// TODO: keep file name in DiffContent ?
String ext = fileType != null ? fileType.getDefaultExtension() : "tmp";
if (prefix.length() > 50) prefix = prefix.substring(0, 50);
return PathUtil.suggestFileName(prefix + "." + ext, true, false);
}
示例7: getNewFileTemplateName
import com.intellij.openapi.fileTypes.FileType; //導入方法依賴的package包/類
@Nullable
public
String getNewFileTemplateName() {
FileType fileType = FileTypeRegistry.getInstance().getFileTypeByFileName(myText);
if (fileType != UnknownFileType.INSTANCE) {
return fileType.getName() + " File." + fileType.getDefaultExtension();
}
return null;
}
示例8: chooseExtension
import com.intellij.openapi.fileTypes.FileType; //導入方法依賴的package包/類
private String chooseExtension() {
DiffContent content = getContent();
VirtualFile contentFile = content.getFile();
String extension;
if (contentFile != null) {
extension = "." + contentFile.getExtension();
}
else {
FileType contentType = content.getContentType();
if (contentType == null) contentType = DiffUtil.chooseContentTypes(myRequest.getContents())[myIndex];
extension = contentType != null ? "." + contentType.getDefaultExtension() : null;
}
return extension;
}
示例9: createFileFragment
import com.intellij.openapi.fileTypes.FileType; //導入方法依賴的package包/類
private static PsiFile createFileFragment(SearchContext searchContext, FileType fileType, Language dialect, String text) {
final String name = "__dummy." + fileType.getDefaultExtension();
final PsiFileFactory factory = PsiFileFactory.getInstance(searchContext.getProject());
return dialect == null ?
factory.createFileFromText(name, fileType, text, LocalTimeCounter.currentTime(), true, true) :
factory.createFileFromText(name, dialect, text, true, true);
}
示例10: finished
import com.intellij.openapi.fileTypes.FileType; //導入方法依賴的package包/類
@Override
public void finished(@Nullable final FileType fileType) {
final File localIOFile;
synchronized (myLock) {
LOG.debug("Downloading finished, size = " + myLocalFile.length() + ", file type=" + (fileType != null ? fileType.getName() : "null"));
if (fileType != null) {
String fileName = myLocalFile.getName();
int dot = fileName.lastIndexOf('.');
String extension = fileType.getDefaultExtension();
if (dot == -1 || !extension.regionMatches(true, 0, fileName, dot + 1, extension.length())) {
File newFile = FileUtil.findSequentNonexistentFile(myLocalFile.getParentFile(), fileName, extension);
try {
FileUtil.rename(myLocalFile, newFile);
myLocalFile = newFile;
}
catch (IOException e) {
LOG.debug(e);
}
}
}
localIOFile = myLocalFile;
}
VirtualFile localFile = new WriteAction<VirtualFile>() {
@Override
protected void run(@NotNull final Result<VirtualFile> result) {
final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(localIOFile);
if (file != null) {
file.refresh(false, false);
}
result.setResult(file);
}
}.execute().getResultObject();
LOG.assertTrue(localFile != null, "Virtual local file not found for " + localIOFile.getAbsolutePath());
LOG.debug("Virtual local file: " + localFile + ", size = " + localFile.getLength());
synchronized (myLock) {
myLocalVirtualFile = localFile;
myPrevLocalFile = null;
myState = RemoteFileState.DOWNLOADED;
myErrorMessage = null;
}
for (FileDownloadingListener listener : myListeners) {
listener.fileDownloaded(localFile);
}
}
示例11: parsePattern
import com.intellij.openapi.fileTypes.FileType; //導入方法依賴的package包/類
public static PsiElement[] parsePattern(Project project,
String context,
String pattern,
FileType fileType,
Language language,
String extension,
boolean physical) {
int offset = context.indexOf(PATTERN_PLACEHOLDER);
final int patternLength = pattern.length();
final String patternInContext = context.replace(PATTERN_PLACEHOLDER, pattern);
final String ext = extension != null ? extension : fileType.getDefaultExtension();
final String name = "__dummy." + ext;
final PsiFileFactory factory = PsiFileFactory.getInstance(project);
final PsiFile file = language == null
? factory.createFileFromText(name, fileType, patternInContext, LocalTimeCounter.currentTime(), physical, true)
: factory.createFileFromText(name, language, patternInContext, physical, true);
if (file == null) {
return PsiElement.EMPTY_ARRAY;
}
final List<PsiElement> result = new ArrayList<PsiElement>();
PsiElement element = file.findElementAt(offset);
if (element == null) {
return PsiElement.EMPTY_ARRAY;
}
PsiElement topElement = element;
element = element.getParent();
while (element != null) {
if (element.getTextRange().getStartOffset() == offset && element.getTextLength() <= patternLength) {
topElement = element;
}
element = element.getParent();
}
if (topElement instanceof PsiFile) {
return topElement.getChildren();
}
final int endOffset = offset + patternLength;
result.add(topElement);
topElement = topElement.getNextSibling();
while (topElement != null && topElement.getTextRange().getEndOffset() <= endOffset) {
result.add(topElement);
topElement = topElement.getNextSibling();
}
return result.toArray(new PsiElement[result.size()]);
}
示例12: getFileTypeExtension
import com.intellij.openapi.fileTypes.FileType; //導入方法依賴的package包/類
@NonNls
protected
String getFileTypeExtension(FileType fileType) {
return fileType.getDefaultExtension();
}
示例13: getExtractExtension
import com.intellij.openapi.fileTypes.FileType; //導入方法依賴的package包/類
@NonNls
protected String getExtractExtension(final FileType extractFileType, final T first) {
return extractFileType.getDefaultExtension();
}
示例14: actionPerformed
import com.intellij.openapi.fileTypes.FileType; //導入方法依賴的package包/類
@Override
public void actionPerformed(final AnActionEvent e) {
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
final Project project = e.getData(CommonDataKeys.PROJECT);
if (view == null || project == null) {
return;
}
final PsiDirectory taskDir = DirectoryChooserUtil.getOrChooseDirectory(view);
if (taskDir == null) return;
PsiDirectory lessonDir = taskDir.getParent();
if (lessonDir == null) {
return;
}
final CCProjectService service = CCProjectService.getInstance(project);
final Course course = service.getCourse();
final Lesson lesson = course.getLesson(lessonDir.getName());
final Task task = lesson.getTask(taskDir.getName());
final int index = task.getTaskFiles().size() + 1;
String generatedName = "file" + index;
CreateTaskFileDialog dialog = new CreateTaskFileDialog(project, generatedName, course);
dialog.show();
if (dialog.getExitCode() != OK_EXIT_CODE) {
return;
}
final String taskFileName = dialog.getFileName();
if (taskFileName == null) return;
FileType type = dialog.getFileType();
if (type == null) {
return;
}
final CCLanguageManager CCLanguageManager = CCUtils.getStudyLanguageManager(course);
if (CCLanguageManager == null) {
return;
}
final String extension = type.getDefaultExtension();
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
final FileTemplate taskTemplate = CCLanguageManager.getTaskFileTemplateForExtension(project, extension);
final String answerFileName = taskFileName + ".answer." + extension;
try {
if (taskTemplate == null) {
VirtualFile file = taskDir.getVirtualFile().createChildData(this, answerFileName);
ProjectView.getInstance(project).select(file, file, false);
FileEditorManager.getInstance(project).openFile(file, true);
}
else {
final PsiElement taskFile = FileTemplateUtil.createFromTemplate(taskTemplate, answerFileName, null, taskDir);
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
EditorHelper.openInEditor(taskFile, false);
view.selectElement(taskFile);
}
});
}
task.addTaskFile(taskFileName + "." + extension, index);
}
catch (Exception ignored) {
}
}
});
}