use of com.intellij.psi.impl.PsiManagerEx in project intellij-community by JetBrains.
the class PsiLiteralExpressionImpl method getType.
@Override
public PsiType getType() {
final IElementType type = getLiteralElementType();
if (type == JavaTokenType.INTEGER_LITERAL) {
return PsiType.INT;
}
if (type == JavaTokenType.LONG_LITERAL) {
return PsiType.LONG;
}
if (type == JavaTokenType.FLOAT_LITERAL) {
return PsiType.FLOAT;
}
if (type == JavaTokenType.DOUBLE_LITERAL) {
return PsiType.DOUBLE;
}
if (type == JavaTokenType.CHARACTER_LITERAL) {
return PsiType.CHAR;
}
if (type == JavaTokenType.STRING_LITERAL) {
PsiManagerEx manager = getManager();
GlobalSearchScope resolveScope = ResolveScopeManager.getElementResolveScope(this);
return PsiType.getJavaLangString(manager, resolveScope);
}
if (type == JavaTokenType.TRUE_KEYWORD || type == JavaTokenType.FALSE_KEYWORD) {
return PsiType.BOOLEAN;
}
if (type == JavaTokenType.NULL_KEYWORD) {
return PsiType.NULL;
}
return null;
}
use of com.intellij.psi.impl.PsiManagerEx in project intellij-community by JetBrains.
the class PsiReferenceExpressionImpl method bindToElementViaStaticImport.
@Override
public PsiElement bindToElementViaStaticImport(@NotNull PsiClass qualifierClass) throws IncorrectOperationException {
String qualifiedName = qualifierClass.getQualifiedName();
if (qualifiedName == null)
throw new IncorrectOperationException();
if (getQualifierExpression() != null) {
throw new IncorrectOperationException("Reference is qualified: " + getText());
}
if (!isPhysical()) {
// don't qualify reference: the isReferenceTo() check fails anyway, whether we have a static import for this member or not
return this;
}
String staticName = getReferenceName();
PsiFile containingFile = getContainingFile();
PsiImportList importList = null;
boolean doImportStatic;
if (containingFile instanceof PsiJavaFile) {
importList = ((PsiJavaFile) containingFile).getImportList();
assert importList != null : containingFile;
PsiImportStatementBase singleImportStatement = importList.findSingleImportStatement(staticName);
doImportStatic = singleImportStatement == null;
if (singleImportStatement instanceof PsiImportStaticStatement) {
String qName = qualifierClass.getQualifiedName() + "." + staticName;
if (qName.equals(singleImportStatement.getImportReference().getQualifiedName()))
return this;
}
} else {
doImportStatic = false;
}
if (doImportStatic) {
bindToElementViaStaticImport(qualifierClass, staticName, importList);
} else {
PsiManagerEx manager = getManager();
PsiReferenceExpression classRef = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createReferenceExpression(qualifierClass);
final CharTable treeCharTab = SharedImplUtil.findCharTableByTree(this);
LeafElement dot = Factory.createSingleLeafElement(JavaTokenType.DOT, ".", 0, 1, treeCharTab, manager);
addInternal(dot, dot, SourceTreeToPsiMap.psiElementToTree(getParameterList()), Boolean.TRUE);
addBefore(classRef, SourceTreeToPsiMap.treeElementToPsi(dot));
}
return this;
}
use of com.intellij.psi.impl.PsiManagerEx in project intellij-community by JetBrains.
the class PostprocessReformattingAspect method doPostponedFormattingInner.
private void doPostponedFormattingInner(@NotNull FileViewProvider key) {
final List<ASTNode> astNodes = getContext().myReformatElements.remove(key);
final Document document = key.getDocument();
// Sort ranges by end offsets so that we won't need any offset adjustment after reformat or reindent
if (document == null)
return;
final VirtualFile virtualFile = key.getVirtualFile();
if (!virtualFile.isValid())
return;
PsiManager manager = key.getManager();
if (manager instanceof PsiManagerEx) {
FileManager fileManager = ((PsiManagerEx) manager).getFileManager();
FileViewProvider viewProvider = fileManager.findCachedViewProvider(virtualFile);
if (viewProvider != key) {
// viewProvider was invalidated e.g. due to language level change
if (viewProvider == null)
viewProvider = fileManager.findViewProvider(virtualFile);
if (viewProvider != null) {
key = viewProvider;
}
}
}
final TreeSet<PostprocessFormattingTask> postProcessTasks = new TreeSet<>();
Collection<Disposable> toDispose = ContainerUtilRt.newArrayList();
try {
// process all roots in viewProvider to find marked for reformat before elements and create appropriate range markers
handleReformatMarkers(key, postProcessTasks);
toDispose.addAll(postProcessTasks);
// then we create ranges by changed nodes. One per node. There ranges can intersect. Ranges are sorted by end offset.
if (astNodes != null)
createActionsMap(astNodes, key, postProcessTasks);
if (Boolean.getBoolean("check.psi.is.valid") && ApplicationManager.getApplication().isUnitTestMode()) {
checkPsiIsCorrect(key);
}
while (!postProcessTasks.isEmpty()) {
// now we have to normalize actions so that they not intersect and ordered in most appropriate way
// (free reformatting -> reindent -> formatting under reindent)
final List<PostponedAction> normalizedActions = normalizeAndReorderPostponedActions(postProcessTasks, document);
toDispose.addAll(normalizedActions);
// only in following loop real changes in document are made
for (final PostponedAction normalizedAction : normalizedActions) {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(myPsiManager.getProject());
boolean old = settings.ENABLE_JAVADOC_FORMATTING;
settings.ENABLE_JAVADOC_FORMATTING = false;
try {
normalizedAction.execute(key);
} finally {
settings.ENABLE_JAVADOC_FORMATTING = old;
}
}
}
} finally {
for (Disposable disposable : toDispose) {
//noinspection SSBasedInspection
disposable.dispose();
}
}
}
use of com.intellij.psi.impl.PsiManagerEx in project intellij-community by JetBrains.
the class InjectedLanguageUtil method clearCaches.
public static void clearCaches(@NotNull PsiFile injected, @NotNull DocumentWindowImpl documentWindow) {
VirtualFileWindowImpl virtualFile = (VirtualFileWindowImpl) injected.getVirtualFile();
PsiManagerEx psiManagerEx = (PsiManagerEx) injected.getManager();
if (psiManagerEx.getProject().isDisposed())
return;
DebugUtil.startPsiModification("injected clearCaches");
try {
psiManagerEx.getFileManager().setViewProvider(virtualFile, null);
} finally {
DebugUtil.finishPsiModification();
}
PsiElement context = InjectedLanguageManager.getInstance(injected.getProject()).getInjectionHost(injected);
PsiFile hostFile;
if (context != null) {
hostFile = context.getContainingFile();
} else {
VirtualFile delegate = virtualFile.getDelegate();
hostFile = delegate.isValid() ? psiManagerEx.findFile(delegate) : null;
}
if (hostFile != null) {
// modification of cachedInjectedDocuments must be under PsiLock
synchronized (InjectedLanguageManagerImpl.ourInjectionPsiLock) {
List<DocumentWindow> cachedInjectedDocuments = getCachedInjectedDocuments(hostFile);
for (int i = cachedInjectedDocuments.size() - 1; i >= 0; i--) {
DocumentWindow cachedInjectedDocument = cachedInjectedDocuments.get(i);
if (cachedInjectedDocument == documentWindow) {
cachedInjectedDocuments.remove(i);
}
}
}
}
}
use of com.intellij.psi.impl.PsiManagerEx in project intellij-community by JetBrains.
the class GrEnumTypeDefinitionImpl method getDefEnumMethods.
private PsiMethod[] getDefEnumMethods() {
return CachedValuesManager.getCachedValue(this, () -> {
PsiMethod[] defMethods = new PsiMethod[4];
final PsiManagerEx manager = getManager();
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(getProject());
defMethods[0] = new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "values").setMethodReturnType(factory.createTypeFromText(CommonClassNames.JAVA_UTIL_COLLECTION + "<" + getName() + ">", this)).setContainingClass(this).addModifier(PsiModifier.PUBLIC).addModifier(PsiModifier.STATIC);
defMethods[1] = new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "next").setMethodReturnType(factory.createType(this)).setContainingClass(this).addModifier(PsiModifier.PUBLIC);
defMethods[2] = new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "previous").setMethodReturnType(factory.createType(this)).setContainingClass(this).addModifier(PsiModifier.PUBLIC);
defMethods[3] = new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "valueOf").setMethodReturnType(factory.createType(this)).setContainingClass(this).addParameter("name", CommonClassNames.JAVA_LANG_STRING).addModifier(PsiModifier.PUBLIC).addModifier(PsiModifier.STATIC);
return CachedValueProvider.Result.create(defMethods, this);
});
}
Aggregations