Java Code Examples for com.intellij.psi.PsiElement#EMPTY_ARRAY

The following examples show how to use com.intellij.psi.PsiElement#EMPTY_ARRAY . 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: ASTDelegatePsiElement.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
@RequiredReadAction
public PsiElement[] getChildren() {
  PsiElement psiChild = getFirstChild();
  if (psiChild == null) return PsiElement.EMPTY_ARRAY;

  List<PsiElement> result = new ArrayList<PsiElement>();
  while (psiChild != null) {
    if (psiChild.getNode() instanceof CompositeElement) {
      result.add(psiChild);
    }
    psiChild = psiChild.getNextSibling();
  }
  return PsiUtilCore.toPsiElementArray(result);
}
 
Example 2
Source File: CreateFileFromTemplateDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public <T extends PsiElement> void show(@Nonnull String errorTitle, @Nullable String selectedTemplateName, @Nonnull final FileCreator<T> creator, @Nonnull Consumer<T> consumer) {
  final Ref<T> created = Ref.create(null);
  myDialog.getKindCombo().setSelectedName(selectedTemplateName);
  myDialog.myCreator = new ElementCreator(myProject, errorTitle) {

    @Override
    protected PsiElement[] create(String newName) throws Exception {
      final T element = creator.createFile(myDialog.getEnteredName(), myDialog.getKindCombo().getSelectedName());
      created.set(element);
      if (element != null) {
        return new PsiElement[]{element};
      }
      return PsiElement.EMPTY_ARRAY;
    }

    @Override
    protected String getActionName(String newName) {
      return creator.getActionName(newName, myDialog.getKindCombo().getSelectedName());
    }
  };

  myDialog.showAsync().doWhenDone(() -> consumer.accept(created.get()));
}
 
Example 3
Source File: ArrayVariableMacro.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
protected PsiElement[] getVariables(Expression[] params, ExpressionContext context)
{
	final PsiElement psiElementAtStartOffset = context.getPsiElementAtStartOffset();
	if(psiElementAtStartOffset == null)
	{
		return PsiElement.EMPTY_ARRAY;
	}

	List<DotNetVariable> variables = CSharpLiveTemplateMacroUtil.resolveAllVariables(context.getPsiElementAtStartOffset());

	List<DotNetVariable> list = new SmartList<DotNetVariable>();
	for(DotNetVariable variable : variables)
	{
		DotNetTypeRef typeRefOfVariable = variable.toTypeRef(true);

		if(typeRefOfVariable instanceof CSharpArrayTypeRef && ((CSharpArrayTypeRef) typeRefOfVariable).getDimensions() == 0)
		{
			list.add(variable);
		}
	}
	return list.toArray(new PsiElement[list.size()]);
}
 
Example 4
Source File: ElementCreator.java    From consulo with Apache License 2.0 6 votes vote down vote up
public PsiElement[] tryCreate(@Nonnull final String inputString) {
  if (inputString.length() == 0) {
    Messages.showMessageDialog(myProject, IdeBundle.message("error.name.should.be.specified"), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    return PsiElement.EMPTY_ARRAY;
  }

  Ref<List<SmartPsiElementPointer>> createdElements = Ref.create();
  Exception exception = executeCommand(getActionName(inputString), () -> {
    PsiElement[] psiElements = create(inputString);
    SmartPointerManager manager = SmartPointerManager.getInstance(myProject);
    createdElements.set(ContainerUtil.map(psiElements, manager::createSmartPsiElementPointer));
  });
  if (exception != null) {
    handleException(exception);
    return PsiElement.EMPTY_ARRAY;
  }

  return ContainerUtil.mapNotNull(createdElements.get(), SmartPsiElementPointer::getElement).toArray(PsiElement.EMPTY_ARRAY);
}
 
Example 5
Source File: PsiElementUtils.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
/**
 * getChildren fixed helper
 */
static public PsiElement[] getChildrenFix(PsiElement psiElement) {
    PsiElement startElement = psiElement.getFirstChild();
    if(startElement == null) {
        return PsiElement.EMPTY_ARRAY;
    }

    List<PsiElement> psiElements = new ArrayList<>();
    psiElements.add(startElement);

    for (PsiElement child = psiElement.getFirstChild().getNextSibling(); child != null; child = child.getNextSibling()) {
        psiElements.add(child);
    }

    return psiElements.toArray(new PsiElement[psiElements.size()]);
}
 
Example 6
Source File: Trees.java    From antlr4-intellij-adaptor with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Get all non-WS, non-Comment children of t */
@NotNull
public static PsiElement[] getChildren(PsiElement t) {
	if ( t==null ) return PsiElement.EMPTY_ARRAY;

	PsiElement psiChild = t.getFirstChild();
	if (psiChild == null) return PsiElement.EMPTY_ARRAY;

	List<PsiElement> result = new ArrayList<>();
	while (psiChild != null) {
		if ( !(psiChild instanceof PsiComment) &&
			 !(psiChild instanceof PsiWhiteSpace) )
		{
			result.add(psiChild);
		}
		psiChild = psiChild.getNextSibling();
	}
	return PsiUtilCore.toPsiElementArray(result);
}
 
Example 7
Source File: PhpEnvCompletionContributor.java    From idea-php-dotenv-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {

    if(psiElement == null) {
        return PsiElement.EMPTY_ARRAY;
    }

    StringLiteralExpression stringLiteral = getStringLiteral(psiElement);

    if(stringLiteral == null) {
        return PsiElement.EMPTY_ARRAY;
    }

    return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), stringLiteral.getContents());
}
 
Example 8
Source File: PythonEnvCompletionProvider.java    From idea-php-dotenv-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {

    if(psiElement == null) {
        return PsiElement.EMPTY_ARRAY;
    }

    PyStringLiteralExpression stringLiteral = getStringLiteral(psiElement);

    if(stringLiteral == null) {
        return PsiElement.EMPTY_ARRAY;
    }

    return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), stringLiteral.getStringValue());
}
 
Example 9
Source File: CustomFoldingSurroundDescriptor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) {
  if (startOffset >= endOffset - 1) return PsiElement.EMPTY_ARRAY;
  Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(file.getLanguage());
  if (commenter == null || commenter.getLineCommentPrefix() == null) return PsiElement.EMPTY_ARRAY;
  PsiElement startElement = file.findElementAt(startOffset);
  if (startElement instanceof PsiWhiteSpace) startElement = startElement.getNextSibling();
  PsiElement endElement = file.findElementAt(endOffset - 1);
  if (endElement instanceof PsiWhiteSpace) endElement = endElement.getPrevSibling();
  if (startElement != null && endElement != null) {
    if (startElement.getTextRange().getStartOffset() > endElement.getTextRange().getStartOffset()) return PsiElement.EMPTY_ARRAY;
    startElement = findClosestParentAfterLineBreak(startElement);
    if (startElement != null) {
      endElement = findClosestParentBeforeLineBreak(endElement);
      if (endElement != null) {
        PsiElement commonParent = startElement.getParent();
        if (endElement.getParent() == commonParent) {
          if (startElement == endElement) return new PsiElement[] {startElement};
          return new PsiElement[] {startElement, endElement};
        }
      }
    }
  }
  return PsiElement.EMPTY_ARRAY;
}
 
Example 10
Source File: DockerfileKeyGotoHandler.java    From idea-php-dotenv-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {

    if(psiElement == null || psiElement.getParent() == null) {
        return PsiElement.EMPTY_ARRAY;
    }

    if(!psiElement.getContainingFile().getName().equals("Dockerfile")) {
        return PsiElement.EMPTY_ARRAY;
    }

    psiElement = psiElement.getParent();

    if(!(psiElement instanceof DockerFileEnvRegularDeclaration)) {
        return PsiElement.EMPTY_ARRAY;
    }

    return EnvironmentVariablesApi.getKeyUsages(psiElement.getProject(), EnvironmentVariablesUtil.getKeyFromString((((DockerFileEnvRegularDeclaration) psiElement).getDeclaredName().getText())));
}
 
Example 11
Source File: JsEnvCompletionProvider.java    From idea-php-dotenv-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {

    if(psiElement == null) {
        return PsiElement.EMPTY_ARRAY;
    }

    if(!JsPsiHelper.checkPsiElement(psiElement)) {
        return PsiElement.EMPTY_ARRAY;
    }

    return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), psiElement.getText());
}
 
Example 12
Source File: GotoClassAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static PsiElement[] getAnonymousClasses(@Nonnull PsiElement element) {
  for (AnonymousElementProvider provider : AnonymousElementProvider.EP_NAME.getExtensionList()) {
    final PsiElement[] elements = provider.getAnonymousElements(element);
    if (elements.length > 0) {
      return elements;
    }
  }
  return PsiElement.EMPTY_ARRAY;
}
 
Example 13
Source File: GoEnvCompletionProvider.java    From idea-php-dotenv-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
    if(psiElement == null) {
        return PsiElement.EMPTY_ARRAY;
    }

    GoStringLiteral stringLiteral = getStringLiteral(psiElement);

    if(stringLiteral == null) {
        return PsiElement.EMPTY_ARRAY;
    }

    return EnvironmentVariablesApi.getKeyDeclarations(psiElement.getProject(), stringLiteral.getDecodedText());
}
 
Example 14
Source File: GotoHandler.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Editor editor) {

    if (!LaravelProjectComponent.isEnabled(psiElement)) {
        return PsiElement.EMPTY_ARRAY;
    }

    Collection<PsiElement> psiTargets = new ArrayList<PsiElement>();

    PsiElement parent = psiElement.getParent();

    for(GotoCompletionContributor contributor: GotoCompletionUtil.getContributors(psiElement)) {
        GotoCompletionProviderInterface gotoCompletionContributorProvider = contributor.getProvider(psiElement);
        if(gotoCompletionContributorProvider != null) {
            // @TODO: replace this: just valid PHP files
            if(parent instanceof StringLiteralExpression) {
                psiTargets.addAll(gotoCompletionContributorProvider.getPsiTargets((StringLiteralExpression) parent));
            } else {
                psiTargets.addAll(gotoCompletionContributorProvider.getPsiTargets(psiElement));
            }

            psiTargets.addAll(gotoCompletionContributorProvider.getPsiTargets(psiElement, i, editor));
        }
    }

    return psiTargets.toArray(new PsiElement[psiTargets.size()]);
}
 
Example 15
Source File: ImplementationSearcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public PsiElement[] searchImplementations(PsiElement element, Editor editor, boolean includeSelfAlways, boolean includeSelfIfNoOthers) {
  if (element == null) return PsiElement.EMPTY_ARRAY;
  PsiElement[] elements = searchDefinitions(element, editor);
  if (elements == null) return null; //the search has been cancelled
  if (elements.length > 0) return filterElements(element, includeSelfAlways ? ArrayUtil.prepend(element, elements) : elements);
  if (includeSelfAlways || includeSelfIfNoOthers) return new PsiElement[]{element};
  return PsiElement.EMPTY_ARRAY;
}
 
Example 16
Source File: BlazeCreateResourceFileDialog.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public PsiElement[] getCreatedElements() {
  return myValidator != null ? myValidator.getCreatedElements() : PsiElement.EMPTY_ARRAY;
}
 
Example 17
Source File: FindUsagesHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public PsiElement[] getSecondaryElements() {
  return PsiElement.EMPTY_ARRAY;
}
 
Example 18
Source File: HaxeFindUsagesHandler.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
protected HaxeFindUsagesHandler(@NotNull PsiElement psiElement) {
  this(psiElement, PsiElement.EMPTY_ARRAY);
}
 
Example 19
Source File: FakePsiElement.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
@Override
@Nonnull
public PsiElement[] getChildren() {
  return PsiElement.EMPTY_ARRAY;
}
 
Example 20
Source File: ThriftPrefixReference.java    From intellij-thrift with Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public Object[] getVariants() {
  return PsiElement.EMPTY_ARRAY;
}