下面列出了com.intellij.psi.PsiElement#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
/** 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();
}
/** 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();
}
}
/**
* 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", " ");
}
@NotNull
@Override
public String getDescriptiveName(@NotNull PsiElement psiElement) {
return psiElement.toString();
}
@NotNull
@Override
public String getDescriptiveName(@NotNull PsiElement element) {
return element.toString();
}
@NotNull
@Override
public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
return element.toString();
}