use of com.intellij.openapi.fileTypes.FileType in project ideavim by JetBrains.
the class FileGroup method openFile.
public boolean openFile(@NotNull String filename, @NotNull DataContext context) {
if (logger.isDebugEnabled()) {
logger.debug("openFile(" + filename + ")");
}
// API change - don't merge
Project proj = PlatformDataKeys.PROJECT.getData(context);
VirtualFile found = findFile(filename, proj);
if (found != null) {
if (logger.isDebugEnabled()) {
logger.debug("found file: " + found);
}
// Can't open a file unless it has a known file type. The next call will return the known type.
// If unknown, IDEA will prompt the user to pick a type.
FileType type = FileTypeManager.getInstance().getKnownFileTypeOrAssociate(found);
if (type != null) {
FileEditorManager fem = FileEditorManager.getInstance(proj);
fem.openFile(found, true);
return true;
} else {
// Return true here because we found the file but the user canceled by not picking a type.
return true;
}
} else {
VimPlugin.showMessage("Unable to find " + filename);
return false;
}
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class FilePathActionJavac method doExecute.
protected void doExecute(final String line, String filePath, final OutputParser.Callback callback) {
if (LOG.isDebugEnabled()) {
LOG.debug("Process parsing message: " + filePath);
}
// for jdk7: cut off characters wrapping the path. e.g. "RegularFileObject[C:/tmp/bugs/src/a/Demo1.java]"
if (myJdk7FormatMatcher.reset(filePath).matches()) {
filePath = myJdk7FormatMatcher.group(1);
}
int index = filePath.lastIndexOf('/');
final String name = index >= 0 ? filePath.substring(index + 1) : filePath;
final FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(name);
if (StdFileTypes.JAVA.equals(fileType)) {
callback.fileProcessed(filePath);
callback.setProgressText(CompilerBundle.message("progress.parsing.file", name));
} else if (StdFileTypes.CLASS.equals(fileType)) {
callback.fileGenerated(filePath);
}
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class CompileAction method update.
public void update(AnActionEvent e) {
super.update(e);
Presentation presentation = e.getPresentation();
if (!presentation.isEnabled()) {
return;
}
presentation.setText(ActionsBundle.actionText(RECOMPILE_FILES_ID_MOD));
presentation.setVisible(true);
Project project = e.getProject();
if (project == null) {
presentation.setEnabled(false);
return;
}
CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(project);
final Module module = e.getData(LangDataKeys.MODULE_CONTEXT);
boolean forFiles = false;
final VirtualFile[] files = getCompilableFiles(project, e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY));
if (module == null && files.length == 0) {
presentation.setEnabled(false);
presentation.setVisible(!ActionPlaces.isPopupPlace(e.getPlace()));
return;
}
String elementDescription = null;
if (module != null) {
elementDescription = CompilerBundle.message("action.compile.description.module", module.getName());
} else {
PsiPackage aPackage = null;
if (files.length == 1) {
final PsiDirectory directory = PsiManager.getInstance(project).findDirectory(files[0]);
if (directory != null) {
aPackage = JavaDirectoryService.getInstance().getPackage(directory);
}
} else {
PsiElement element = e.getData(CommonDataKeys.PSI_ELEMENT);
if (element instanceof PsiPackage) {
aPackage = (PsiPackage) element;
}
}
if (aPackage != null) {
String name = aPackage.getQualifiedName();
if (name.length() == 0) {
//noinspection HardCodedStringLiteral
name = "<default>";
}
elementDescription = "'" + name + "'";
} else if (files.length == 1) {
forFiles = true;
final VirtualFile file = files[0];
FileType fileType = file.getFileType();
if (CompilerManager.getInstance(project).isCompilableFileType(fileType) || compilerConfiguration.isCompilableResourceFile(project, file)) {
elementDescription = "'" + file.getName() + "'";
} else {
if (!ActionPlaces.isMainMenuOrActionSearch(e.getPlace())) {
// the action should be invisible in popups for non-java files
presentation.setEnabled(false);
presentation.setVisible(false);
return;
}
}
} else {
forFiles = true;
elementDescription = CompilerBundle.message("action.compile.description.selected.files");
}
}
if (elementDescription == null) {
presentation.setEnabled(false);
return;
}
presentation.setText(createPresentationText(elementDescription, forFiles), true);
presentation.setEnabled(true);
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class CompilerConfigurationImpl method createCompilers.
private void createCompilers() {
if (JAVAC_EXTERNAL_BACKEND != null) {
return;
}
JAVAC_EXTERNAL_BACKEND = new JavacCompiler(myProject);
myRegisteredCompilers.add(JAVAC_EXTERNAL_BACKEND);
if (!ApplicationManager.getApplication().isUnitTestMode()) {
if (EclipseCompiler.isInitialized()) {
final EclipseCompiler eclipse = new EclipseCompiler(myProject);
myRegisteredCompilers.add(eclipse);
}
}
final Set<FileType> types = new HashSet<>();
for (BackendCompiler compiler : Extensions.getExtensions(BackendCompiler.EP_NAME, myProject)) {
myRegisteredCompilers.add(compiler);
types.addAll(compiler.getCompilableFileTypes());
}
final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
for (FileType type : types) {
compilerManager.addCompilableFileType(type);
}
myDefaultJavaCompiler = JAVAC_EXTERNAL_BACKEND;
for (BackendCompiler compiler : myRegisteredCompilers) {
if (compiler.getId().equals(myState.DEFAULT_COMPILER)) {
myDefaultJavaCompiler = compiler;
break;
}
}
myState.DEFAULT_COMPILER = myDefaultJavaCompiler.getId();
}
use of com.intellij.openapi.fileTypes.FileType in project kotlin by JetBrains.
the class KotlinTypedHandler method indentBrace.
/**
* Copied from
* @see com.intellij.codeInsight.editorActions.TypedHandler#indentBrace(Project, Editor, char)
*/
private static void indentBrace(@NotNull final Project project, @NotNull final Editor editor, char braceChar) {
final int offset = editor.getCaretModel().getOffset() - 1;
Document document = editor.getDocument();
CharSequence chars = document.getCharsSequence();
if (offset < 0 || chars.charAt(offset) != braceChar)
return;
int spaceStart = CharArrayUtil.shiftBackward(chars, offset - 1, " \t");
if (spaceStart < 0 || chars.charAt(spaceStart) == '\n' || chars.charAt(spaceStart) == '\r') {
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
documentManager.commitDocument(document);
final PsiFile file = documentManager.getPsiFile(document);
if (file == null || !file.isWritable())
return;
PsiElement element = file.findElementAt(offset);
if (element == null)
return;
EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(offset);
FileType fileType = file.getFileType();
BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, iterator);
boolean isBrace = braceMatcher.isLBraceToken(iterator, chars, fileType) || braceMatcher.isRBraceToken(iterator, chars, fileType);
if (element.getNode() != null && isBrace) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
int newOffset = CodeStyleManager.getInstance(project).adjustLineIndent(file, offset);
editor.getCaretModel().moveToOffset(newOffset + 1);
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
editor.getSelectionModel().removeSelection();
}
});
}
}
}
Aggregations