Java Code Examples for com.intellij.psi.PsiElement#toString()

The following examples show how to use com.intellij.psi.PsiElement#toString() . 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: CustomRenameHandler.java    From Intellij-Plugin with Apache License 2.0 6 votes vote down vote up
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
    PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
    if (element == null) element = psiElement;
    psiElement = element;
    String text = element.toString();

    //Finding text from annotation
    if (isMethod(element)) {
        List<String> values = StepUtil.getGaugeStepAnnotationValues((PsiMethod) element);
        if (values.size() == 0) {
            return;
        } else if (values.size() == 1)
            text = values.get(0);
        else if (values.size() > 1) {
            Messages.showWarningDialog("Refactoring for steps having aliases are not supported", "Warning");
            return;
        }
    } else if (isStep(element)) {
        text = ((SpecStepImpl) element).getStepValue().getStepAnnotationText();
    } else if (isConcept(element)) {
        text = removeIdentifiers(((ConceptStepImpl) element).getStepValue().getStepAnnotationText());
    }
    final RefactoringDialog form = new RefactoringDialog(this.editor.getProject(), file, this.editor, text);
    form.show();
}
 
Example 2
Source File: BuildFindUsagesProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** Controls text shown for target element in the 'find usages' dialog */
@Override
public String getDescriptiveName(PsiElement element) {
  if (element instanceof BuildElement) {
    return ((BuildElement) element).getPresentableText();
  }
  return element.toString();
}
 
Example 3
Source File: RunConfigurationContext.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** Convert a {@link #getSourceElement()} into an uniquely identifiable string. */
default String getSourceElementString() {
  if (!ApplicationManager.getApplication().isReadAccessAllowed()) {
    return ReadAction.compute(this::getSourceElementString);
  }
  PsiElement element = getSourceElement();
  if (element instanceof PsiFile) {
    return Optional.of((PsiFile) element)
        .map(PsiFile::getVirtualFile)
        .map(VirtualFile::getPath)
        .orElse(element.toString());
  }
  String path =
      Optional.of(element)
              .map(PsiElement::getContainingFile)
              .map(PsiFile::getVirtualFile)
              .map(VirtualFile::getPath)
              .orElse("")
          + '#';
  if (element instanceof PsiQualifiedNamedElement) {
    return path + ((PsiQualifiedNamedElement) element).getQualifiedName();
  } else if (element instanceof PsiNamedElement) {
    return path + ((PsiNamedElement) element).getName();
  } else {
    return path + element.toString();
  }
}
 
Example 4
Source File: HaxeFindUsagesProvider.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
/**
 * Get a useful debug value from an element.
 * XXX: Should check whether element is a HaxePsiElement type and call a specific debug method there?
 *
 * @param psiElement
 * @return ID for debug logging.
 */
private static String debugId(final PsiElement psiElement) {
  String s = psiElement.toString();
  if (s.length() > DEBUG_ID_LEN) {
    s = s.substring(0, DEBUG_ID_LEN);
  }
  return s.replaceAll("\n", " ");
}
 
Example 5
Source File: ConceptStepFindUsagesProvider.java    From Intellij-Plugin with Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public String getDescriptiveName(@NotNull PsiElement psiElement) {
    return psiElement.toString();
}
 
Example 6
Source File: GLSLFindUsagesProvider.java    From glsl4idea with GNU Lesser General Public License v3.0 4 votes vote down vote up
@NotNull
@Override
public String getDescriptiveName(@NotNull PsiElement element) {
    return element.toString();
}
 
Example 7
Source File: GLSLFindUsagesProvider.java    From glsl4idea with GNU Lesser General Public License v3.0 4 votes vote down vote up
@NotNull
@Override
public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
    return element.toString();
}