下面列出了com.intellij.psi.PsiElement#isPhysical ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Nullable
private static PsiClass getMainClass(ConfigurationContext context) {
Location location = context.getLocation();
if (location == null) {
return null;
}
location = JavaExecutionUtil.stepIntoSingleClass(location);
if (location == null) {
return null;
}
PsiElement element = location.getPsiElement();
if (!element.isPhysical()) {
return null;
}
return ApplicationConfigurationType.getMainClass(element);
}
@Nullable
static ScObject getMainObject(ConfigurationContext context) {
Location location = context.getLocation();
if (location == null) {
return null;
}
location = JavaExecutionUtil.stepIntoSingleClass(context.getLocation());
if (location == null) {
return null;
}
PsiElement element = location.getPsiElement();
if (!(element.getContainingFile() instanceof ScalaFile)) {
return null;
}
if (!element.isPhysical()) {
return null;
}
return getMainObjectFromElement(element);
}
@Nullable
@Override
@RequiredReadAction
public PsiElement getAnchor(@Nonnull PsiElement element)
{
if(element instanceof MsilElementWrapper || !element.isPhysical())
{
return null;
}
if(element instanceof CSharpTypeDeclaration ||
element instanceof CSharpFieldDeclaration ||
element instanceof CSharpMethodDeclaration ||
element instanceof CSharpConstructorDeclaration ||
element instanceof CSharpIndexMethodDeclaration ||
//element instanceof CSharpConversionMethodDeclaration ||
element instanceof CSharpPropertyDeclaration ||
element instanceof CSharpEventDeclaration)
{
return ((PsiNameIdentifierOwner) element).getNameIdentifier();
}
return null;
}
@javax.annotation.Nullable
@RequiredReadAction
public static PsiElement getNameIdentifier(@Nonnull PsiElement element) {
if (element instanceof PsiNameIdentifierOwner) {
return ((PsiNameIdentifierOwner)element).getNameIdentifier();
}
if (element.isPhysical() &&
element instanceof PsiNamedElement &&
element.getContainingFile() != null &&
element.getTextRange() != null) {
// Quite hacky way to get name identifier. Depends on getTextOffset overriden properly.
final PsiElement potentialIdentifier = element.findElementAt(element.getTextOffset() - element.getTextRange().getStartOffset());
if (potentialIdentifier != null && Comparing.equal(potentialIdentifier.getText(), ((PsiNamedElement)element).getName(), false)) {
return potentialIdentifier;
}
}
return null;
}
@Nullable
private String _getInfo(PsiElement psiElement) {
if (!(psiElement instanceof PsiFile) || !(psiElement.isPhysical())) {
return null;
}
final PsiFile psiFile = (PsiFile)psiElement;
final FileLookupInfoProvider provider = myFileType2InfoProvider.get(psiFile.getFileType());
if (provider != null) {
final VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile != null) {
final Pair<String, String> info = provider.getLookupInfo(virtualFile, psiElement.getProject());
return info == null ? null : info.second;
}
}
return null;
}
@Override
@RequiredReadAction
public void visitPrefixExpression(CSharpPrefixExpressionImpl expression)
{
CSharpOperatorReferenceImpl operatorElement = expression.getOperatorElement();
PsiElement element = operatorElement.resolveToCallable();
if(element != null)
{
if(!element.isPhysical())
{
CSharpCallArgument[] callArguments = expression.getCallArguments();
for(CSharpCallArgument callArgument : callArguments)
{
DotNetExpression argumentExpression = callArgument.getArgumentExpression();
if(argumentExpression == null)
{
cantEvaluateExpression();
}
argumentExpression.accept(this);
}
myEvaluators.add(new PrefixOperatorEvaluator(operatorElement.getOperatorElementType()));
return;
}
}
expressionIsNotSupported();
}
@Nullable
public String getURL() {
final PsiElement element = getPsiElement();
if (element == null || !element.isPhysical()) return null;
final PsiFile containingFile = element.getContainingFile();
if (containingFile == null) return null;
final VirtualFile virtualFile = containingFile.getVirtualFile();
if (virtualFile == null) return null;
return virtualFile.getUrl() + "#" + element.getTextOffset();
}
private static FileStatus getPsiElementFileStatus(PsiElement psiElement) {
if (!psiElement.isPhysical()) return FileStatus.NOT_CHANGED;
PsiFile contFile = psiElement.getContainingFile();
if (contFile == null) return FileStatus.NOT_CHANGED;
VirtualFile vFile = contFile.getVirtualFile();
return vFile != null ? FileStatusManager.getInstance(psiElement.getProject()).getStatus(vFile) : FileStatus.NOT_CHANGED;
}
@Nullable
static Pair<ByAnchor, PsiElement> withAnchor(@Nonnull PsiElement element, @Nonnull Language fileLanguage) {
PsiUtilCore.ensureValid(element);
if (element.isPhysical()) {
for (SmartPointerAnchorProvider provider : SmartPointerAnchorProvider.EP_NAME.getExtensionList()) {
PsiElement anchor = provider.getAnchor(element);
if (anchor != null && anchor.isPhysical() && provider.restoreElement(anchor) == element) {
ByAnchor anchorKit = new ByAnchor(fromPsi(element, fileLanguage), fromPsi(anchor, fileLanguage), provider);
return Pair.create(ourAnchorInterner.intern(anchorKit), anchor);
}
}
}
return null;
}
private boolean isVeryPhysical(@Nonnull PsiElement dependency) {
if (!dependency.isValid()) {
return false;
}
if (!dependency.isPhysical()) {
return false;
}
// injected files are physical but can sometimes (look at you, completion)
// be inexplicably injected into non-physical element, in which case PSI_MODIFICATION_COUNT doesn't change and thus can't be relied upon
InjectedLanguageManager manager = InjectedLanguageManager.getInstance(myManager.getProject());
PsiFile topLevelFile = manager.getTopLevelFile(dependency);
return topLevelFile != null && topLevelFile.isPhysical();
}
public static Object getFileLookupItem(PsiElement psiElement) {
if (!(psiElement instanceof PsiFile) || !(psiElement.isPhysical())) {
return psiElement;
}
final PsiFile file = (PsiFile)psiElement;
return getFileInfoManager()._getLookupItem(file, file.getName(), TargetAWT.to(IconDescriptorUpdaters.getIcon(file, 0)));
}
public static LookupElementBuilder getFileLookupItem(PsiElement psiElement, String encoded, Icon icon) {
if (!(psiElement instanceof PsiFile) || !(psiElement.isPhysical())) {
return LookupElementBuilder.create(psiElement, encoded).withIcon(icon);
}
return getFileInfoManager()._getLookupItem((PsiFile)psiElement, encoded, icon);
}
private static boolean seemsToBeResolveTarget(@Nonnull PsiElement psi) {
if (psi.isPhysical()) return true;
PsiElement nav = psi.getNavigationElement();
return nav != null && nav.isPhysical();
}