com.intellij.psi.PsiFile#getName ( )源码实例Demo

下面列出了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;
    }
 
源代码2 项目: consulo   文件: FileIncludeManagerImpl.java
@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;
    }
 
源代码5 项目: BashSupport   文件: AbstractBashFileReference.java
@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;
}
 
源代码9 项目: consulo   文件: FilePathCompletionContributor.java
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;
}
 
源代码10 项目: consulo   文件: SmartRefElementPointerImpl.java
@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();
}
 
源代码11 项目: camel-idea-plugin   文件: FakeCamelPsiElement.java
@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");
    }
}
 
源代码13 项目: intellij   文件: GoSyncStatusContributor.java
@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());
}
 
源代码14 项目: intellij   文件: SkylarkDebuggerEditorsProvider.java
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));
                }
            }
        }
    }
}
 
源代码16 项目: droidtestrec   文件: EventsList.java
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");
}
 
源代码17 项目: react-templates-plugin   文件: RTInfoFilter.java
@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;
    }
 
源代码18 项目: consulo   文件: RefElementImpl.java
protected RefElementImpl(PsiFile file, RefManager manager) {
  this(file.getName(), file, manager);
}
 
源代码19 项目: consulo   文件: CompletionAssertions.java
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()));
}
 
源代码20 项目: consulo   文件: AbstractLayoutCodeProcessor.java
private String getPresentablePath(@Nonnull PsiFile file) {
  VirtualFile vFile = file.getVirtualFile();
  return vFile != null ? ProjectUtil.calcRelativeToProjectPath(vFile, myProject) : file.getName();
}