com.intellij.psi.templateLanguages.OuterLanguageElement Java Examples

The following examples show how to use com.intellij.psi.templateLanguages.OuterLanguageElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ErrorFilter.java    From intellij-latte with MIT License 6 votes vote down vote up
public boolean shouldHighlightErrorElement(@NotNull PsiErrorElement element) {
	PsiFile templateLanguageFile = PsiUtilCore.getTemplateLanguageFile(element.getContainingFile());
	if (templateLanguageFile == null) {
		return true;
	}
	Language language = templateLanguageFile.getLanguage();
	if (language != LatteLanguage.INSTANCE) {
		return true;
	}
	if (element.getParent() instanceof XmlElement || element.getParent() instanceof CssElement) {
		return false;
	}
	if (element.getParent().getLanguage() == LatteLanguage.INSTANCE) {
		return true;
	}
	PsiElement nextSibling;
	for (nextSibling = PsiTreeUtil.nextLeaf(element); nextSibling instanceof PsiWhiteSpace; nextSibling = nextSibling.getNextSibling());

	PsiElement psiElement = nextSibling == null ? null : PsiTreeUtil.findCommonParent(nextSibling, element);
	boolean nextIsOuterLanguageElement = nextSibling instanceof OuterLanguageElement || nextSibling instanceof LatteMacroClassic;
	return !nextIsOuterLanguageElement || psiElement == null || psiElement instanceof PsiFile;
}
 
Example #2
Source File: MultiplePsiFilesPerDocumentFileViewProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nullable
public PsiElement findElementAt(int offset, @Nonnull Class<? extends Language> lang) {
  final PsiFile mainRoot = getPsi(getBaseLanguage());
  PsiElement ret = null;
  for (final Language language : getLanguages()) {
    if (!ReflectionUtil.isAssignable(lang, language.getClass())) continue;
    if (lang.equals(Language.class) && !getLanguages().contains(language)) continue;

    final PsiFile psiRoot = getPsi(language);
    final PsiElement psiElement = findElementAt(psiRoot, offset);
    if (psiElement == null || psiElement instanceof OuterLanguageElement) continue;
    if (ret == null || psiRoot != mainRoot) {
      ret = psiElement;
    }
  }
  return ret;
}
 
Example #3
Source File: SharedPsiElementImplUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@RequiredReadAction
public static PsiReference findReferenceAt(PsiElement thisElement, int offset, @Nullable Language lang) {
  if (thisElement == null) return null;
  PsiElement element = lang != null ? thisElement.getContainingFile().getViewProvider().findElementAt(offset, lang) :
                       thisElement.findElementAt(offset);
  if (element == null || element instanceof OuterLanguageElement) return null;
  offset = thisElement.getTextRange().getStartOffset() + offset - element.getTextRange().getStartOffset();

  List<PsiReference> referencesList = new ArrayList<PsiReference>();
  while (element != null) {
    addReferences(offset, element, referencesList);
    if (element instanceof PsiFile) break;
    if (element instanceof HintedReferenceHost &&
        !((HintedReferenceHost)element).shouldAskParentForReferences(new PsiReferenceService.Hints(null, offset))) {
      break;
    }
    offset = element.getStartOffsetInParent() + offset;
    element = element.getParent();
  }

  if (referencesList.isEmpty()) return null;
  if (referencesList.size() == 1) return referencesList.get(0);
  return new PsiMultiReference(referencesList.toArray(new PsiReference[referencesList.size()]),
                               referencesList.get(referencesList.size() - 1).getElement());
}
 
Example #4
Source File: CommentByBlockCommentHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean testSelectionForNonComments() {
  if (!myCaret.hasSelection()) {
    return true;
  }
  TextRange range = new TextRange(myCaret.getSelectionStart(), myCaret.getSelectionEnd() - 1);
  for (PsiElement element = myFile.findElementAt(range.getStartOffset()); element != null && range.intersects(element.getTextRange()); element = element.getNextSibling()) {
    if (element instanceof OuterLanguageElement) {
      if (!isInjectedWhiteSpace(range, (OuterLanguageElement)element)) {
        return false;
      }
    }
    else {
      if (!isWhiteSpaceOrComment(element, range)) {
        return false;
      }
    }
  }
  return true;
}
 
Example #5
Source File: PsiTreeUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static List<PsiElement> getInjectedElements(@Nonnull OuterLanguageElement outerLanguageElement) {
  PsiElement psi = outerLanguageElement.getContainingFile().getViewProvider().getPsi(outerLanguageElement.getLanguage());
  TextRange injectionRange = outerLanguageElement.getTextRange();
  List<PsiElement> res = ContainerUtil.newArrayList();

  assert psi != null : outerLanguageElement;
  for (PsiElement element = psi.findElementAt(injectionRange.getStartOffset()); element != null && injectionRange.intersectsStrict(element.getTextRange()); element = element.getNextSibling()) {
    res.add(element);
  }

  return res;
}
 
Example #6
Source File: PsiErrorElementImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public Language getLanguage() {
  PsiElement master = this;
  while (true) {
    master = master.getNextSibling();
    if (master == null || master instanceof OuterLanguageElement) return getParent().getLanguage();
    if (master instanceof PsiWhiteSpace || master instanceof PsiErrorElement) continue;
    return master.getLanguage();
  }
}
 
Example #7
Source File: TreeUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean containsOuterLanguageElements(@Nonnull ASTNode node) {
  AtomicBoolean result = new AtomicBoolean(false);
  ((TreeElement)node).acceptTree(new RecursiveTreeElementWalkingVisitor() {
    @Override
    protected void visitNode(TreeElement element) {
      if (element instanceof OuterLanguageElement) {
        result.set(true);
        stopWalking();
        return;
      }
      super.visitNode(element);
    }
  });
  return result.get();
}
 
Example #8
Source File: CodeEditUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void checkForOuters(ASTNode element) {
  if (element instanceof OuterLanguageElement && element.getCopyableUserData(OUTER_OK) == null) {
    throw new IllegalArgumentException("Outer element " + element + " is not allowed here");
  }

  ASTNode child = element.getFirstChildNode();
  while (child != null) {
    checkForOuters(child);
    child = child.getTreeNext();
  }
}
 
Example #9
Source File: CommentByBlockCommentHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean isInjectedWhiteSpace(@Nonnull TextRange range, @Nonnull OuterLanguageElement element) {
  PsiElement psi = element.getContainingFile().getViewProvider().getPsi(element.getLanguage());
  if (psi == null) {
    return false;
  }
  List<PsiElement> injectedElements = PsiTreeUtil.getInjectedElements(element);
  for (PsiElement el : injectedElements) {
    if (!isWhiteSpaceOrComment(el, range)) {
      return false;
    }
  }
  return true;
}
 
Example #10
Source File: PsiElementVisitor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void visitOuterLanguageElement(OuterLanguageElement element) {
  visitElement(element);
}
 
Example #11
Source File: GenericDynamicContextProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected boolean isDynamic(PsiElement child) {
  return child instanceof OuterLanguageElement;
}
 
Example #12
Source File: DataLanguageBlockWrapper.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public static DataLanguageBlockWrapper create(@Nonnull final Block original, @Nullable final Indent indent) {
  final boolean doesntNeedWrapper = original instanceof ASTBlock && ((ASTBlock)original).getNode() instanceof OuterLanguageElement;
  return doesntNeedWrapper ? null : new DataLanguageBlockWrapper(original);
}