当前位置: 首页>>代码示例>>Java>>正文


Java FileReference类代码示例

本文整理汇总了Java中com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference的典型用法代码示例。如果您正苦于以下问题:Java FileReference类的具体用法?Java FileReference怎么用?Java FileReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileReference类属于com.intellij.psi.impl.source.resolve.reference.impl.providers包,在下文中一共展示了FileReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isAvailable

import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; //导入依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
  final int offset = editor.getCaretModel().getOffset();
  final PsiElement element = file.findElementAt(offset);
  if (element == null ||
      element instanceof PsiWhiteSpace) {
    return false;
  }

  final PsiReference reference = file.findReferenceAt(offset);
  final FileReference fileReference = reference == null ? null : FileReference.findFileReference(reference);

  if (fileReference != null) {
    final FileReferenceSet set = fileReference.getFileReferenceSet();
    final FileReference lastReference = set.getLastReference();
    return set.couldBeConvertedTo(isConvertToRelative()) && lastReference != null &&
           (!isConvertToRelative() && !set.isAbsolutePathReference() || isConvertToRelative() && set.isAbsolutePathReference()) &&
           lastReference.resolve() != null;
  }

  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ConvertAbsolutePathToRelativeIntentionAction.java

示例2: testInjectReference

import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; //导入依赖的package包/类
public void testInjectReference() throws Exception {
  myFixture.configureByText("foo.xml", "<foo xmlns=\"http://foo.bar\" \n" +
                                       "     xxx=\"ba<caret>r\"/>");
  assertNull(myFixture.getReferenceAtCaretPosition());
  assertTrue(new InjectLanguageAction().isAvailable(getProject(), myFixture.getEditor(), myFixture.getFile()));
  assertFalse(new UnInjectLanguageAction().isAvailable(getProject(), myFixture.getEditor(), myFixture.getFile()));

  InjectLanguageAction.invokeImpl(getProject(), myFixture.getEditor(), myFixture.getFile(), new FileReferenceInjector());
  assertTrue(myFixture.getReferenceAtCaretPosition() instanceof FileReference);
  assertFalse(new InjectLanguageAction().isAvailable(getProject(), myFixture.getEditor(), myFixture.getFile()));
  assertTrue(new UnInjectLanguageAction().isAvailable(getProject(), myFixture.getEditor(), myFixture.getFile()));

  myFixture.configureByText("bar.xml",
                            "<foo xmlns=\"<error descr=\"URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)\">http://foo.bar</error>\" \n" +
                            "     xxx=\"<error descr=\"Cannot resolve file 'bar'\">b<caret>ar</error>\"/>");
  myFixture.testHighlighting();

  UnInjectLanguageAction.invokeImpl(getProject(), myFixture.getEditor(), myFixture.getFile());
  assertNull(myFixture.getReferenceAtCaretPosition());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:ReferenceInjectionTest.java

示例3: testSurviveSerialization

import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; //导入依赖的package包/类
public void testSurviveSerialization() throws Exception {
  myFixture.configureByText("foo.xml", "<foo xmlns=\"http://foo.bar\" \n" +
                                       "     xxx=\"ba<caret>r\"/>");
  assertNull(myFixture.getReferenceAtCaretPosition());

  InjectLanguageAction.invokeImpl(getProject(), myFixture.getEditor(), myFixture.getFile(), new FileReferenceInjector());
  assertTrue(myFixture.getReferenceAtCaretPosition() instanceof FileReference);

  Configuration configuration = Configuration.getInstance();
  Element element = configuration.getState();
  configuration.loadState(element);

  ((PsiModificationTrackerImpl)PsiManager.getInstance(getProject()).getModificationTracker()).incCounter();
  assertTrue(myFixture.getReferenceAtCaretPosition() instanceof FileReference);

  UnInjectLanguageAction.invokeImpl(getProject(), myFixture.getEditor(), myFixture.getFile());
  assertNull(myFixture.getReferenceAtCaretPosition());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ReferenceInjectionTest.java

示例4: testInjectIntoJava

import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; //导入依赖的package包/类
public void testInjectIntoJava() throws Exception {
  myFixture.configureByText("Foo.java", "class Foo {\n" +
                                        "    String bar() {\n" +
                                        "        return \"ba<caret>r.xml\";\n" +
                                        "    }    \n" +
                                        "}");
  assertNull(getInjectedReferences());

  InjectLanguageAction.invokeImpl(getProject(), myFixture.getEditor(), myFixture.getFile(), new FileReferenceInjector());
  PsiReference[] references = getInjectedReferences();
  PsiReference reference = assertOneElement(references);
  assertTrue(reference instanceof FileReference);

  UnInjectLanguageAction.invokeImpl(getProject(), myFixture.getEditor(), myFixture.getFile());
  assertNull(getInjectedReferences());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:ReferenceInjectionTest.java

示例5: findFileReference

import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; //导入依赖的package包/类
@Nullable
private static FileReference findFileReference(@NotNull final PsiReference original) {
  if (original instanceof PsiMultiReference) {
    final PsiMultiReference multiReference = (PsiMultiReference)original;
    for (PsiReference reference : multiReference.getReferences()) {
      if (reference instanceof FileReference) {
        return (FileReference)reference;
      }
    }
  }
  else if (original instanceof FileReferenceOwner) {
    final PsiFileReference fileReference = ((FileReferenceOwner)original).getLastFileReference();
    if (fileReference instanceof FileReference) {
      return (FileReference)fileReference;
    }
  }

  return null;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:ConvertAbsolutePathToRelativeIntentionAction.java

示例6: resolveFile

import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; //导入依赖的package包/类
@Override
public PsiFile resolveFile()
{
	final String includeText = getIncludeText();
	if(includeText == null)
	{
		return null;
	}
	final FileReference[] references = new FileReferenceSet(includeText, this, 0, null, SystemInfo.isFileSystemCaseSensitive).getAllReferences();

	if(references != null && references.length > 0)
	{
		final PsiElement element = references[references.length - 1].resolve();
		if(element instanceof PsiFile)
		{
			return (PsiFile) element;
		}
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:21,代码来源:JSIncludeDirectiveImpl.java

示例7: isAvailable

import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; //导入依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file)
{
	final int offset = editor.getCaretModel().getOffset();
	final PsiElement element = file.findElementAt(offset);
	if(element == null || element instanceof PsiWhiteSpace)
	{
		return false;
	}

	final PsiReference reference = file.findReferenceAt(offset);
	final FileReference fileReference = reference == null ? null : FileReference.findFileReference(reference);

	if(fileReference != null)
	{
		final FileReferenceSet set = fileReference.getFileReferenceSet();
		final FileReference lastReference = set.getLastReference();
		return set.couldBeConvertedTo(isConvertToRelative()) && lastReference != null &&
				(!isConvertToRelative() && !set.isAbsolutePathReference() || isConvertToRelative() && set.isAbsolutePathReference()) &&
				lastReference.resolve() != null;
	}

	return false;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:25,代码来源:ConvertAbsolutePathToRelativeIntentionAction.java

示例8: invoke

import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException
{
	if(!FileModificationService.getInstance().prepareFileForWrite(file))
	{
		return;
	}

	final PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset());
	final FileReference fileReference = reference == null ? null : FileReference.findFileReference(reference);
	if(fileReference != null)
	{
		final FileReference lastReference = fileReference.getFileReferenceSet().getLastReference();
		if(lastReference != null)
		{
			lastReference.bindToElement(lastReference.resolve(), !isConvertToRelative());
		}
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:20,代码来源:ConvertAbsolutePathToRelativeIntentionAction.java

示例9: invoke

import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
  if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

  final PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset());
  final FileReference fileReference = reference == null ? null : FileReference.findFileReference(reference);
  if (fileReference != null) {
    final FileReference lastReference = fileReference.getFileReferenceSet().getLastReference();
    if (lastReference != null) lastReference.bindToElement(lastReference.resolve(), !isConvertToRelative());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:ConvertAbsolutePathToRelativeIntentionAction.java

示例10: bindToElement

import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; //导入依赖的package包/类
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
  for (PsiReference reference : myReferences) {
    if (reference instanceof FileReference) {
      return reference.bindToElement(element);
    }
  }
  return myElement;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:PsiDynaReference.java

示例11: retargetUsages

import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; //导入依赖的package包/类
protected void retargetUsages(UsageInfo[] usages, Map<PsiElement, PsiElement> oldToNewMap) {
  final List<NonCodeUsageInfo> nonCodeUsages = new ArrayList<NonCodeUsageInfo>();
  for (UsageInfo usageInfo : usages) {
    if (usageInfo instanceof MyUsageInfo) {
      final MyUsageInfo info = (MyUsageInfo)usageInfo;
      final PsiElement element = myElementsToMove[info.myIndex];

      if (info.getReference() instanceof FileReference || info.getReference() instanceof PsiDynaReference) {
        final PsiElement usageElement = info.getElement();
        if (usageElement != null) {
          final PsiFile usageFile = usageElement.getContainingFile();
          final PsiFile psiFile = usageFile.getViewProvider().getPsi(usageFile.getViewProvider().getBaseLanguage());
          if (psiFile != null && psiFile.equals(element)) {
            continue;  // already processed in MoveFilesOrDirectoriesUtil.doMoveFile
          }
        }
      }
      final PsiElement refElement = info.myReference.getElement();
      if (refElement != null && refElement.isValid()) {
        info.myReference.bindToElement(element);
      }
    } else if (usageInfo instanceof NonCodeUsageInfo) {
      nonCodeUsages.add((NonCodeUsageInfo)usageInfo);
    }
  }

  for (PsiFile movedFile : myFoundUsages.keySet()) {
    MoveFileHandler.forElement(movedFile).retargetUsages(myFoundUsages.get(movedFile), oldToNewMap);
  }

  myNonCodeUsages = nonCodeUsages.toArray(new NonCodeUsageInfo[nonCodeUsages.size()]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:MoveFilesOrDirectoriesProcessor.java

示例12: reparse

import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; //导入依赖的package包/类
@Override
protected void reparse() {
  //noinspection ConstantConditions
  if (myStringLiteralExpression != null) {
    final List<FileReference> references = getFileReferences(myStringLiteralExpression);
    myReferences = references.toArray(new FileReference[references.size()]);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:PyStringLiteralFileReferenceSet.java

示例13: resolveFileReference

import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; //导入依赖的package包/类
@Nullable
@Override
public PsiFileSystemItem resolveFileReference(@NotNull FileReference reference, @NotNull String name) {
  VirtualFile file = getVirtualFile();
  if (!(file instanceof HttpVirtualFile)) {
    return null;
  }

  VirtualFile parent = file;
  if (!parent.isDirectory()) {
    parent = parent.getParent();
    if (parent == null) {
      parent = file;
    }
  }

  VirtualFile childFile = parent.findChild(name);
  HttpFileSystem fileSystem = (HttpFileSystem)parent.getFileSystem();
  if (childFile == null) {
    childFile = fileSystem.createChild(parent, name, !reference.isLast());
  }
  if (childFile.isDirectory()) {
    // pre create children
    VirtualFile childParent = childFile;
    FileReference[] references = reference.getFileReferenceSet().getAllReferences();
    for (int i = reference.getIndex() + 1, n = references.length; i < n; i++) {
      FileReference childReference = references[i];
      childParent = fileSystem.createChild(childParent, childReference.decode(childReference.getText()), i != (n - 1));
    }
    return getManager().findDirectory(childFile);
  }
  else {
    return getManager().findFile(childFile);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:HtmlFileImpl.java

示例14: createReferences

import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; //导入依赖的package包/类
@Override
public boolean createReferences(@NotNull final PsiElement psiElement, @NotNull final List<PsiReference> references, final boolean soft) {

  final TextRange range = ElementManipulators.getValueTextRange(psiElement);
  final String elementText = psiElement.getText();
  final int anchorOffset = elementText.indexOf('#');
  if (anchorOffset == -1) {
    return false;
  }
  final boolean dynamic = isDynamic(psiElement, anchorOffset + 1, elementText);
  if (dynamic) {
    return false;
  }

  FileReference fileReference = null;
  if (range.getStartOffset() != anchorOffset) {
    fileReference = findFileReference(references);
    if (fileReference == null || fileReference.resolve() == null) {
      return false;
    }
  }
  final int pos = elementText.indexOf('?', anchorOffset);
  final String anchor;
  try {
    int endIndex = pos != -1 ? pos : range.getEndOffset();
    if (endIndex <= anchorOffset) {
      endIndex = anchorOffset + 1;
    }
    anchor = elementText.substring(anchorOffset + 1, endIndex);
  }
  catch (StringIndexOutOfBoundsException e) {      
    throw new RuntimeException(elementText, e);
  }
  final AnchorReferenceImpl anchorReference = new AnchorReferenceImpl(anchor, fileReference, psiElement, anchorOffset + 1, soft);
  references.add(anchorReference);
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:AnchorPathReferenceProvider.java

示例15: findFileReference

import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference; //导入依赖的package包/类
@Nullable
private static FileReference findFileReference(final List<PsiReference> references) {
  FileReference fileReference = null;
  for (PsiReference reference : references) {
    if (reference instanceof FileReference) {
      fileReference = ((FileReference)reference).getFileReferenceSet().getLastReference();
      break;
    }
  }
  return fileReference;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:AnchorPathReferenceProvider.java


注:本文中的com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。