use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class QualifiedMethodInsertHandler method handleInsert.
@Override
public void handleInsert(InsertionContext context, JavaGlobalMemberLookupElement item) {
GroovyInsertHandler.INSTANCE.handleInsert(context, item);
final PsiClass containingClass = item.getContainingClass();
context.getDocument().insertString(context.getStartOffset(), containingClass.getName() + ".");
PsiDocumentManager.getInstance(containingClass.getProject()).commitDocument(context.getDocument());
final GrReferenceExpression ref = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), GrReferenceExpression.class, false);
if (ref != null) {
ref.bindToElement(containingClass);
}
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class ImportOnDemandIntention method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
if (!(element instanceof GrReferenceElement))
return;
final GrReferenceElement ref = (GrReferenceElement) element;
final PsiElement resolved = ref.resolve();
if (!(resolved instanceof PsiClass))
return;
final String qname = ((PsiClass) resolved).getQualifiedName();
final GrImportStatement importStatement = GroovyPsiElementFactory.getInstance(project).createImportStatementFromText(qname, true, true, null);
final PsiFile containingFile = element.getContainingFile();
if (!(containingFile instanceof GroovyFile))
return;
((GroovyFile) containingFile).addImport(importStatement);
for (PsiReference reference : ReferencesSearch.search(resolved, new LocalSearchScope(containingFile))) {
final PsiElement refElement = reference.getElement();
if (refElement == null)
continue;
final PsiElement parent = refElement.getParent();
if (parent instanceof GrQualifiedReference<?>) {
org.jetbrains.plugins.groovy.codeStyle.GrReferenceAdjuster.shortenReference((GrQualifiedReference<?>) parent);
}
}
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class GrMethodBodyFixer method apply.
@Override
public void apply(@NotNull Editor editor, @NotNull GroovySmartEnterProcessor processor, @NotNull PsiElement psiElement) {
if (!(psiElement instanceof GrMethod))
return;
GrMethod method = (GrMethod) psiElement;
final PsiClass aClass = method.getContainingClass();
if (aClass != null && aClass.isInterface() || method.hasModifierProperty(PsiModifier.ABSTRACT))
return;
final GrCodeBlock body = method.getBlock();
final Document doc = editor.getDocument();
if (body != null) {
// See IDEADEV-1093. This is quite hacky heuristic but it seem to be best we can do.
String bodyText = body.getText();
if (StringUtil.startsWithChar(bodyText, '{')) {
final GrStatement[] statements = body.getStatements();
if (statements.length > 0) {
// [todo]
// if (statements[0] instanceof PsiDeclarationStatement) {
// if (PsiTreeUtil.getDeepestLast(statements[0]) instanceof PsiErrorElement) {
// if (method.getContainingClass().getRBrace() == null) {
// doc.insertString(body.getTextRange().getStartOffset() + 1, "\n}");
// }
// }
// }
}
}
return;
}
int endOffset = method.getTextRange().getEndOffset();
if (StringUtil.endsWithChar(method.getText(), ';')) {
doc.deleteString(endOffset - 1, endOffset);
endOffset--;
}
doc.insertString(endOffset, "{\n}");
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class SceneBuilderImpl method prepareCustomComponents.
@NotNull
private Collection<CustomComponent> prepareCustomComponents(Collection<PsiClass> psiClasses) {
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(myProject);
final GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
final Map<String, BuiltinComponent> builtinComponents = loadBuiltinComponents(className -> psiFacade.findClass(className, scope) != null);
final List<CustomComponent> customComponents = new ArrayList<>();
for (PsiClass psiClass : psiClasses) {
final String qualifiedName = psiClass.getQualifiedName();
final String name = psiClass.getName();
if (qualifiedName != null && name != null) {
BuiltinComponent parentComponent = null;
for (PsiClass aClass = psiClass; aClass != null; aClass = aClass.getSuperClass()) {
final BuiltinComponent component = builtinComponents.get(aClass.getQualifiedName());
if (component != null) {
parentComponent = component;
break;
}
}
final String moduleName = getComponentModuleName(psiClass);
final Map<String, String> attributes = parentComponent != null ? parentComponent.getAttributes() : Collections.emptyMap();
customComponents.add(new CustomComponent(name, qualifiedName, moduleName, attributes));
}
}
return customComponents;
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class SceneBuilderImpl method collectCustomComponents.
private Collection<CustomComponent> collectCustomComponents() {
if (myProject.isDisposed()) {
return Collections.emptyList();
}
final PsiClass nodeClass = JavaPsiFacade.getInstance(myProject).findClass(JavaFxCommonNames.JAVAFX_SCENE_NODE, GlobalSearchScope.allScope(myProject));
if (nodeClass == null) {
return Collections.emptyList();
}
final Collection<PsiClass> psiClasses = CachedValuesManager.getCachedValue(nodeClass, () -> {
// Take custom components from libraries, but not from the project modules, because SceneBuilder instantiates the components' classes.
// Modules might be not compiled or may change since last compile, it's too expensive to keep track of that.
final GlobalSearchScope scope = ProjectScope.getLibrariesScope(nodeClass.getProject());
final String ideJdkVersion = Object.class.getPackage().getSpecificationVersion();
final LanguageLevel ideLanguageLevel = LanguageLevel.parse(ideJdkVersion);
final Query<PsiClass> query = ClassInheritorsSearch.search(nodeClass, scope, true, true, false);
final Set<PsiClass> result = new THashSet<>();
query.forEach(psiClass -> {
if (psiClass.hasModifierProperty(PsiModifier.PUBLIC) && !psiClass.hasModifierProperty(PsiModifier.ABSTRACT) && !isBuiltInComponent(psiClass) && isCompatibleLanguageLevel(psiClass, ideLanguageLevel)) {
result.add(psiClass);
}
});
return CachedValueProvider.Result.create(result, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
});
if (psiClasses.isEmpty()) {
return Collections.emptyList();
}
return prepareCustomComponents(psiClasses);
}
Aggregations