use of com.intellij.psi.impl.file.PsiDirectoryImpl in project intellij-community by JetBrains.
the class CreateFileFix method invoke.
private void invoke(@NotNull Project project, PsiDirectory myDirectory) throws IncorrectOperationException {
// to revalidate applicability
myIsAvailableTimeStamp = 0;
try {
if (myIsDirectory) {
myDirectory.createSubdirectory(myNewFileName);
} else {
String newFileName = myNewFileName;
String newDirectories = null;
if (myNewFileName.contains("/")) {
int pos = myNewFileName.lastIndexOf("/");
newFileName = myNewFileName.substring(pos + 1);
newDirectories = myNewFileName.substring(0, pos);
}
PsiDirectory directory = myDirectory;
if (newDirectories != null) {
try {
VfsUtil.createDirectoryIfMissing(myDirectory.getVirtualFile(), newDirectories);
VirtualFile vfsDir = VfsUtil.findRelativeFile(myDirectory.getVirtualFile(), ArrayUtil.toStringArray(StringUtil.split(newDirectories, "/")));
directory = new PsiDirectoryImpl((PsiManagerImpl) myDirectory.getManager(), vfsDir);
} catch (IOException e) {
throw new IncorrectOperationException(e.getMessage());
}
}
final PsiFile newFile = directory.createFile(newFileName);
String text = getFileText();
if (text != null) {
final FileType type = FileTypeRegistry.getInstance().getFileTypeByFileName(newFileName);
final PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText("_" + newFileName, type, text);
final PsiElement psiElement = CodeStyleManager.getInstance(project).reformat(psiFile);
text = psiElement.getText();
}
openFile(project, directory, newFile, text);
}
} catch (IncorrectOperationException e) {
myIsAvailable = false;
}
}
use of com.intellij.psi.impl.file.PsiDirectoryImpl in project intellij-plugins by JetBrains.
the class DartServerResolverTest method getPresentableElementPosition.
@NotNull
private static String getPresentableElementPosition(@NotNull final CodeInsightTestFixture fixture, @Nullable final PsiElement element) {
if (element == null)
return "";
final StringBuilder buf = new StringBuilder(element.getText());
DartComponent component = PsiTreeUtil.getParentOfType(element, DartComponent.class);
while (component != null) {
final DartComponentName componentName = component.getComponentName();
if (componentName != null && componentName != element) {
buf.insert(0, component.getName() + " -> ");
}
component = PsiTreeUtil.getParentOfType(component, DartComponent.class);
}
String path = element instanceof PsiDirectoryImpl ? ((PsiDirectoryImpl) element).getVirtualFile().getPath() : element.getContainingFile().getVirtualFile().getPath();
final String contentRoot = ModuleRootManager.getInstance(fixture.getModule()).getContentRoots()[0].getPath();
if (path.equals(contentRoot))
path = "[content root]";
final String contentRootWithSlash = contentRoot + "/";
path = StringUtil.trimStart(path, contentRootWithSlash);
final DartSdk sdk = DartSdk.getDartSdk(element.getProject());
if (sdk != null && path.startsWith(sdk.getHomePath()))
path = "[Dart SDK]" + path.substring(sdk.getHomePath().length());
if (buf.length() > 0)
buf.insert(0, " -> ");
buf.insert(0, path);
return buf.toString();
}
Aggregations