Java 类com.intellij.psi.impl.source.tree.injected.Place 实例源码

项目:intellij-ce-playground    文件:QuickEditHandler.java   
public void initMarkers(Place shreds) {
  SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(myProject);
  int curOffset = -1;
  for (PsiLanguageInjectionHost.Shred shred : shreds) {
    final RangeMarker rangeMarker = myNewDocument.createRangeMarker(
      shred.getRange().getStartOffset() + shred.getPrefix().length(),
      shred.getRange().getEndOffset() - shred.getSuffix().length());
    final TextRange rangeInsideHost = shred.getRangeInsideHost();
    PsiLanguageInjectionHost host = shred.getHost();
    RangeMarker origMarker = myOrigDocument.createRangeMarker(rangeInsideHost.shiftRight(host.getTextRange().getStartOffset()));
    SmartPsiElementPointer<PsiLanguageInjectionHost> elementPointer = smartPointerManager.createSmartPsiElementPointer(host);
    Trinity<RangeMarker, RangeMarker, SmartPsiElementPointer> markers =
      Trinity.<RangeMarker, RangeMarker, SmartPsiElementPointer>create(origMarker, rangeMarker, elementPointer);
    myMarkers.add(markers);

    origMarker.setGreedyToRight(true);
    rangeMarker.setGreedyToRight(true);
    if (origMarker.getStartOffset() > curOffset) {
      origMarker.setGreedyToLeft(true);
      rangeMarker.setGreedyToLeft(true);
    }
    curOffset = origMarker.getEndOffset();
  }
  initGuardedBlocks(shreds);
}
项目:intellij-ce-playground    文件:DocumentWindowImpl.java   
@Override
public boolean areRangesEqual(@NotNull DocumentWindow otherd) {
  DocumentWindowImpl window = (DocumentWindowImpl)otherd;
  Place shreds = getShreds();
  Place otherShreds = window.getShreds();
  if (shreds.size() != otherShreds.size()) return false;
  for (int i = 0; i < shreds.size(); i++) {
    PsiLanguageInjectionHost.Shred shred = shreds.get(i);
    PsiLanguageInjectionHost.Shred otherShred = otherShreds.get(i);
    if (!shred.getPrefix().equals(otherShred.getPrefix())) return false;
    if (!shred.getSuffix().equals(otherShred.getSuffix())) return false;

    Segment hostRange = shred.getHostRangeMarker();
    Segment other = otherShred.getHostRangeMarker();
    if (hostRange == null || other == null || hostRange.getStartOffset() != other.getStartOffset()) return false;
    if (hostRange.getEndOffset() != other.getEndOffset()) return false;
  }
  return true;
}
项目:consulo-unity3d    文件:ShaderLabCGCompletionContributor.java   
public ShaderLabCGCompletionContributor()
{
    extend(CompletionType.BASIC, StandardPatterns.psiElement().withLanguage(CGLanguage.INSTANCE), new CompletionProvider()
    {
        @RequiredReadAction
        @Override
        public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull final CompletionResultSet result)
        {
            Place shreds = InjectedLanguageUtil.getShreds(parameters.getOriginalFile());

            for(PsiLanguageInjectionHost.Shred shred : shreds)
            {
                PsiLanguageInjectionHost host = shred.getHost();
                if(host instanceof ShaderCGScript)
                {
                    ShaderLabFile containingFile = (ShaderLabFile) host.getContainingFile();
                    ShaderReference.consumeProperties(containingFile, result::addElement);
                }
            }
        }
    });
}
项目:tools-idea    文件:QuickEditHandler.java   
public void initMarkers(Place shreds) {
  SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(myProject);
  int curOffset = -1;
  for (PsiLanguageInjectionHost.Shred shred : shreds) {
    final RangeMarker rangeMarker = myNewDocument.createRangeMarker(
      shred.getRange().getStartOffset() + shred.getPrefix().length(),
      shred.getRange().getEndOffset() - shred.getSuffix().length());
    final TextRange rangeInsideHost = shred.getRangeInsideHost();
    PsiLanguageInjectionHost host = shred.getHost();
    RangeMarker origMarker = myOrigDocument.createRangeMarker(rangeInsideHost.shiftRight(host.getTextRange().getStartOffset()));
    SmartPsiElementPointer<PsiLanguageInjectionHost> elementPointer = smartPointerManager.createSmartPsiElementPointer(host);
    Trinity<RangeMarker, RangeMarker, SmartPsiElementPointer> markers =
      Trinity.<RangeMarker, RangeMarker, SmartPsiElementPointer>create(origMarker, rangeMarker, elementPointer);
    myMarkers.add(markers);

    origMarker.setGreedyToRight(true);
    rangeMarker.setGreedyToRight(true);
    if (origMarker.getStartOffset() > curOffset) {
      origMarker.setGreedyToLeft(true);
      rangeMarker.setGreedyToLeft(true);
    }
    curOffset = origMarker.getEndOffset();
  }
  initGuardedBlocks(shreds);
}
项目:tools-idea    文件:DocumentWindowImpl.java   
@Override
public boolean areRangesEqual(@NotNull DocumentWindow otherd) {
  DocumentWindowImpl window = (DocumentWindowImpl)otherd;
  Place shreds = getShreds();
  Place otherShreds = window.getShreds();
  if (shreds.size() != otherShreds.size()) return false;
  for (int i = 0; i < shreds.size(); i++) {
    PsiLanguageInjectionHost.Shred shred = shreds.get(i);
    PsiLanguageInjectionHost.Shred otherShred = otherShreds.get(i);
    if (!shred.getPrefix().equals(otherShred.getPrefix())) return false;
    if (!shred.getSuffix().equals(otherShred.getSuffix())) return false;

    Segment hostRange = shred.getHostRangeMarker();
    Segment other = otherShred.getHostRangeMarker();
    if (hostRange == null || other == null || hostRange.getStartOffset() != other.getStartOffset()) return false;
    if (hostRange.getEndOffset() != other.getEndOffset()) return false;
  }
  return true;
}
项目:consulo    文件:QuickEditHandler.java   
public void initMarkers(Place shreds) {
  SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(myProject);
  int curOffset = -1;
  for (PsiLanguageInjectionHost.Shred shred : shreds) {
    final RangeMarker rangeMarker = myNewDocument.createRangeMarker(
            shred.getRange().getStartOffset() + shred.getPrefix().length(),
            shred.getRange().getEndOffset() - shred.getSuffix().length());
    final TextRange rangeInsideHost = shred.getRangeInsideHost();
    PsiLanguageInjectionHost host = shred.getHost();
    RangeMarker origMarker = myOrigDocument.createRangeMarker(rangeInsideHost.shiftRight(host.getTextRange().getStartOffset()));
    SmartPsiElementPointer<PsiLanguageInjectionHost> elementPointer = smartPointerManager.createSmartPsiElementPointer(host);
    Trinity<RangeMarker, RangeMarker, SmartPsiElementPointer> markers =
            Trinity.<RangeMarker, RangeMarker, SmartPsiElementPointer>create(origMarker, rangeMarker, elementPointer);
    myMarkers.add(markers);

    origMarker.setGreedyToRight(true);
    rangeMarker.setGreedyToRight(true);
    if (origMarker.getStartOffset() > curOffset) {
      origMarker.setGreedyToLeft(true);
      rangeMarker.setGreedyToLeft(true);
    }
    curOffset = origMarker.getEndOffset();
  }
  initGuardedBlocks(shreds);
}
项目:intellij-ce-playground    文件:QuickEditAction.java   
public static QuickEditHandler getExistingHandler(@NotNull PsiFile injectedFile) {
  Place shreds = InjectedLanguageUtil.getShreds(injectedFile);
  DocumentWindow documentWindow = InjectedLanguageUtil.getDocumentWindow(injectedFile);
  if (shreds == null || documentWindow == null) return null;

  TextRange hostRange = TextRange.create(shreds.get(0).getHostRangeMarker().getStartOffset(),
                                         shreds.get(shreds.size() - 1).getHostRangeMarker().getEndOffset());
  for (Editor editor : EditorFactory.getInstance().getAllEditors()) {
    if (editor.getDocument() != documentWindow.getDelegate()) continue;
    QuickEditHandler handler = editor.getUserData(QUICK_EDIT_HANDLER);
    if (handler != null && handler.changesRange(hostRange)) return handler;
  }
  return null;
}
项目:intellij-ce-playground    文件:DocumentWindowImpl.java   
public DocumentWindowImpl(@NotNull DocumentEx delegate, boolean oneLine, @NotNull Place shreds) {
  myDelegate = delegate;
  myOneLine = oneLine;
  synchronized (myLock) {
    myShreds = shreds;
  }
  myPrefixLineCount = Math.max(1, 1 + StringUtil.countNewLines(shreds.get(0).getPrefix()));
  mySuffixLineCount = Math.max(1, 1 + StringUtil.countNewLines(shreds.get(shreds.size()- 1).getSuffix()));
}
项目:tools-idea    文件:QuickEditAction.java   
public static QuickEditHandler getExistingHandler(PsiFile injectedFile) {
  Place shreds = InjectedLanguageUtil.getShreds(injectedFile);
  if (shreds == null) return null;
  TextRange hostRange = TextRange.create(shreds.get(0).getHostRangeMarker().getStartOffset(),
                                         shreds.get(shreds.size() - 1).getHostRangeMarker().getEndOffset());
  for (Editor editor : EditorFactory.getInstance().getAllEditors()) {
    QuickEditHandler handler = editor.getUserData(QUICK_EDIT_HANDLER);
    if (handler != null && handler.changesRange(hostRange)) return handler;
  }
  return null;
}
项目:tools-idea    文件:DocumentWindowImpl.java   
public DocumentWindowImpl(@NotNull DocumentEx delegate, boolean oneLine, @NotNull Place shreds) {
  myDelegate = delegate;
  myOneLine = oneLine;
  synchronized (myLock) {
    myShreds = shreds;
  }
  myPrefixLineCount = Math.max(1, 1 + StringUtil.countNewLines(shreds.get(0).getPrefix()));
  mySuffixLineCount = Math.max(1, 1 + StringUtil.countNewLines(shreds.get(shreds.size()- 1).getSuffix()));
}
项目:consulo    文件:QuickEditAction.java   
public static QuickEditHandler getExistingHandler(@Nonnull PsiFile injectedFile) {
  Place shreds = InjectedLanguageUtil.getShreds(injectedFile);
  DocumentWindow documentWindow = InjectedLanguageUtil.getDocumentWindow(injectedFile);
  if (shreds == null || documentWindow == null) return null;

  TextRange hostRange = TextRange.create(shreds.get(0).getHostRangeMarker().getStartOffset(),
                                         shreds.get(shreds.size() - 1).getHostRangeMarker().getEndOffset());
  for (Editor editor : EditorFactory.getInstance().getAllEditors()) {
    if (editor.getDocument() != documentWindow.getDelegate()) continue;
    QuickEditHandler handler = editor.getUserData(QUICK_EDIT_HANDLER);
    if (handler != null && handler.changesRange(hostRange)) return handler;
  }
  return null;
}
项目:intellij-ce-playground    文件:DocumentWindowImpl.java   
public void setShreds(@NotNull Place shreds) {
  synchronized (myLock) {
    myShreds.dispose();
    myShreds = shreds;
  }
}
项目:intellij-ce-playground    文件:DocumentWindowImpl.java   
@NotNull
public Place getShreds() {
  synchronized (myLock) {
    return myShreds;
  }
}
项目:intellij-ce-playground    文件:PythonRegexpInjector.java   
@Nullable
private static PsiFile getInjectedFile(@NotNull MultiHostRegistrar registrar) {
  // Don't add a dependency on IntelliLang here now, but this injector should become IntelliLang-based in the future
  final List<Pair<Place,PsiFile>> result = ((MultiHostRegistrarImpl)registrar).getResult();
  return result == null || result.isEmpty() ? null : result.get(result.size() - 1).second;
}
项目:intellij-ce-playground    文件:InjectorUtils.java   
public static PsiFile getInjectedFile(MultiHostRegistrar registrar) {
  final List<Pair<Place,PsiFile>> result = ((MultiHostRegistrarImpl)registrar).getResult();
  return result == null || result.isEmpty() ? null : result.get(result.size() - 1).second;
}
项目:tools-idea    文件:DocumentWindowImpl.java   
public void setShreds(@NotNull Place shreds) {
  synchronized (myLock) {
    myShreds.dispose();
    myShreds = shreds;
  }
}
项目:tools-idea    文件:DocumentWindowImpl.java   
@NotNull
public Place getShreds() {
  synchronized (myLock) {
    return myShreds;
  }
}
项目:tools-idea    文件:InjectorUtils.java   
public static PsiFile getInjectedFile(MultiHostRegistrar registrar) {
  final List<Pair<Place,PsiFile>> result = ((MultiHostRegistrarImpl)registrar).getResult();
  return result == null || result.isEmpty() ? null : result.get(result.size() - 1).second;
}
项目:consulo-dotnet    文件:CfsCompletionContributor.java   
public CfsCompletionContributor()
{
    extend(CompletionType.BASIC, StandardPatterns.psiElement().withElementType(CfsTokens.INDEX), new CompletionProvider()
    {
        @Override
        public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result)
        {
            int thisArgumentInex = -1;
            DotNetExpression[] callArguments = null;
            Place shreds = InjectedLanguageUtil.getShreds(parameters.getOriginalFile());
            for(PsiLanguageInjectionHost.Shred shred : shreds)
            {
                PsiLanguageInjectionHost host = shred.getHost();
                if(host == null)
                {
                    continue;
                }
                DotNetCallArgumentList callArgumentList = PsiTreeUtil.getParentOfType(host, DotNetCallArgumentList.class);
                if(callArgumentList != null)
                {
                    if(host instanceof DotNetExpression)
                    {
                        thisArgumentInex = ArrayUtil.find(callArguments = callArgumentList.getExpressions(), host);
                    }
                    break;
                }
            }

            if(callArguments == null || thisArgumentInex == -1)
            {
                return;
            }

            for(int i = (thisArgumentInex + 1); i < callArguments.length; i++)
            {
                DotNetExpression callArgument = callArguments[i];

                LookupElementBuilder builder = LookupElementBuilder.create(String.valueOf(i - 1));
                builder = builder.withTypeText(String.valueOf(i - 1));
                builder = builder.withIcon(AllIcons.Nodes.Parameter);
                builder = builder.withPresentableText(StringUtil.trimLog(callArgument.getText().trim(), 15));
                result.addElement(builder);
            }
        }
    });
}