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


Java InjectedLanguageUtil.enumerate方法代码示例

本文整理汇总了Java中com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil.enumerate方法的典型用法代码示例。如果您正苦于以下问题:Java InjectedLanguageUtil.enumerate方法的具体用法?Java InjectedLanguageUtil.enumerate怎么用?Java InjectedLanguageUtil.enumerate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil的用法示例。


在下文中一共展示了InjectedLanguageUtil.enumerate方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: match

import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
void match(PsiElement element, final Language language) {
  final MatchingStrategy strategy = matchContext.getPattern().getStrategy();

  final Language elementLanguage = element.getLanguage();
  if (strategy.continueMatching(element) && elementLanguage.isKindOf(language)) {
    visitor.matchContext(new ArrayBackedNodeIterator(new PsiElement[] {element}));
    return;
  }
  for(PsiElement el=element.getFirstChild();el!=null;el=el.getNextSibling()) {
    match(el, language);
  }
  if (element instanceof PsiLanguageInjectionHost) {
    InjectedLanguageUtil.enumerate(element, new PsiLanguageInjectionHost.InjectedPsiVisitor() {
      @Override
      public void visit(@NotNull PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places) {
        match(injectedPsi, language);
      }
    });
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:MatcherImpl.java

示例2: getFiles

import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@NotNull
public static PsiFile[] getFiles(XmlAttribute attribute) {
  final XmlAttributeValue value = attribute.getValueElement();
  if (value != null) {
    final List<PsiFile> files = new SmartList<PsiFile>();
    InjectedLanguageUtil.enumerate(value, new PsiLanguageInjectionHost.InjectedPsiVisitor() {
      public void visit(@NotNull PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places) {
        if (injectedPsi instanceof XPathFile) {
          files.add(injectedPsi);
        }
      }
    });
    return files.isEmpty() ? PsiFile.EMPTY_ARRAY : PsiUtilCore.toPsiFileArray(files);
  }
  return PsiFile.EMPTY_ARRAY;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:XsltSupport.java

示例3: inspectInjectedPsi

import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
void inspectInjectedPsi(@Nonnull final List<PsiElement> elements,
                        final boolean onTheFly,
                        @Nonnull final ProgressIndicator indicator,
                        @Nonnull final InspectionManager iManager,
                        final boolean inVisibleRange,
                        @Nonnull final List<LocalInspectionToolWrapper> wrappers) {
  final Set<PsiFile> injected = new THashSet<>();
  for (PsiElement element : elements) {
    InjectedLanguageUtil.enumerate(element, getFile(), false, (injectedPsi, places) -> injected.add(injectedPsi));
  }
  if (injected.isEmpty()) return;
  Processor<PsiFile> processor = injectedPsi -> {
    doInspectInjectedPsi(injectedPsi, onTheFly, indicator, iManager, inVisibleRange, wrappers);
    return true;
  };
  if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<>(injected), indicator, myFailFastOnAcquireReadAction, processor)) {
    throw new ProcessCanceledException();
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:20,代码来源:LocalInspectionsPass.java

示例4: setUpRegexpInjectionAndGetRegexpFile

import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@NotNull
private PsiFile setUpRegexpInjectionAndGetRegexpFile() {
  final PsiFile file = getFile();

  int offsetWithRegexp = file.getText().indexOf("Pattern.compile(\"")
    + "Pattern.compile(\"".length();

  final PsiElement stringLiteralLeaf = file.findElementAt(offsetWithRegexp);
  assertNotNull(stringLiteralLeaf);
  assertNotNull(stringLiteralLeaf.getParent());
  assertTrue(stringLiteralLeaf.getParent() instanceof PsiLanguageInjectionHost);

  final PsiLanguageInjectionHost elementWithInjection = ((PsiLanguageInjectionHost)stringLiteralLeaf.getParent());

  InjectedLanguageUtil.enumerate(elementWithInjection, file, false, new PsiLanguageInjectionHost.InjectedPsiVisitor() {
    @Override
    public void visit(@NotNull final PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places) {
    }
  });

  assertTrue(InjectedLanguageUtil.hasInjections(elementWithInjection));
  final PsiElement elementInInjected =
    InjectedLanguageUtil.findElementInInjected(elementWithInjection, offsetWithRegexp);

  final PsiFile regexpFile = PsiTreeUtil.getParentOfType(elementInInjected, PsiFile.class);
  assertNotNull(regexpFile);

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

示例5: getBindingExprDefault

import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Nullable
public static String getBindingExprDefault(@NotNull XmlAttribute psiAttribute) {
  XmlAttributeValue attrValue = psiAttribute.getValueElement();
  if (attrValue instanceof PsiLanguageInjectionHost) {
    final Ref<PsiElement> injections = Ref.create();
    InjectedLanguageUtil.enumerate(attrValue, new PsiLanguageInjectionHost.InjectedPsiVisitor() {
      @Override
      public void visit(@NotNull PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places) {
        if (injectedPsi instanceof DbFile) {
          injections.set(injectedPsi);
        }
      }
    });
    if (injections.get() != null) {
      PsiDbDefaults defaults = PsiTreeUtil.getChildOfType(injections.get(), PsiDbDefaults.class);
      if (defaults != null) {
        // TODO: extract value from literals and resolve variable values if needed.
        PsiDbConstantValue constantValue = defaults.getConstantValue();
        if (constantValue.getNode().getElementType() == DbTokenTypes.STRING_LITERAL) {
          String text = constantValue.getText();
          return text.substring(1, text.length() -1);  // return unquoted string literal.
        }
        return constantValue.getText();
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:DbUtil.java

示例6: registerReferencesFromInjectedFragments

import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
private void registerReferencesFromInjectedFragments(final PsiElement element) {
  InjectedLanguageUtil.enumerate(element, myFile, false, new PsiLanguageInjectionHost.InjectedPsiVisitor() {
    @Override
    public void visit(@NotNull final PsiFile injectedPsi, @NotNull final List<PsiLanguageInjectionHost.Shred> places) {
      injectedPsi.accept(REGISTER_REFERENCES_VISITOR);
    }
  });
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:9,代码来源:HighlightVisitorImpl.java

示例7: queryLineMarkersForInjected

import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
private static void queryLineMarkersForInjected(@Nonnull PsiElement element,
                                                @Nonnull final PsiFile containingFile,
                                                @Nonnull Set<PsiFile> visitedInjectedFiles,
                                                @Nonnull final PairConsumer<PsiElement, LineMarkerInfo> consumer) {
  if (containingFile.getViewProvider() instanceof InjectedFileViewProvider) return;
  final InjectedLanguageManager manager = InjectedLanguageManager.getInstance(containingFile.getProject());

  InjectedLanguageUtil.enumerate(element, containingFile, false, (injectedPsi, places) -> {
    if (!visitedInjectedFiles.add(injectedPsi)) return; // there may be several concatenated literals making the one injected file
    final Project project = injectedPsi.getProject();
    Document document = PsiDocumentManager.getInstance(project).getCachedDocument(injectedPsi);
    if (!(document instanceof DocumentWindow)) return;
    List<PsiElement> injElements = CollectHighlightsUtil.getElementsInRange(injectedPsi, 0, injectedPsi.getTextLength());
    final List<LineMarkerProvider> providers = getMarkerProviders(injectedPsi.getLanguage(), project);

    queryProviders(injElements, injectedPsi, providers, (injectedElement, injectedMarker) -> {
      GutterIconRenderer gutterRenderer = injectedMarker.createGutterRenderer();
      TextRange injectedRange = new TextRange(injectedMarker.startOffset, injectedMarker.endOffset);
      List<TextRange> editables = manager.intersectWithAllEditableFragments(injectedPsi, injectedRange);
      for (TextRange editable : editables) {
        TextRange hostRange = manager.injectedToHost(injectedPsi, editable);
        Icon icon = gutterRenderer == null ? null : gutterRenderer.getIcon();
        GutterIconNavigationHandler<PsiElement> navigationHandler = injectedMarker.getNavigationHandler();
        LineMarkerInfo<PsiElement> converted =
                new LineMarkerInfo<>(injectedElement, hostRange, icon, injectedMarker.updatePass,
                                     e -> injectedMarker.getLineMarkerTooltip(), navigationHandler,
                                     GutterIconRenderer.Alignment.RIGHT);
        consumer.consume(injectedElement, converted);
      }
    });
  });
}
 
开发者ID:consulo,项目名称:consulo,代码行数:33,代码来源:LineMarkersPass.java

示例8: processInjectedFileForTag

import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
public static void processInjectedFileForTag(final @NotNull XmlTag tag, @NotNull JSInjectedFilesVisitor visitor)
{

	for(XmlTagChild child : tag.getValue().getChildren())
	{
		if(child instanceof XmlText)
		{
			InjectedLanguageUtil.enumerate(child, visitor);
		}
	}
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:12,代码来源:JSResolveUtil.java

示例9: processInjectedContent

import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
public static void processInjectedContent(final XmlTag element,
                                          @NotNull final Processor<XmlTag> tagProcessor) {
  final PsiLanguageInjectionHost.InjectedPsiVisitor injectedPsiVisitor = new PsiLanguageInjectionHost.InjectedPsiVisitor() {
    @Override
    public void visit(@NotNull PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places) {
      if (injectedPsi instanceof XmlFile) {
        final XmlDocument injectedDocument = ((XmlFile)injectedPsi).getDocument();
        if (injectedDocument != null) {
          final XmlTag rootTag = injectedDocument.getRootTag();
          if (rootTag != null) {
            for (PsiElement element = rootTag; element != null; element = element.getNextSibling()) {
              if (element instanceof XmlTag) {
                final XmlTag tag = (XmlTag)element;
                String tagName = tag.getLocalName();
                if (element instanceof HtmlTag || tag.getNamespacePrefix().length() > 0) tagName = tagName.toLowerCase();
                if (LINK.equalsIgnoreCase(tagName)) {
                  tagProcessor.process((XmlTag)element);
                }
              }
            }
          }
        }
      }
    }
  };

  final XmlText[] texts = PsiTreeUtil.getChildrenOfType(element, XmlText.class);
  if (texts != null && texts.length > 0) {
    for (final XmlText text : texts) {
      for (PsiElement _element : text.getChildren()) {
        if (_element instanceof PsiLanguageInjectionHost) {
          InjectedLanguageUtil.enumerate(_element, injectedPsiVisitor);
        }
      }
    }
  }

  final XmlComment[] comments = PsiTreeUtil.getChildrenOfType(element, XmlComment.class);
  if (comments != null && comments.length > 0) {
    for (final XmlComment comment : comments) {
      if (comment instanceof PsiLanguageInjectionHost) {
        InjectedLanguageUtil.enumerate(comment, injectedPsiVisitor);
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:47,代码来源:HtmlLinkUtil.java

示例10: processInjectedPsi

import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
public void processInjectedPsi(@NotNull InjectedPsiVisitor visitor) {
    InjectedLanguageUtil.enumerate(this, visitor);
}
 
开发者ID:jflex-de,项目名称:idea-jflex,代码行数:4,代码来源:JFlexJavaCodeImpl.java

示例11: execute

import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public boolean execute(final PsiElement element)
{
	if(element instanceof XmlTag)
	{
		final XmlTag tag = (XmlTag) element;

		if(myVisitAllTags || SCRIPT_TAG_NAME.equals(tag.getLocalName()))
		{
			final String srcLocation = tag.getAttributeValue("source");
			if(srcLocation != null)
			{
				PsiReference ref = findFileReference(tag.getAttribute("source").getValueElement());
				if(ref != null)
				{
					final PsiElement psiElement = ref.resolve();
					if(psiElement instanceof JSFile)
					{
						psiElement.putUserData(JSResolveUtil.contextKey, tag);
						myVisitor.visit(myRootTag, (JSFile) psiElement);
					}
				}
			}
			else
			{
				JSResolveUtil.processInjectedFileForTag(tag, new JSResolveUtil.JSInjectedFilesVisitor()
				{
					@Override
					protected void process(final JSFile file)
					{
						myVisitor.visit(myRootTag, file);
					}
				});
			}
		}
		if(isInlineComponentTag(tag))
		{
			if(myVisitInnerComponents)
			{
				new InjectedScriptsVisitor(tag, myVisitAllTags, myVisitAttributes, true, myVisitor).go();
			}
		}
		else
		{
			tag.processElements(this, null);
		}
	}
	if(myVisitAttributes && element instanceof XmlAttribute)
	{
		XmlAttributeValue value = ((XmlAttribute) element).getValueElement();
		if(value != null)
		{
			InjectedLanguageUtil.enumerate(value, new PsiLanguageInjectionHost.InjectedPsiVisitor()
			{
				@Override
				public void visit(@NotNull PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places)
				{
					if(places.get(0).getHost() instanceof XmlAttributeValue)
					{
						myVisitor.visit(myRootTag, (JSFile) injectedPsi);
					}
				}
			});
		}
	}
	return true;
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:68,代码来源:XmlBackedJSClassImpl.java

示例12: getExpressionAtOffset

import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Nullable
public static TextRange getExpressionAtOffset(@NotNull Project project, @NotNull Document document, final int offset)
{
	PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
	if(file == null)
	{
		return null;
	}

	int injectionOffsetCorrection = 0;
	PsiReference ref = file.findReferenceAt(offset);

	if(ref == null)
	{
		final PsiElement at = file.findElementAt(offset);

		TextRange rangeForNamedElement = getRangeForNamedElement(at, 0);
		if(rangeForNamedElement != null)
		{
			return rangeForNamedElement;
		}

		final PsiLanguageInjectionHost psiLanguageInjectionHost = PsiTreeUtil.getParentOfType(at, PsiLanguageInjectionHost.class);

		if(psiLanguageInjectionHost != null)
		{
			final Ref<PsiReference> result = new Ref<PsiReference>();
			final Ref<PsiElement> eltInInjected = new Ref<PsiElement>();
			final int[] injectedOffset = new int[1];

			InjectedLanguageUtil.enumerate(psiLanguageInjectionHost, new PsiLanguageInjectionHost.InjectedPsiVisitor()
			{
				@Override
				public void visit(@NotNull final PsiFile injectedPsi, @NotNull final List<PsiLanguageInjectionHost.Shred> places)
				{
					final PsiLanguageInjectionHost.Shred shred = places.get(0);
					final int injectedStart = shred.getRangeInsideHost().getStartOffset() + shred.getHost().getTextOffset();
					final int offsetInInjected = offset - injectedStart;

					result.set(injectedPsi.findReferenceAt(offsetInInjected));
					eltInInjected.set(injectedPsi.findElementAt(offsetInInjected));
					injectedOffset[0] = injectedStart;
				}
			});

			ref = result.get();

			if(ref == null)
			{
				rangeForNamedElement = getRangeForNamedElement(eltInInjected.get(), injectedOffset[0]);
				if(rangeForNamedElement != null)
				{
					return rangeForNamedElement;
				}
			}
			else
			{
				injectionOffsetCorrection = injectedOffset[0];
			}
		}

		if(ref == null)
		{
			return null;
		}
	}

	final PsiElement element = ref.getElement();
	if(!element.getLanguage().isKindOf(JavaScriptLanguage.INSTANCE))
	{
		return null;
	}

	return element.getTextRange().shiftRight(injectionOffsetCorrection);
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:76,代码来源:JSDebuggerSupportUtils.java

示例13: getContextElement

import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Nullable
public static PsiElement getContextElement(VirtualFile virtualFile, int offset, final @NotNull Project project)
{
	Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
	PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
	if(file == null || document == null)
	{
		return null;
	}

	if(offset < 0)
	{
		offset = 0;
	}
	if(offset > document.getTextLength())
	{
		offset = document.getTextLength();
	}
	int startOffset = offset;

	int lineEndOffset = document.getLineEndOffset(document.getLineNumber(offset));
	PsiElement result = null;
	do
	{
		PsiElement element = file.findElementAt(offset);
		if(!(element instanceof PsiWhiteSpace) && !(element instanceof PsiComment))
		{
			result = element;
			break;
		}

		offset = element.getTextRange().getEndOffset() + 1;
	}
	while(offset < lineEndOffset);

	if(result == null)
	{
		result = file.findElementAt(startOffset);
	}

	if(result != null && result.getLanguage() == XMLLanguage.INSTANCE)
	{
		PsiLanguageInjectionHost parent = PsiTreeUtil.getParentOfType(result, PsiLanguageInjectionHost.class);

		if(parent != null)
		{
			final int finalOffset = offset;
			final Ref<PsiElement> resultInInjected = new Ref<PsiElement>();

			InjectedLanguageUtil.enumerate(parent, new PsiLanguageInjectionHost.InjectedPsiVisitor()
			{
				@Override
				public void visit(@NotNull final PsiFile injectedPsi, @NotNull final List<PsiLanguageInjectionHost.Shred> places)
				{
					final PsiLanguageInjectionHost.Shred shred = places.get(0);
					final int injectedStart = shred.getRangeInsideHost().getStartOffset() + shred.getHost().getTextOffset();
					final int offsetInInjected = finalOffset - injectedStart;

					resultInInjected.set(injectedPsi.findElementAt(offsetInInjected));
				}
			});

			result = resultInInjected.get();
		}
	}
	return result;
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:68,代码来源:JSDebuggerSupportUtils.java


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