Java 类com.intellij.psi.PsiPlainTextFile 实例源码

项目:manifold-ij    文件:ResourceToManifoldUtil.java   
static PsiElement findFakePlainTextElement( PsiPlainTextFile psiTextFile )
{
  try
  {
    int start = getWordAtCaretStart( psiTextFile.getProject(), psiTextFile.getVirtualFile().getPath() );
    if( start < 0 )
    {
      return null;
    }

    int end = getWordAtCaretEnd( psiTextFile.getProject(), psiTextFile.getVirtualFile().getPath() );
    if( end < 0 )
    {
      return null;
    }

    String name = psiTextFile.getText().substring( start, end );

    return new FakeTargetElement( psiTextFile, start, end - start, name );
  }
  catch( Exception e )
  {
    return null;
  }
}
项目:consulo-ui-designer    文件:ChangeFormComponentTypeFix.java   
public ChangeFormComponentTypeFix(PsiPlainTextFile formFile, String fieldName, PsiType componentTypeToSet) {
  myFormFile = formFile;
  myFieldName = fieldName;
  if (componentTypeToSet instanceof PsiClassType) {
    PsiClass psiClass = ((PsiClassType)componentTypeToSet).resolve();
    if (psiClass != null) {
      myComponentTypeToSet = ClassUtil.getJVMClassName(psiClass);
    }
    else {
      myComponentTypeToSet = ((PsiClassType) componentTypeToSet).rawType().getCanonicalText();
    }
  }
  else {
    myComponentTypeToSet = componentTypeToSet.getCanonicalText();
  }
}
项目:consulo-ui-designer    文件:GuiEditor.java   
private void handleEvent(final PsiTreeChangeEvent event)
{
    if(event.getParent() != null)
    {
        PsiFile containingFile = event.getParent().getContainingFile();
        if(containingFile instanceof PropertiesFile)
        {
            LOG.debug("Received PSI change event for properties file");
            myAlarm.cancelRequest(myRefreshPropertiesRequest);
            myAlarm.addRequest(myRefreshPropertiesRequest, 500, ModalityState.stateForComponent(GuiEditor.this));
        }
        else if(containingFile instanceof PsiPlainTextFile && containingFile.getFileType().equals(GuiFormFileType.INSTANCE))
        {
            // quick check if relevant
            String resourceName = FormEditingUtil.buildResourceName(containingFile);
            if(myDocument.getText().indexOf(resourceName) >= 0)
            {
                LOG.debug("Received PSI change event for nested form");
                // TODO[yole]: handle multiple nesting
                myAlarm.cancelRequest(mySynchronizeRequest);
                myAlarm.addRequest(mySynchronizeRequest, 500, ModalityState.stateForComponent(GuiEditor.this));
            }
        }
    }
}
项目:manifold-ij    文件:RenameTypeManifoldFileProcessor.java   
private boolean isElementInsidePlainTextFile( PsiElement element )
{
  if( element instanceof PsiPlainText )
  {
    element = element.getContainingFile();
  }

  if( element instanceof PsiPlainTextFile )
  {
    PsiElement fakeElement = ResourceToManifoldUtil.findFakePlainTextElement( (PsiPlainTextFile)element );
    return fakeElement != null && !(fakeElement instanceof PsiPlainTextFile) && !isTopLevelClassDeclaration( fakeElement );

  }
  return false;
}
项目:intellij-ce-playground    文件:PlainFileManipulator.java   
@Override
public PsiPlainTextFile handleContentChange(@NotNull PsiPlainTextFile file, @NotNull TextRange range, String newContent)
throws IncorrectOperationException {
  final Document document = FileDocumentManager.getInstance().getDocument(file.getVirtualFile());
  document.replaceString(range.getStartOffset(), range.getEndOffset(), newContent);
  PsiDocumentManager.getInstance(file.getProject()).commitDocument(document);

  return file;
}
项目:intellij-ce-playground    文件:CompletionContributorForTextField.java   
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
  PsiFile file = parameters.getOriginalFile();
  if (!(file instanceof PsiPlainTextFile)) return;

  TextFieldCompletionProvider field = file.getUserData(TextFieldCompletionProvider.COMPLETING_TEXT_FIELD_KEY);
  if (field == null) return;

  if (!(field instanceof DumbAware) && DumbService.isDumb(file.getProject())) return;

  String text = file.getText();
  int offset = Math.min(text.length(), parameters.getOffset());

  String prefix = field.getPrefix(text.substring(0, offset));

  CompletionResultSet activeResult;

  if (!result.getPrefixMatcher().getPrefix().equals(prefix)) {
    activeResult = result.withPrefixMatcher(prefix);
  }
  else {
    activeResult = result;
  }

  if (field.isCaseInsensitivity()) {
    activeResult = activeResult.caseInsensitive();
  }

  field.addCompletionVariants(text, offset, prefix, activeResult);
  activeResult.stopHere();
}
项目:tools-idea    文件:PlainFileManipulator.java   
@Override
public PsiPlainTextFile handleContentChange(PsiPlainTextFile file, TextRange range, String newContent)
throws IncorrectOperationException {
  final Document document = FileDocumentManager.getInstance().getDocument(file.getVirtualFile());
  document.replaceString(range.getStartOffset(), range.getEndOffset(), newContent);
  PsiDocumentManager.getInstance(file.getProject()).commitDocument(document);

  return file;
}
项目:tools-idea    文件:CompletionContributorForTextField.java   
@Override
public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) {
  PsiFile file = parameters.getOriginalFile();
  if (!(file instanceof PsiPlainTextFile)) return;

  TextFieldCompletionProvider field = file.getUserData(TextFieldCompletionProvider.COMPLETING_TEXT_FIELD_KEY);
  if (field == null) return;

  if (!(field instanceof DumbAware) && DumbService.isDumb(file.getProject())) return;

  String text = file.getText();
  int offset = Math.min(text.length(), parameters.getOffset());

  String prefix = field.getPrefix(text.substring(0, offset));

  CompletionResultSet activeResult;

  if (!result.getPrefixMatcher().getPrefix().equals(prefix)) {
    activeResult = result.withPrefixMatcher(prefix);
  }
  else {
    activeResult = result;
  }

  if (field.isCaseInsensitivity()) {
    activeResult = activeResult.caseInsensitive();
  }

  field.addCompletionVariants(text, offset, prefix, activeResult);
}
项目:consulo    文件:PlainFileManipulator.java   
@Override
public PsiPlainTextFile handleContentChange(@Nonnull PsiPlainTextFile file, @Nonnull TextRange range, String newContent)
        throws IncorrectOperationException {
  final Document document = FileDocumentManager.getInstance().getDocument(file.getVirtualFile());
  document.replaceString(range.getStartOffset(), range.getEndOffset(), newContent);
  PsiDocumentManager.getInstance(file.getProject()).commitDocument(document);

  return file;
}
项目:consulo    文件:CompletionContributorForTextField.java   
@RequiredReadAction
@Override
public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) {
  PsiFile file = parameters.getOriginalFile();
  if (!(file instanceof PsiPlainTextFile)) return;

  TextFieldCompletionProvider field = file.getUserData(TextFieldCompletionProvider.COMPLETING_TEXT_FIELD_KEY);
  if (field == null) return;

  if (!(field instanceof DumbAware) && DumbService.isDumb(file.getProject())) return;

  String text = file.getText();
  int offset = Math.min(text.length(), parameters.getOffset());

  String prefix = field.getPrefix(text.substring(0, offset));

  CompletionResultSet activeResult;

  if (!result.getPrefixMatcher().getPrefix().equals(prefix)) {
    activeResult = result.withPrefixMatcher(prefix);
  }
  else {
    activeResult = result;
  }

  if (field.isCaseInsensitivity()) {
    activeResult = activeResult.caseInsensitive();
  }

  field.addCompletionVariants(text, offset, prefix, activeResult);
}
项目:intellij-ce-playground    文件:LiveTemplateCompletionContributor.java   
public LiveTemplateCompletionContributor() {
  extend(CompletionType.BASIC, PlatformPatterns.psiElement(), new CompletionProvider<CompletionParameters>() {
    @Override
    protected void addCompletions(@NotNull final CompletionParameters parameters,
                                  ProcessingContext context,
                                  @NotNull CompletionResultSet result) {
      final PsiFile file = parameters.getPosition().getContainingFile();
      if (file instanceof PsiPlainTextFile && parameters.getEditor().getComponent().getParent() instanceof EditorTextField) {
        return;
      }

      Editor editor = parameters.getEditor();
      int offset = editor.getCaretModel().getOffset();
      final List<TemplateImpl> availableTemplates = TemplateManagerImpl.listApplicableTemplates(file, offset, false);
      final Map<TemplateImpl, String> templates = filterTemplatesByPrefix(availableTemplates, editor, offset, false, false);
      if (showAllTemplates()) {
        final AtomicBoolean templatesShown = new AtomicBoolean(false);
        final CompletionResultSet finalResult = result;
        result.runRemainingContributors(parameters, new Consumer<CompletionResult>() {
          @Override
          public void consume(CompletionResult completionResult) {
            finalResult.passResult(completionResult);
            if (completionResult.isStartMatch()) {
              ensureTemplatesShown(templatesShown, templates, parameters, finalResult);
            }
          }
        });

        ensureTemplatesShown(templatesShown, templates, parameters, result);
        return;
      }

      if (parameters.getInvocationCount() > 0) return; //only in autopopups for now

      // custom templates should handle this situation by itself (return true from hasCompletionItems() and provide lookup element)
      // regular templates won't be shown in this case
      if (!customTemplateAvailableAndHasCompletionItem(null, editor, file, offset)) {
        TemplateImpl template = findFullMatchedApplicableTemplate(editor, offset, availableTemplates);
        if (template != null) {
          result.withPrefixMatcher(result.getPrefixMatcher().cloneWithPrefix(template.getKey()))
            .addElement(new LiveTemplateLookupElementImpl(template, true));
        }
      }

      for (Map.Entry<TemplateImpl, String> possible : templates.entrySet()) {
        String templateKey = possible.getKey().getKey();
        String currentPrefix = possible.getValue();
        result.withPrefixMatcher(result.getPrefixMatcher().cloneWithPrefix(currentPrefix))
          .restartCompletionOnPrefixChange(templateKey);
      }
    }
  });
}
项目:intellij-ce-playground    文件:ResourceBundleKeyReference.java   
public ResourceBundleKeyReference(final PsiPlainTextFile file, String bundleName, TextRange keyNameRange) {
  super(file, keyNameRange);
  myBundleName = bundleName;
}
项目:intellij-ce-playground    文件:ResourceFileReference.java   
public ResourceFileReference(final PsiPlainTextFile file, TextRange range) {
  super(file, range);
}
项目:intellij-ce-playground    文件:ReferenceInForm.java   
protected ReferenceInForm(final PsiPlainTextFile file, TextRange range) {
  myFile = file;
  final Document document = FileDocumentManager.getInstance().getDocument(myFile.getVirtualFile());
  myRangeMarker = document.createRangeMarker(range);
}
项目:intellij-ce-playground    文件:FormPackageReference.java   
protected FormPackageReference(final PsiPlainTextFile file, TextRange range) {
  super(file, range);
}
项目:intellij-ce-playground    文件:FormEnumConstantReference.java   
protected FormEnumConstantReference(final PsiPlainTextFile file, final TextRange range, final PsiClassType enumClass) {
  super(file, range);
  myEnumClass = enumClass;
}
项目:intellij-ce-playground    文件:FormReferenceContributor.java   
public void registerReferenceProviders(@NotNull final PsiReferenceRegistrar registrar) {
  registrar.registerReferenceProvider(psiFile(PsiPlainTextFile.class), new FormReferenceProvider());
}
项目:intellij-ce-playground    文件:ResourceBundleFileReference.java   
public ResourceBundleFileReference(final PsiPlainTextFile file, TextRange bundleNameRange) {
  super(file, bundleNameRange);
}
项目:tools-idea    文件:ResourceBundleKeyReference.java   
public ResourceBundleKeyReference(final PsiPlainTextFile file, String bundleName, TextRange keyNameRange) {
  super(file, keyNameRange);
  myBundleName = bundleName;
}
项目:tools-idea    文件:ResourceFileReference.java   
public ResourceFileReference(final PsiPlainTextFile file, TextRange range) {
  super(file, range);
}
项目:tools-idea    文件:ReferenceInForm.java   
protected ReferenceInForm(final PsiPlainTextFile file, TextRange range) {
  myFile = file;
  final Document document = FileDocumentManager.getInstance().getDocument(myFile.getVirtualFile());
  myRangeMarker = document.createRangeMarker(range);
}
项目:tools-idea    文件:FormPackageReference.java   
protected FormPackageReference(final PsiPlainTextFile file, TextRange range) {
  super(file, range);
}
项目:tools-idea    文件:FormEnumConstantReference.java   
protected FormEnumConstantReference(final PsiPlainTextFile file, final TextRange range, final PsiClassType enumClass) {
  super(file, range);
  myEnumClass = enumClass;
}
项目:tools-idea    文件:FormReferenceContributor.java   
public void registerReferenceProviders(final PsiReferenceRegistrar registrar) {
  registrar.registerReferenceProvider(psiFile(PsiPlainTextFile.class), new FormReferenceProvider());
}
项目:tools-idea    文件:ResourceBundleFileReference.java   
public ResourceBundleFileReference(final PsiPlainTextFile file, TextRange bundleNameRange) {
  super(file, bundleNameRange);
}
项目:consulo-ui-designer    文件:ResourceBundleKeyReference.java   
public ResourceBundleKeyReference(final PsiPlainTextFile file, String bundleName, TextRange keyNameRange) {
  super(file, keyNameRange);
  myBundleName = bundleName;
}
项目:consulo-ui-designer    文件:ResourceFileReference.java   
public ResourceFileReference(final PsiPlainTextFile file, TextRange range) {
  super(file, range);
}
项目:consulo-ui-designer    文件:ReferenceInForm.java   
protected ReferenceInForm(final PsiPlainTextFile file, TextRange range) {
  myFile = file;
  final Document document = FileDocumentManager.getInstance().getDocument(myFile.getVirtualFile());
  myRangeMarker = document.createRangeMarker(range);
}
项目:consulo-ui-designer    文件:FormPackageReference.java   
protected FormPackageReference(final PsiPlainTextFile file, TextRange range) {
  super(file, range);
}
项目:consulo-ui-designer    文件:FormEnumConstantReference.java   
protected FormEnumConstantReference(final PsiPlainTextFile file, final TextRange range, final PsiClassType enumClass) {
  super(file, range);
  myEnumClass = enumClass;
}
项目:consulo-ui-designer    文件:FormReferenceContributor.java   
public void registerReferenceProviders(final PsiReferenceRegistrar registrar) {
  registrar.registerReferenceProvider(psiFile(PsiPlainTextFile.class), new FormReferenceProvider());
}
项目:consulo-ui-designer    文件:ResourceBundleFileReference.java   
public ResourceBundleFileReference(final PsiPlainTextFile file, TextRange bundleNameRange) {
  super(file, bundleNameRange);
}
项目:consulo    文件:LiveTemplateCompletionContributor.java   
public LiveTemplateCompletionContributor() {
  extend(CompletionType.BASIC, PlatformPatterns.psiElement(), new CompletionProvider() {
    @RequiredReadAction
    @Override
    public void addCompletions(@Nonnull final CompletionParameters parameters,
                                  ProcessingContext context,
                                  @Nonnull CompletionResultSet result) {
      final PsiFile file = parameters.getPosition().getContainingFile();
      if (file instanceof PsiPlainTextFile && parameters.getEditor().getComponent().getParent() instanceof EditorTextField) {
        return;
      }

      Editor editor = parameters.getEditor();
      int offset = editor.getCaretModel().getOffset();
      final List<TemplateImpl> availableTemplates = TemplateManagerImpl.listApplicableTemplates(file, offset, false);
      final Map<TemplateImpl, String> templates = filterTemplatesByPrefix(availableTemplates, editor, offset, false, false);
      if (showAllTemplates()) {
        final AtomicBoolean templatesShown = new AtomicBoolean(false);
        final CompletionResultSet finalResult = result;
        result.runRemainingContributors(parameters, new Consumer<CompletionResult>() {
          @Override
          public void consume(CompletionResult completionResult) {
            finalResult.passResult(completionResult);
            ensureTemplatesShown(templatesShown, templates, parameters, finalResult);
          }
        });

        ensureTemplatesShown(templatesShown, templates, parameters, result);
        return;
      }

      if (parameters.getInvocationCount() > 0) return; //only in autopopups for now

      // custom templates should handle this situation by itself (return true from hasCompletionItems() and provide lookup element)
      // regular templates won't be shown in this case
      if (!customTemplateAvailableAndHasCompletionItem(null, editor, file, offset)) {
        TemplateImpl template = findFullMatchedApplicableTemplate(editor, offset, availableTemplates);
        if (template != null) {
          result.withPrefixMatcher(result.getPrefixMatcher().cloneWithPrefix(template.getKey()))
                  .addElement(new LiveTemplateLookupElementImpl(template, true));
        }
      }

      for (Map.Entry<TemplateImpl, String> possible : templates.entrySet()) {
        String templateKey = possible.getKey().getKey();
        String currentPrefix = possible.getValue();
        result.withPrefixMatcher(result.getPrefixMatcher().cloneWithPrefix(currentPrefix))
                .restartCompletionOnPrefixChange(templateKey);
      }
    }
  });
}