本文整理汇总了Java中com.intellij.psi.util.PsiUtilCore类的典型用法代码示例。如果您正苦于以下问题:Java PsiUtilCore类的具体用法?Java PsiUtilCore怎么用?Java PsiUtilCore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PsiUtilCore类属于com.intellij.psi.util包,在下文中一共展示了PsiUtilCore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIcon
import com.intellij.psi.util.PsiUtilCore; //导入依赖的package包/类
@Nullable
@Override
public Icon getIcon(@NotNull final PsiElement psiElement, final int i) {
Icon icon = null;
// Only replace icons on elements representing a file
// Prevents file icons from being assigned to classes, methods, fields, etc.
if (psiElement instanceof PsiFile) {
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(psiElement);
if (virtualFile != null) {
final FileInfo file = new VirtualFileInfo(psiElement, virtualFile);
icon = getIconForAssociation(file, associations.findAssociationForFile(file));
}
} else if (psiElement instanceof PsiDirectory) {
icon = getDirectoryIcon((PsiDirectory) psiElement);
}
return icon;
}
示例2: isAccepted
import com.intellij.psi.util.PsiUtilCore; //导入依赖的package包/类
@Override
public boolean isAccepted(PsiClass klass) {
return ApplicationManager.getApplication().runReadAction((Computable<Boolean>) () -> {
if (isSketchClass(klass)) {
final CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(project);
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(klass);
if (virtualFile == null) {
return false;
}
return ! compilerConfiguration.isExcludedFromCompilation(virtualFile) &&
! ProjectRootManager.getInstance(project)
.getFileIndex()
.isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.RESOURCES);
}
return false;
});
}
示例3: createInstance
import com.intellij.psi.util.PsiUtilCore; //导入依赖的package包/类
public static SafeDeleteProcessor createInstance(Project project, @Nullable Runnable prepareSuccessfulCallBack,
PsiElement[] elementsToDelete, boolean isSearchInComments, boolean isSearchNonJava,
boolean askForAccessors) {
ArrayList<PsiElement> elements = new ArrayList<PsiElement>(Arrays.asList(elementsToDelete));
HashSet<PsiElement> elementsToDeleteSet = new HashSet<PsiElement>(Arrays.asList(elementsToDelete));
for (PsiElement psiElement : elementsToDelete) {
for(SafeDeleteProcessorDelegate delegate: Extensions.getExtensions(SafeDeleteProcessorDelegate.EP_NAME)) {
if (delegate.handlesElement(psiElement)) {
Collection<PsiElement> addedElements = delegate.getAdditionalElementsToDelete(psiElement, elementsToDeleteSet, askForAccessors);
if (addedElements != null) {
elements.addAll(addedElements);
}
break;
}
}
}
return new SafeDeleteProcessor(project, prepareSuccessfulCallBack,
PsiUtilCore.toPsiElementArray(elements),
isSearchInComments, isSearchNonJava);
}
示例4: invoke
import com.intellij.psi.util.PsiUtilCore; //导入依赖的package包/类
@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) {
PsiDocumentManager.getInstance(project).commitAllDocuments();
int offset = editor.getCaretModel().getOffset();
final Language language = PsiUtilCore.getLanguageAtOffset(file, offset);
final CodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.GOTO_SUPER.forLanguage(language);
if (codeInsightActionHandler != null) {
DumbService.getInstance(project).withAlternativeResolveEnabled(new Runnable() {
@Override
public void run() {
codeInsightActionHandler.invoke(project, editor, file);
}
});
}
}
示例5: visitClassType
import com.intellij.psi.util.PsiUtilCore; //导入依赖的package包/类
@Override
public PsiType visitClassType(final PsiClassType classType) {
PsiClassType alreadyComputed = myResultMap.get(classType);
if (alreadyComputed != null) {
return alreadyComputed;
}
final PsiClassType.ClassResolveResult classResolveResult = classType.resolveGenerics();
final PsiClass psiClass = classResolveResult.getElement();
final PsiSubstitutor substitutor = classResolveResult.getSubstitutor();
if (psiClass == null) return classType;
PsiUtilCore.ensureValid(psiClass);
final PsiClass mappedClass = mapClass(psiClass);
if (mappedClass == null) return classType;
PsiClassType mappedType = new PsiCorrectedClassType(classType.getLanguageLevel(),
classType,
new CorrectedResolveResult(psiClass, mappedClass, substitutor, classResolveResult));
myResultMap.put(classType, mappedType);
return mappedType;
}
示例6: findCommenter
import com.intellij.psi.util.PsiUtilCore; //导入依赖的package包/类
@Nullable
private static Commenter findCommenter(Editor editor, PsiFile file, final int line) {
final FileType fileType = file.getFileType();
if (fileType instanceof AbstractFileType) {
return ((AbstractFileType)fileType).getCommenter();
}
Document document = editor.getDocument();
int lineStartOffset = document.getLineStartOffset(line);
int lineEndOffset = document.getLineEndOffset(line) - 1;
final CharSequence charSequence = document.getCharsSequence();
lineStartOffset = CharArrayUtil.shiftForward(charSequence, lineStartOffset, " \t");
lineEndOffset = CharArrayUtil.shiftBackward(charSequence, lineEndOffset < 0 ? 0 : lineEndOffset, " \t");
final Language lineStartLanguage = PsiUtilCore.getLanguageAtOffset(file, lineStartOffset);
final Language lineEndLanguage = PsiUtilCore.getLanguageAtOffset(file, lineEndOffset);
return CommentByBlockCommentHandler.getCommenter(file, editor, lineStartLanguage, lineEndLanguage);
}
示例7: findFirstTopLevelWithUsageAtDestination
import com.intellij.psi.util.PsiUtilCore; //导入依赖的package包/类
@Nullable
private PsiElement findFirstTopLevelWithUsageAtDestination() {
final List<PsiElement> topLevelAtDestination = ContainerUtil.mapNotNull(myUsages, new Function<UsageInfo, PsiElement>() {
@Override
public PsiElement fun(UsageInfo usage) {
final PsiElement element = usage.getElement();
if (element != null && ScopeUtil.getScopeOwner(element) == myDestinationFile && getImportStatementByElement(element) == null) {
return findTopLevelParent(element);
}
return null;
}
});
if (topLevelAtDestination.isEmpty()) {
return null;
}
return Collections.min(topLevelAtDestination, new Comparator<PsiElement>() {
@Override
public int compare(PsiElement e1, PsiElement e2) {
return PsiUtilCore.compareElementsByPosition(e1, e2);
}
});
}
示例8: getDescriptor
import com.intellij.psi.util.PsiUtilCore; //导入依赖的package包/类
@Nullable
public static Navigatable getDescriptor(@NotNull PsiElement element) {
PsiElement original = getNavigatableOriginalElement(element);
if (original != null) {
element = original;
}
else if (!canNavigate(element)) {
return null;
}
if (element instanceof PomTargetPsiElement) {
return ((PomTargetPsiElement)element).getTarget();
}
final PsiElement navigationElement = element.getNavigationElement();
if (navigationElement instanceof PomTargetPsiElement) {
return ((PomTargetPsiElement)navigationElement).getTarget();
}
final int offset = navigationElement instanceof PsiFile ? -1 : navigationElement.getTextOffset();
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(navigationElement);
if (virtualFile == null || !virtualFile.isValid()) {
return null;
}
OpenFileDescriptor desc = new OpenFileDescriptor(navigationElement.getProject(), virtualFile, offset);
desc.setUseCurrentWindow(FileEditorManager.USE_CURRENT_WINDOW.isIn(navigationElement));
return desc;
}
示例9: contains
import com.intellij.psi.util.PsiUtilCore; //导入依赖的package包/类
public boolean contains(VirtualFile file) {
final Object value = getValue();
if (value instanceof PsiElement) {
final boolean equalContainingFile = Comparing.equal(PsiUtilCore.getVirtualFile((PsiElement)value), file);
if (equalContainingFile) return true;
}
if (value instanceof PsiDirectory) {
return contains(file, (PsiDirectory)value);
}
else if (value instanceof PsiDirectoryContainer) {
final PsiDirectory[] directories = ((PsiDirectoryContainer)value).getDirectories();
for (PsiDirectory directory : directories) {
if (contains(file, directory)) return true;
}
}
return false;
}
示例10: shortenReference
import com.intellij.psi.util.PsiUtilCore; //导入依赖的package包/类
public static void shortenReference(final PsiFile file, final int offset) throws IncorrectOperationException {
Project project = file.getProject();
final PsiDocumentManager manager = PsiDocumentManager.getInstance(project);
Document document = manager.getDocument(file);
if (document == null) {
PsiUtilCore.ensureValid(file);
LOG.error("No document for " + file);
return;
}
manager.commitDocument(document);
final PsiReference ref = file.findReferenceAt(offset);
if (ref != null) {
PsiElement element = ref.getElement();
if (element != null) {
JavaCodeStyleManager.getInstance(project).shortenClassReferences(element);
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
}
}
}
示例11: getName
import com.intellij.psi.util.PsiUtilCore; //导入依赖的package包/类
private static String getName(final PsiClass psiClass, final LookupElement item, boolean diamond, @NotNull PsiSubstitutor substitutor) {
if (item instanceof JavaPsiClassReferenceElement) {
String forced = ((JavaPsiClassReferenceElement)item).getForcedPresentableName();
if (forced != null) {
return forced;
}
}
String name = PsiUtilCore.getName(psiClass);
if (diamond) {
return name + "<>";
}
if (substitutor != PsiSubstitutor.EMPTY) {
final PsiTypeParameter[] params = psiClass.getTypeParameters();
if (params.length > 0) {
return name + formatTypeParameters(substitutor, params);
}
}
return StringUtil.notNullize(name);
}
示例12: isAccepted
import com.intellij.psi.util.PsiUtilCore; //导入依赖的package包/类
public boolean isAccepted(final PsiClass aClass) {
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
if (aClass.getQualifiedName() != null && ConfigurationUtil.PUBLIC_INSTANTIATABLE_CLASS.value(aClass) &&
(aClass.isInheritor(myBase, true) || JUnitUtil.isTestClass(aClass))) {
final CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(getProject());
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(aClass);
if (virtualFile == null) return false;
return !compilerConfiguration.isExcludedFromCompilation(virtualFile) &&
!ProjectRootManager.getInstance(myProject).getFileIndex().isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.RESOURCES);
}
return false;
}
});
}
示例13: compareEntity
import com.intellij.psi.util.PsiUtilCore; //导入依赖的package包/类
private static int compareEntity(final RefEntity entity, final PsiElement element) {
if (entity instanceof RefElement) {
final PsiElement psiElement = ((RefElement)entity).getElement();
if (psiElement != null && element != null) {
return PsiUtilCore.compareElementsByPosition(psiElement, element);
}
if (element == null) return psiElement == null ? 0 : 1;
}
if (element instanceof PsiQualifiedNamedElement) {
return StringUtil.compare(entity.getQualifiedName(), ((PsiQualifiedNamedElement)element).getQualifiedName(), true);
}
if (element instanceof PsiNamedElement) {
return StringUtil.compare(entity.getName(), ((PsiNamedElement)element).getName(), true);
}
return -1;
}
示例14: forcePsiPostprocessAndRestoreElement
import com.intellij.psi.util.PsiUtilCore; //导入依赖的package包/类
public static <T extends PsiElement> T forcePsiPostprocessAndRestoreElement(@NotNull T element,
boolean useFileLanguage) {
final PsiFile psiFile = element.getContainingFile();
final Document document = psiFile.getViewProvider().getDocument();
//if (document == null) return element;
final Language language = useFileLanguage ? psiFile.getLanguage() : PsiUtilCore.getDialect(element);
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(psiFile.getProject());
final RangeMarker rangeMarker = document.createRangeMarker(element.getTextRange());
documentManager.doPostponedOperationsAndUnblockDocument(document);
documentManager.commitDocument(document);
T elementInRange = findElementInRange(psiFile, rangeMarker.getStartOffset(), rangeMarker.getEndOffset(),
(Class<? extends T>)element.getClass(),
language);
rangeMarker.dispose();
return elementInRange;
}
示例15: navigate
import com.intellij.psi.util.PsiUtilCore; //导入依赖的package包/类
@Override
public void navigate(MouseEvent e, PsiElement nameIdentifier) {
final PsiElement listOwner = nameIdentifier.getParent();
final PsiFile containingFile = listOwner.getContainingFile();
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(listOwner);
if (virtualFile != null && containingFile != null) {
final Project project = listOwner.getProject();
final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (editor != null) {
editor.getCaretModel().moveToOffset(nameIdentifier.getTextOffset());
final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file != null && virtualFile.equals(file.getVirtualFile())) {
final JBPopup popup = createActionGroupPopup(containingFile, project, editor);
if (popup != null) {
popup.show(new RelativePoint(e));
}
}
}
}
}