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

The following examples show how to use com.intellij.psi.PsiElement#isPhysical() . 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: JavaBinaryContextProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: ScalaBinaryContextProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 3
Source File: CSharpAnchorProvider.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 4
Source File: IdentifierUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 5
Source File: FileInfoManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 6
Source File: CSharpExpressionEvaluator.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 7
Source File: RefElementImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 8
Source File: NavigationItemFileStatus.java    From consulo with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: Identikit.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 10
Source File: PsiCachedValue.java    From consulo with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 11
Source File: FileInfoManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
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)));
}
 
Example 12
Source File: FileInfoManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 13
Source File: IdempotenceChecker.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean seemsToBeResolveTarget(@Nonnull PsiElement psi) {
  if (psi.isPhysical()) return true;
  PsiElement nav = psi.getNavigationElement();
  return nav != null && nav.isPhysical();
}