Java源码示例:com.intellij.openapi.util.io.FileUtilRt
示例1
@NotNull
protected VirtualFile createProjectJarSubFile(String relativePath, Pair<ByteArraySequence, String>... contentEntries) throws IOException {
assertTrue("Use 'jar' extension for JAR files: '" + relativePath + "'", FileUtilRt.extensionEquals(relativePath, "jar"));
File f = new File(getProjectPath(), relativePath);
FileUtil.ensureExists(f.getParentFile());
FileUtil.ensureCanCreateFile(f);
final boolean created = f.createNewFile();
if (!created) {
throw new AssertionError("Unable to create the project sub file: " + f.getAbsolutePath());
}
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
JarOutputStream target = new JarOutputStream(new FileOutputStream(f), manifest);
for (Pair<ByteArraySequence, String> contentEntry : contentEntries) {
addJarEntry(contentEntry.first.getBytes(), contentEntry.second, target);
}
target.close();
final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f);
assertNotNull(virtualFile);
final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(virtualFile);
assertNotNull(jarFile);
return jarFile;
}
示例2
public File copyProjectBeforeOpening(@NotNull String projectDirName) throws IOException {
File masterProjectPath = getMasterProjectDirPath(projectDirName);
File projectPath = getTestProjectDirPath(projectDirName);
if (projectPath.isDirectory()) {
FileUtilRt.delete(projectPath);
}
// If masterProjectPath contains a src.zip file, unzip the file to projectPath.
// Otherwise, copy the whole directory to projectPath.
File srcZip = new File(masterProjectPath, SRC_ZIP_NAME);
if (srcZip.exists() && srcZip.isFile()) {
ZipUtil.unzip(null, projectPath, srcZip, null, null, true);
}
else {
FileUtil.copyDir(masterProjectPath, projectPath);
}
return projectPath;
}
示例3
protected static String pathToUrl(File path) {
String name = path.getName();
boolean isJarFile =
FileUtilRt.extensionEquals(name, "jar")
|| FileUtilRt.extensionEquals(name, "srcjar")
|| FileUtilRt.extensionEquals(name, "zip");
// .jar files require an URL with "jar" protocol.
String protocol =
isJarFile
? StandardFileSystems.JAR_PROTOCOL
: VirtualFileSystemProvider.getInstance().getSystem().getProtocol();
String filePath = FileUtil.toSystemIndependentName(path.getPath());
String url = VirtualFileManager.constructUrl(protocol, filePath);
if (isJarFile) {
url += URLUtil.JAR_SEPARATOR;
}
return url;
}
示例4
@Nullable
@Override
public OCLanguageKind getLanguageByExtension(Project project, String name) {
if (Blaze.isBlazeProject(project)) {
String extension = FileUtilRt.getExtension(name);
if (CFileExtensions.C_FILE_EXTENSIONS.contains(extension)) {
return CLanguageKind.C;
}
if (CFileExtensions.CXX_FILE_EXTENSIONS.contains(extension)) {
return CLanguageKind.CPP;
}
if (CFileExtensions.CXX_ONLY_HEADER_EXTENSIONS.contains(extension)) {
return CLanguageKind.CPP;
}
}
return null;
}
示例5
private void doMove(String[] checkedFiles, String movedFileSource, String moveTargetDir) {
myFixture.setTestDataPath(getTestDataPath() + getTestName(true));
Set<String> filenames = Sets.newHashSet(checkedFiles);
filenames.add(movedFileSource);
myFixture.configureByFiles(filenames.toArray(new String[filenames.size()]));
VirtualFile sourceVirtualFile = myFixture.findFileInTempDir(movedFileSource);
Assert.assertNotNull(sourceVirtualFile);
PsiFile sourceFile = myFixture.getPsiManager().findFile(sourceVirtualFile);
moveFile(moveTargetDir, sourceFile);
for (String filename : checkedFiles) {
myFixture.checkResultByFile(filename, FileUtil.getNameWithoutExtension(filename) + "_after." + FileUtilRt.getExtension(filename), false);
}
myFixture.checkResultByFile(moveTargetDir + "/" + movedFileSource, moveTargetDir + "/" + FileUtil.getNameWithoutExtension(movedFileSource) + "_after." + FileUtilRt.getExtension(movedFileSource), false);
}
示例6
@Override
public PsiElement setName(@NonNls @NotNull String newElementName) throws IncorrectOperationException {
final HaxeIdentifier identifier = getIdentifier();
final HaxeIdentifier identifierNew = HaxeElementGenerator.createIdentifierFromText(getProject(), newElementName);
final String oldName = getName();
if (identifierNew != null) {
getNode().replaceChild(identifier.getNode(), identifierNew.getNode());
}
if (oldName != null &&
getParent() instanceof HaxeClass &&
getParent().getParent() instanceof HaxeFile)
{
final HaxeFile haxeFile = (HaxeFile)getParent().getParent();
if (oldName.equals(FileUtil.getNameWithoutExtension(haxeFile.getName()))) {
haxeFile.setName(newElementName + "." + FileUtilRt.getExtension(haxeFile.getName()));
}
}
return this;
}
示例7
@Nonnull
@Override
public List<String> getAdditionalParameters() {
if (myCommandLineOptions == null) {
if (myUseCustomProfile && myUserDataDirectoryPath != null) {
return Collections.singletonList(USER_DATA_DIR_ARG + FileUtilRt.toSystemDependentName(myUserDataDirectoryPath));
}
else {
return Collections.emptyList();
}
}
List<String> cliOptions = ParametersListUtil.parse(myCommandLineOptions);
if (myUseCustomProfile && myUserDataDirectoryPath != null) {
cliOptions.add(USER_DATA_DIR_ARG + FileUtilRt.toSystemDependentName(myUserDataDirectoryPath));
}
return cliOptions;
}
示例8
@Nonnull
private static String cleanupPath(@Nonnull String path) {
path = FileUtilRt.toSystemIndependentName(path);
path = trimTrailingSeparators(path);
for (int i = 0; i < path.length(); ) {
int slash = path.indexOf('/', i);
if (slash == -1 || slash == path.length() - 1) {
break;
}
char next = path.charAt(slash + 1);
if (next == '/' && !(i == 0 && SystemInfo.isWindows) || // additional condition for Windows UNC
next == '.' && (slash == path.length() - 2 || path.charAt(slash + 2) == '/')) {
return cleanupTail(path, slash);
}
i = slash + 1;
}
return path;
}
示例9
@Override
public void execute(Logger logger) throws IOException {
if (mySource == null) {
return;
}
if (!mySource.exists()) {
logger.error("Source file " + mySource.getAbsolutePath() + " does not exist for action " + this);
}
else if (!FileUtilRt.delete(mySource)) {
logger.error("Action " + this + " failed.");
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
MessageFormat.format("<html>Cannot delete {0}<br>Please, check your access rights on folder <br>{1}", mySource.getAbsolutePath(), mySource.getAbsolutePath()),
"Installing Plugin", JOptionPane.ERROR_MESSAGE);
}
}
示例10
@Nullable
public static File compressFile(@Nonnull File srcFile, @Nonnull File zipFile) throws IOException {
InputStream is = new FileInputStream(srcFile);
try {
ZipOutputStream os = new ZipOutputStream(new FileOutputStream(zipFile));
try {
os.putNextEntry(new ZipEntry(srcFile.getName()));
FileUtilRt.copy(is, os);
os.closeEntry();
return zipFile;
}
finally {
os.close();
}
}
finally {
is.close();
}
}
示例11
public static boolean checkAssociate(final Project project, String fileName, DiffChainContext context) {
final String pattern = FileUtilRt.getExtension(fileName).toLowerCase();
if (context.contains(pattern)) return false;
int rc = Messages.showOkCancelDialog(project,
VcsBundle.message("diff.unknown.file.type.prompt", fileName),
VcsBundle.message("diff.unknown.file.type.title"),
VcsBundle.message("diff.unknown.file.type.associate"),
CommonBundle.getCancelButtonText(),
Messages.getQuestionIcon());
if (rc == Messages.OK) {
FileType fileType = FileTypeChooser.associateFileType(fileName);
return fileType != null && !fileType.isBinary();
} else {
context.add(pattern);
}
return false;
}
示例12
public void updateOutputPath(@Nonnull String oldArtifactName, @Nonnull final String newArtifactName) {
final String oldDefaultPath = ArtifactUtil.getDefaultArtifactOutputPath(oldArtifactName, myProject);
if (Comparing.equal(oldDefaultPath, getConfiguredOutputPath())) {
setOutputPath(ArtifactUtil.getDefaultArtifactOutputPath(newArtifactName, myProject));
final CompositePackagingElement<?> root = getRootElement();
if (root instanceof ArchivePackagingElement) {
String oldFileName = ArtifactUtil.suggestArtifactFileName(oldArtifactName);
final String name = ((ArchivePackagingElement)root).getArchiveFileName();
final String fileName = FileUtil.getNameWithoutExtension(name);
final String extension = FileUtilRt.getExtension(name);
if (fileName.equals(oldFileName) && extension.length() > 0) {
myLayoutTreeComponent.editLayout(new Runnable() {
@Override
public void run() {
((ArchivePackagingElement)getRootElement()).setArchiveFileName(ArtifactUtil.suggestArtifactFileName(newArtifactName) + "." + extension);
}
});
myLayoutTreeComponent.updateRootNode();
}
}
}
}
示例13
private void updateExtensionsCombo() {
final Object source = getSource();
if (source instanceof LanguageFileType) {
final List<String> extensions = getAllExtensions((LanguageFileType)source);
if (extensions.size() > 1) {
final ExtensionComparator comp = new ExtensionComparator(extensions.get(0));
Collections.sort(extensions, comp);
final SortedComboBoxModel<String> model = new SortedComboBoxModel<String>(comp);
model.setAll(extensions);
myExtensionComboBox.setModel(model);
myExtensionComboBox.setVisible(true);
myExtensionLabel.setVisible(true);
String fileExt = myCurrentFile != null ? FileUtilRt.getExtension(myCurrentFile.getName()) : "";
if (fileExt.length() > 0 && extensions.contains(fileExt)) {
myExtensionComboBox.setSelectedItem(fileExt);
return;
}
myExtensionComboBox.setSelectedIndex(0);
return;
}
}
myExtensionComboBox.setVisible(false);
myExtensionLabel.setVisible(false);
}
示例14
@Inject
public FileTemplateManagerImpl(@Nonnull FileTypeManager typeManager,
FileTemplateSettings projectSettings,
ExportableFileTemplateSettings defaultSettings,
ProjectManager pm,
final Project project) {
myTypeManager = (FileTypeManagerEx)typeManager;
myProjectSettings = projectSettings;
myDefaultSettings = defaultSettings;
myProject = project;
myProjectScheme = project.isDefault() ? null : new FileTemplatesScheme("Project") {
@Nonnull
@Override
public String getTemplatesDir() {
return FileUtilRt.toSystemDependentName(StorageUtil.getStoreDir(project) + "/" + TEMPLATES_DIR);
}
@Nonnull
@Override
public Project getProject() {
return project;
}
};
}
示例15
@NotNull
public static String fileNameToModuleName(@NotNull String filename) {
String nameWithoutExtension = FileUtilRt.getNameWithoutExtension(filename);
if (nameWithoutExtension.isEmpty()) {
return "";
}
return nameWithoutExtension.substring(0, 1).toUpperCase(Locale.getDefault()) + nameWithoutExtension.substring(1);
}
示例16
public void cleanUpProjectForImport(@NotNull File projectPath) {
File dotIdeaFolderPath = new File(projectPath, Project.DIRECTORY_STORE_FOLDER);
if (dotIdeaFolderPath.isDirectory()) {
File modulesXmlFilePath = new File(dotIdeaFolderPath, "modules.xml");
if (modulesXmlFilePath.isFile()) {
SAXBuilder saxBuilder = new SAXBuilder();
try {
Document document = saxBuilder.build(modulesXmlFilePath);
XPath xpath = XPath.newInstance("//*[@fileurl]");
//noinspection unchecked
List<Element> modules = xpath.selectNodes(document);
int urlPrefixSize = "file://$PROJECT_DIR$/".length();
for (Element module : modules) {
String fileUrl = module.getAttributeValue("fileurl");
if (!StringUtil.isEmpty(fileUrl)) {
String relativePath = toSystemDependentName(fileUrl.substring(urlPrefixSize));
File imlFilePath = new File(projectPath, relativePath);
if (imlFilePath.isFile()) {
FileUtilRt.delete(imlFilePath);
}
// It is likely that each module has a "build" folder. Delete it as well.
File buildFilePath = new File(imlFilePath.getParentFile(), "build");
if (buildFilePath.isDirectory()) {
FileUtilRt.delete(buildFilePath);
}
}
}
}
catch (Throwable ignored) {
// if something goes wrong, just ignore. Most likely it won't affect project import in any way.
}
}
FileUtilRt.delete(dotIdeaFolderPath);
}
}
示例17
private String readSettingsFile() {
inSameDir = flutterModuleDir.getParent().equals(projectRoot);
pathToModule = FileUtilRt.getRelativePath(new File(projectRoot.getPath()), flutterModuleRoot);
try {
requireNonNull(pathToModule);
requireNonNull(settingsFile);
@SuppressWarnings({"IOResourceOpenedButNotSafelyClosed", "resource"})
BufferedInputStream str = new BufferedInputStream(settingsFile.getInputStream());
return FileUtil.loadTextAndClose(new InputStreamReader(str, CharsetToolkit.UTF8_CHARSET));
}
catch (NullPointerException | IOException e) {
cleanupAfterError();
}
return "";
}
示例18
private String readSettingsFile() {
inSameDir = flutterModuleDir.getParent().equals(projectRoot);
pathToModule = FileUtilRt.getRelativePath(new File(projectRoot.getPath()), flutterModuleRoot);
try {
requireNonNull(pathToModule);
requireNonNull(settingsFile);
@SuppressWarnings({"IOResourceOpenedButNotSafelyClosed", "resource"})
BufferedInputStream str = new BufferedInputStream(settingsFile.getInputStream());
return FileUtil.loadTextAndClose(new InputStreamReader(str, CharsetToolkit.UTF8_CHARSET));
}
catch (NullPointerException | IOException e) {
cleanupAfterError();
}
return "";
}
示例19
/** Whether the editor notification should be shown for this file type. */
private static boolean supportedFileType(File file) {
LanguageClass language =
LanguageClass.fromExtension(FileUtilRt.getExtension(file.getName()).toLowerCase());
if (language != null && !LanguageSupport.languagesSupportedByCurrentIde().contains(language)) {
return false;
}
FileType type = FileTypeManager.getInstance().getFileTypeByFileName(file.getName());
if (IGNORED_FILE_TYPE_NAMES.contains(type.getName()) || type instanceof UserBinaryFileType) {
return false;
}
return true;
}
示例20
/** Creates a temporary output file to write the shell script to. */
public static File createScriptPathFile() {
File tempDir = new File(FileUtilRt.getTempDirectory());
String suffix = UUID.randomUUID().toString().substring(0, 8);
String fileName = "blaze-script-" + suffix;
File tempFile = new File(tempDir, fileName);
tempFile.deleteOnExit();
return tempFile;
}
示例21
private static boolean containsCompiledSources(TargetIdeInfo target) {
Predicate<ArtifactLocation> isCompiled =
location -> {
String locationExtension = FileUtilRt.getExtension(location.getRelativePath());
return CFileExtensions.SOURCE_EXTENSIONS.contains(locationExtension);
};
return target.getcIdeInfo() != null
&& target.getcIdeInfo().getSources().stream()
.filter(ArtifactLocation::isSource)
.anyMatch(isCompiled);
}
示例22
@Nullable
public static String findRelativeFilePath(PsiFile base, PsiFile targetFile) {
PsiFile currentFile = BashPsiUtils.findFileContext(base);
VirtualFile baseVirtualFile = currentFile.getVirtualFile();
if (!(baseVirtualFile.getFileSystem() instanceof LocalFileSystem)) {
throw new IncorrectOperationException("Can not rename file refeferences in non-local files");
}
VirtualFile targetVirtualFile = BashPsiUtils.findFileContext(targetFile).getVirtualFile();
if (!(targetVirtualFile.getFileSystem() instanceof LocalFileSystem)) {
throw new IncorrectOperationException("Can not bind to non-local files");
}
VirtualFile baseParent = baseVirtualFile.getParent();
VirtualFile targetParent = targetVirtualFile.getParent();
if (baseParent == null || targetParent == null) {
throw new IllegalStateException("parent directories not found");
}
char separator = '/';
String baseDirPath = ensureEnds(baseParent.getPath(), separator);
String targetDirPath = ensureEnds(targetParent.getPath(), separator);
String targetRelativePath = FileUtilRt.getRelativePath(baseDirPath, targetDirPath, separator, true);
if (targetRelativePath == null) {
return null;
}
if (".".equals(targetRelativePath)) {
//same parent dir
return targetVirtualFile.getName();
}
return ensureEnds(targetRelativePath, separator) + targetVirtualFile.getName();
}
示例23
private void doRename(Runnable renameLogic, String newName, String... sourceFiles) {
myFixture.setTestDataPath(getTestDataPath() + getTestName(true));
myFixture.configureByFiles(sourceFiles);
renameLogic.run();
for (String filename : sourceFiles) {
myFixture.checkResultByFile(filename, FileUtil.getNameWithoutExtension(filename) + "_after." + FileUtilRt.getExtension(filename), false);
}
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
Assert.assertNotNull("caret element is null", psiElement);
while (psiElement.getReference() == null) {
if (psiElement.getParent() == null) {
break;
}
psiElement = psiElement.getParent();
}
PsiReference psiReference = psiElement.getReference();
Assert.assertNotNull("target file reference wasn't found", psiReference);
Assert.assertTrue("Renamed reference wasn't found in the canonical text: " + psiReference.getCanonicalText(), psiReference.getCanonicalText().contains(newName));
PsiElement targetMarker = psiReference.resolve();
Assert.assertNotNull("target file resolve result wasn't found", targetMarker);
Assert.assertTrue("target is not a psi file", targetMarker instanceof BashHereDocMarker);
}
示例24
private void doRename(boolean expectFileReference, Runnable renameLogic, String... sourceFiles) {
myFixture.setTestDataPath(getTestDataPath() + getTestName(true));
List<String> filenames = Lists.newArrayList(sourceFiles);
filenames.add("target.bash");
myFixture.configureByFiles(filenames.toArray(new String[filenames.size()]));
renameLogic.run();
for (String filename : sourceFiles) {
myFixture.checkResultByFile(filename, FileUtil.getNameWithoutExtension(filename) + "_after." + FileUtilRt.getExtension(filename), false);
}
PsiElement psiElement;
if (expectFileReference) {
psiElement = PsiTreeUtil.getParentOfType(myFixture.getFile().findElementAt(myFixture.getCaretOffset()), BashFileReference.class);
Assert.assertNotNull("file reference is null. Current: " + myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getText(), psiElement);
Assert.assertTrue("Filename wasn't changed", psiElement.getText().contains("target_renamed.bash"));
} else {
psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
Assert.assertNotNull("caret element is null", psiElement);
while (psiElement.getReference() == null) {
if (psiElement.getParent() == null) {
break;
}
psiElement = psiElement.getParent();
}
}
PsiReference psiReference = psiElement.getReference();
Assert.assertNotNull("target file reference wasn't found", psiReference);
Assert.assertTrue("Renamed reference wasn't found in the canonical text", psiReference.getCanonicalText().contains("target_renamed.bash"));
PsiElement targetFile = psiReference.resolve();
Assert.assertNotNull("target file resolve result wasn't found", targetFile);
Assert.assertTrue("target is not a psi file", targetFile instanceof BashFile);
}
示例25
private void doRename(Runnable renameLogic, String... sourceFiles) {
myFixture.setTestDataPath(getTestDataPath() + getTestName(true));
List<String> filenames = Lists.newArrayList(sourceFiles);
filenames.add("target.bash");
myFixture.configureByFiles(filenames.toArray(new String[filenames.size()]));
renameLogic.run();
for (String filename : filenames) {
myFixture.checkResultByFile(filename, FileUtil.getNameWithoutExtension(filename) + "_after." + FileUtilRt.getExtension(filename), false);
}
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
Assert.assertNotNull("caret element is null", psiElement);
while (psiElement.getReference() == null) {
if (psiElement.getParent() == null) {
break;
}
psiElement = psiElement.getParent();
}
PsiReference psiReference = psiElement.getReference();
Assert.assertNotNull("target reference wasn't found", psiReference);
Assert.assertTrue("Renamed reference wasn't found in the canonical text", psiReference.getCanonicalText().contains("myFunction_renamed"));
PsiElement targetFile = psiReference.resolve();
Assert.assertNotNull("target resolve result wasn't found", targetFile);
Assert.assertTrue("target is not a psi function definition", targetFile instanceof BashFunctionDef);
}
示例26
private void doRename(String... sourceFiles) {
myFixture.setTestDataPath(getTestDataPath() + getTestName(true));
List<String> filenames = Lists.newArrayList(sourceFiles);
myFixture.configureByFiles(filenames.toArray(new String[filenames.size()]));
myFixture.renameElementAtCaret("a_renamed");
for (String filename : filenames) {
myFixture.checkResultByFile(filename, FileUtil.getNameWithoutExtension(filename) + "_after." + FileUtilRt.getExtension(filename), false);
}
}
示例27
private void doRename(Runnable renameLogic, String... sourceFiles) {
myFixture.setTestDataPath(getTestDataPath() + getTestName(true));
List<String> filenames = Lists.newArrayList(sourceFiles);
myFixture.configureByFiles(filenames.toArray(new String[filenames.size()]));
renameLogic.run();
for (String filename : filenames) {
myFixture.checkResultByFile(filename, FileUtil.getNameWithoutExtension(filename) + "_after." + FileUtilRt.getExtension(filename), false);
}
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
Assert.assertNotNull("caret element is null", psiElement);
while (psiElement.getReference() == null) {
if (psiElement.getParent() == null) {
break;
}
psiElement = psiElement.getParent();
}
PsiReference psiReference = psiElement.getReference();
Assert.assertNotNull("target reference wasn't found", psiReference);
Assert.assertTrue("Renamed reference wasn't found in the canonical text", psiReference.getCanonicalText().contains("a_renamed"));
PsiElement targetVariable = psiReference.resolve();
if (!(psiElement instanceof BashVarDef)) {
Assert.assertNotNull("target resolve result wasn't found", targetVariable);
Assert.assertTrue("target is not a psi function definition", targetVariable instanceof BashVarDef);
}
}
示例28
public static boolean isGeneratableFile(@NotNull String path) {
// todo(fkorotkov): make it configurable or get it from patns.
// maybe mark target as a target that generates sources and
// we need to refresh the project for any change in the corresponding module
// https://github.com/pantsbuild/intellij-pants-plugin/issues/13
return FileUtilRt.extensionEquals(path, PantsConstants.THRIFT_EXT) ||
FileUtilRt.extensionEquals(path, PantsConstants.ANTLR_EXT) ||
FileUtilRt.extensionEquals(path, PantsConstants.ANTLR_4_EXT) ||
FileUtilRt.extensionEquals(path, PantsConstants.PROTOBUF_EXT);
}
示例29
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
final boolean isNmml = FileUtilRt.extensionEquals(file.getName(), NMMLFileType.DEFAULT_EXTENSION);
if (!isNmml || !(file instanceof XmlFile)) {
return ProblemDescriptor.EMPTY_ARRAY;
}
MyVisitor visitor = new MyVisitor();
file.accept(visitor);
if (ContainerUtil.exists(visitor.getResult(), new Condition<XmlTag>() {
@Override
public boolean value(XmlTag tag) {
final XmlAttribute ifAttribute = tag.getAttribute("if");
return "debug".equals(ifAttribute != null ? ifAttribute.getValue() : null);
}
})) {
// all good
return ProblemDescriptor.EMPTY_ARRAY;
}
final XmlTag lastTag = ContainerUtil.iterateAndGetLastItem(visitor.getResult());
if (lastTag == null) {
return ProblemDescriptor.EMPTY_ARRAY;
}
final ProblemDescriptor descriptor = manager.createProblemDescriptor(
lastTag,
HaxeBundle.message("haxe.inspections.nme.build.directory.descriptor"),
new AddTagFix(),
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
isOnTheFly
);
return new ProblemDescriptor[]{descriptor};
}
示例30
private static JMenuItem createExportMenuItem(UberTreeViewer parseTreeViewer, String label, boolean useTransparentBackground) {
JMenuItem item = new JMenuItem(label);
boolean isMacNativSaveDialog = SystemInfo.isMac && Registry.is("ide.mac.native.save.dialog");
item.addActionListener(event -> {
String[] extensions = useTransparentBackground ? new String[]{"png", "svg"} : new String[]{"png", "jpg", "svg"};
FileSaverDescriptor descriptor = new FileSaverDescriptor("Export Image to", "Choose the destination file", extensions);
FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(descriptor, (Project) null);
String fileName = "parseTree" + (isMacNativSaveDialog ? ".png" : "");
VirtualFileWrapper vf = dialog.save(null, fileName);
if (vf == null) {
return;
}
File file = vf.getFile();
String imageFormat = FileUtilRt.getExtension(file.getName());
if (StringUtils.isBlank(imageFormat)) {
imageFormat = "png";
}
if ("svg".equals(imageFormat)) {
exportToSvg(parseTreeViewer, file, useTransparentBackground);
} else {
exportToImage(parseTreeViewer, file, useTransparentBackground, imageFormat);
}
});
return item;
}