下面列出了com.intellij.psi.PsiFile#getName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static boolean isValidForIndex(FileContent inputData, PsiFile psiFile) {
String fileName = psiFile.getName();
if(fileName.startsWith(".") || fileName.endsWith("Test")) {
return false;
}
String extension = inputData.getFile().getExtension();
if(extension == null || !(extension.equalsIgnoreCase("xml") || extension.equalsIgnoreCase("yml")|| extension.equalsIgnoreCase("yaml"))) {
return false;
}
if(inputData.getFile().getLength() > MAX_FILE_BYTE_SIZE) {
return false;
}
return true;
}
@Override
public void processIncludingFiles(PsiFile context, Processor<? super Pair<VirtualFile, FileIncludeInfo>> processor) {
context = context.getOriginalFile();
VirtualFile contextFile = context.getVirtualFile();
if (contextFile == null) return;
String originalName = context.getName();
Collection<String> names = getPossibleIncludeNames(context, originalName);
GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
for (String name : names) {
MultiMap<VirtualFile, FileIncludeInfoImpl> infoList = FileIncludeIndex.getIncludingFileCandidates(name, scope);
for (VirtualFile candidate : infoList.keySet()) {
PsiFile psiFile = myPsiManager.findFile(candidate);
if (psiFile == null || context.equals(psiFile)) continue;
for (FileIncludeInfo info : infoList.get(candidate)) {
PsiFileSystemItem item = resolveFileInclude(info, psiFile);
if (item != null && contextFile.equals(item.getVirtualFile())) {
if (!processor.process(Pair.create(candidate, info))) {
return;
}
}
}
}
}
}
@Override
public ItemPresentation getPresentation(final ThriftDeclaration item) {
return new ItemPresentation() {
@Nullable
@Override
public String getPresentableText() {
return item.getName();
}
@Nullable
@Override
public String getLocationString() {
PsiFile containingFile = item.getContainingFile();
return containingFile == null ? null : containingFile.getName();
}
@Nullable
@Override
public Icon getIcon(boolean unused) {
return item.getIcon(Iconable.ICON_FLAG_VISIBILITY);
}
};
}
private static boolean isValidForIndex(FileContent inputData, PsiFile psiFile) {
String fileName = psiFile.getName();
if(fileName.startsWith(".") || fileName.endsWith("Test")) {
return false;
}
VirtualFile baseDir = ProjectUtil.getProjectDir(inputData.getProject());
if(baseDir == null) {
return false;
}
// is Test file in path name
String relativePath = VfsUtil.getRelativePath(inputData.getFile(), baseDir, '/');
if(relativePath != null && (relativePath.contains("/Test/") || relativePath.contains("/Fixtures/"))) {
return false;
}
return true;
}
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
if (!element.isWritable()) {
throw new IncorrectOperationException("bindToElement not possible for read-only element: " + element);
}
if (element instanceof PsiFile) {
//findRelativeFilePath already leaves the injection host file
PsiFile currentFile = cmd.getContainingFile();
if (!currentFile.isWritable()) {
throw new IncorrectOperationException("bindToElement not possible for read-only file: " + currentFile.getName());
}
String relativeFilePath = BashPsiFileUtils.findRelativeFilePath(currentFile, (PsiFile) element);
return handleElementRename(relativeFilePath);
}
throw new IncorrectOperationException("unsupported for element " + element);
}
public static boolean isValidForIndex(@NotNull FileContent inputData, @NotNull PsiFile psiFile) {
String fileName = psiFile.getName();
if(fileName.startsWith(".") || fileName.endsWith("Test")) {
return false;
}
VirtualFile baseDir = inputData.getProject().getBaseDir();
if(baseDir == null) {
return false;
}
// is Test file in path name
String relativePath = VfsUtil.getRelativePath(inputData.getFile(), baseDir, '/');
if(relativePath != null && (relativePath.contains("/Test/") || relativePath.contains("/Fixtures/"))) {
return false;
}
return true;
}
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
PsiFile psiFile = holder.getFile();
if(!ShopwareProjectComponent.isValidForProject(psiFile)) {
return super.buildVisitor(holder, isOnTheFly);
}
String name = psiFile.getName();
if(name.contains("Bootstrap")) {
psiFile.acceptChildren(new MyBootstrapRecursiveElementWalkingVisitor(holder));
return super.buildVisitor(holder, isOnTheFly);
}
return new MySubscriberRecursiveElementWalkingVisitor(holder);
}
@Nonnull
public static MsilClassEntry findRootClassEntry(@Nonnull MsilClassEntry element)
{
PsiFile containingFile = element.getContainingFile();
if(!(containingFile instanceof MsilFile))
{
return element;
}
MsilClassEntry originalClassEntry = null;
PsiElement temp = element;
while(!(temp instanceof MsilFile))
{
if(temp instanceof MsilClassEntry && temp.getParent() instanceof MsilFile)
{
originalClassEntry = (MsilClassEntry) temp;
break;
}
temp = temp.getParent();
}
if(originalClassEntry == null)
{
throw new IllegalArgumentException("Cant determinate parent msil class for: " + containingFile.getName());
}
return originalClassEntry;
}
public FilePathLookupItem(@Nonnull final PsiFile file, @Nonnull final List<FileReferenceHelper> helpers) {
myName = file.getName();
myPath = file.getVirtualFile().getPath();
myHelpers = helpers;
myInfo = FileInfoManager.getFileAdditionalInfo(file);
myIcon = TargetAWT.to(file.getFileType().getIcon());
myFile = file;
}
@Nullable
private String getContainingFileName(RefElement ref) {
SmartPsiElementPointer pointer = ref.getPointer();
if (pointer == null) return null;
PsiFile file = pointer.getContainingFile();
if (file == null) return null;
return file.getName();
}
@Nullable
@Override
public String getLocationString() {
PsiFile file = getContainingFile();
if (file != null) {
return file.getName();
}
return null;
}
@Override
public void actionPerformed(AnActionEvent e) {
Project project = getEventProject(e);
if (project == null) {
Notifier.error("Query execution error", "No project present.");
return;
}
MessageBus messageBus = project.getMessageBus();
ParametersService parameterService = ServiceManager.getService(project, ParametersService.class);
PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
StatementCollector statementCollector = new StatementCollector(messageBus, parameterService);
// This should never happen
if (psiFile == null) {
Notifier.error("Internal error", "No PsiFile present.");
}
psiFile.acceptChildren(statementCollector);
if (!statementCollector.hasErrors()) {
ExecuteQueryPayload executeQueryPayload =
new ExecuteQueryPayload(statementCollector.getQueries(), statementCollector.getParameters(), psiFile.getName());
ConsoleToolWindow.ensureOpen(project);
DataSourcesComponent dataSourcesComponent = project.getComponent(DataSourcesComponent.class);
ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(
"Choose Data Source",
new ChooseDataSourceActionGroup(messageBus, dataSourcesComponent, executeQueryPayload),
e.getDataContext(),
JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
false
);
popup.showInBestPositionFor(e.getDataContext());
} else {
Notifier.error("Query execution error", "File contains errors");
}
}
@Nullable
@Override
public PsiFileAndName toPsiFileAndName(BlazeProjectData projectData, ProjectViewNode<?> node) {
if (!(node instanceof PsiFileNode)) {
return null;
}
PsiFile psiFile = ((PsiFileNode) node).getValue();
if (!(psiFile instanceof GoFile)) {
return null;
}
return new PsiFileAndName(psiFile, psiFile.getName());
}
private static String codeFragmentFileName(@Nullable PsiElement context) {
if (context == null) {
return "fragment.bzl";
}
PsiFile contextFile = context.getContainingFile();
return contextFile != null ? contextFile.getName() : "fragment.bzl";
}
private void attachEntityClass(@NotNull Collection<LineMarkerInfo> lineMarkerInfos, @NotNull PsiElement psiElement) {
if(psiElement.getNode().getElementType() != YAMLTokenTypes.SCALAR_KEY) {
return;
}
PsiElement yamlKeyValue = psiElement.getParent();
if(!(yamlKeyValue instanceof YAMLKeyValue)) {
return;
}
if(yamlKeyValue.getParent() instanceof YAMLMapping && yamlKeyValue.getParent().getParent() instanceof YAMLDocument) {
PsiFile containingFile;
try {
containingFile = yamlKeyValue.getContainingFile();
} catch (PsiInvalidElementAccessException e) {
return;
}
String fileName = containingFile.getName();
if(isMetadataFile(fileName)) {
String keyText = ((YAMLKeyValue) yamlKeyValue).getKeyText();
if(StringUtils.isNotBlank(keyText)) {
Collection<PhpClass> phpClasses = PhpElementsUtil.getClassesInterface(psiElement.getProject(), keyText);
if(phpClasses.size() > 0) {
NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Symfony2Icons.DOCTRINE_LINE_MARKER).
setTargets(phpClasses).
setTooltipText("Navigate to class");
lineMarkerInfos.add(builder.createLineMarkerInfo(psiElement));
}
}
}
}
}
public void clear(Project project, Module module, PsiFile activityFile) {
listModel.removeAllElements();
events.clear();
this.project = project;
this.module = module;
this.activityFile = activityFile;
activityClassName = activityFile.getName();
int pos = activityClassName.indexOf('.');
if (pos > 0) {
activityClassName = activityClassName.substring(0, pos);
}
testClassField.setText(activityClassName +"Test");
}
@Override
public boolean accept(@NotNull HighlightInfo highlightInfo, PsiFile psiFile) {
if (psiFile != null && psiFile.getName() != null && psiFile.getName().endsWith(".rt") && MSG_EMPTY_TAG.equals(highlightInfo.getDescription())) {
return false;
}
// System.out.println(highlightInfo.getSeverity() + " " + highlightInfo.getDescription());
return true;
}
protected RefElementImpl(PsiFile file, RefManager manager) {
this(file.getName(), file, manager);
}
static void assertCommitSuccessful(Editor editor, PsiFile psiFile) {
Document document = editor.getDocument();
int docLength = document.getTextLength();
int psiLength = psiFile.getTextLength();
PsiDocumentManager manager = PsiDocumentManager.getInstance(psiFile.getProject());
boolean committed = !manager.isUncommited(document);
if (docLength == psiLength && committed) {
return;
}
FileViewProvider viewProvider = psiFile.getViewProvider();
String message = "unsuccessful commit:";
message += "\nmatching=" + (psiFile == manager.getPsiFile(document));
message += "\ninjectedEditor=" + (editor instanceof EditorWindow);
message += "\ninjectedFile=" + InjectedLanguageManager.getInstance(psiFile.getProject()).isInjectedFragment(psiFile);
message += "\ncommitted=" + committed;
message += "\nfile=" + psiFile.getName();
message += "\nfile class=" + psiFile.getClass();
message += "\nfile.valid=" + psiFile.isValid();
message += "\nfile.physical=" + psiFile.isPhysical();
message += "\nfile.eventSystemEnabled=" + viewProvider.isEventSystemEnabled();
message += "\nlanguage=" + psiFile.getLanguage();
message += "\ndoc.length=" + docLength;
message += "\npsiFile.length=" + psiLength;
String fileText = psiFile.getText();
if (fileText != null) {
message += "\npsiFile.text.length=" + fileText.length();
}
FileASTNode node = psiFile.getNode();
if (node != null) {
message += "\nnode.length=" + node.getTextLength();
String nodeText = node.getText();
message += "\nnode.text.length=" + nodeText.length();
}
VirtualFile virtualFile = viewProvider.getVirtualFile();
message += "\nvirtualFile=" + virtualFile;
message += "\nvirtualFile.class=" + virtualFile.getClass();
message += "\n" + DebugUtil.currentStackTrace();
throw new RuntimeExceptionWithAttachments("Commit unsuccessful", message, new Attachment(virtualFile.getPath() + "_file.txt", StringUtil.notNullize(fileText)), createAstAttachment(psiFile, psiFile),
new Attachment("docText.txt", document.getText()));
}
private String getPresentablePath(@Nonnull PsiFile file) {
VirtualFile vFile = file.getVirtualFile();
return vFile != null ? ProjectUtil.calcRelativeToProjectPath(vFile, myProject) : file.getName();
}