本文整理汇总了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);
}
});
}
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}
示例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);
}
});
}
示例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);
}
});
});
}
示例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);
}
}
}
示例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);
}
}
}
}
示例10: processInjectedPsi
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
public void processInjectedPsi(@NotNull InjectedPsiVisitor visitor) {
InjectedLanguageUtil.enumerate(this, visitor);
}
示例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;
}
示例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);
}
示例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;
}