use of com.intellij.psi.PsiJavaCodeReferenceElement in project qi4j-sdk by Qi4j.
the class MixinImplementsMixinType method checkClass.
@Override
public final ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
// If psiClass is not an interface, ignore
if (!psiClass.isInterface()) {
return null;
}
// If @Mixins annotation is empty, ignore
List<PsiAnnotationMemberValue> mixinAnnotationValues = getMixinsAnnotationValue(psiClass);
if (mixinAnnotationValues.isEmpty()) {
return null;
}
// Get all valid mixin type
Set<PsiClass> validMixinsType = getAllValidMixinTypes(psiClass);
if (validMixinsType.isEmpty()) {
return null;
}
// For each mixin
List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
for (PsiAnnotationMemberValue mixinAnnotationValue : mixinAnnotationValues) {
PsiJavaCodeReferenceElement mixinClassReference = getMixinClassReference(mixinAnnotationValue);
// If it's not a class reference, ignore
if (mixinClassReference == null) {
continue;
}
// If class reference can't be resolved, ignore
PsiClass mixinClass = (PsiClass) mixinClassReference.resolve();
if (mixinClass == null) {
continue;
}
String mixinQualifiedName = mixinClass.getQualifiedName();
boolean isMixinsDeclarationValid = false;
String message = "";
if (mixinClass.isInterface()) {
// Mixin can't be an interface
message = message("mixin.implements.mixin.type.error.mixin.is.an.interface", mixinQualifiedName);
} else if (isAConcern(mixinClass)) {
// Mixin can't be a concern
message = message("mixin.implements.mixin.type.error.mixin.is.a.concern", mixinQualifiedName);
} else if (isASideEffect(mixinClass)) {
// Mixin can't be a side effect
message = message("mixin.implements.mixin.type.error.mixin.is.a.side.effect", mixinQualifiedName);
} else {
// If doesn't implement any mixin type, it's a problem
if (!isImplementValidMixinType(mixinClass, validMixinsType)) {
message = message("mixin.implements.mixin.type.error.does.not.implement.any.mixin.type", mixinQualifiedName, psiClass.getQualifiedName());
} else {
isMixinsDeclarationValid = true;
}
}
if (!isMixinsDeclarationValid) {
ProblemDescriptor problemDescriptor = createProblemDescriptor(manager, mixinAnnotationValue, mixinClassReference, message);
problems.add(problemDescriptor);
}
}
return problems.toArray(new ProblemDescriptor[problems.size()]);
}
use of com.intellij.psi.PsiJavaCodeReferenceElement in project intellij-community by JetBrains.
the class PsiImportStatementBaseImpl method getImportReference.
@Override
public PsiJavaCodeReferenceElement getImportReference() {
PsiUtilCore.ensureValid(this);
final PsiImportStatementStub stub = getStub();
if (stub != null) {
return stub.getReference();
}
return (PsiJavaCodeReferenceElement) calcTreeElement().findChildByRoleAsPsiElement(ChildRole.IMPORT_REFERENCE);
}
use of com.intellij.psi.PsiJavaCodeReferenceElement in project intellij-community by JetBrains.
the class PsiImportStatementStubImpl method getRegularReference.
@Nullable
private PsiJavaCodeReferenceElement getRegularReference() {
final PsiJavaCodeReferenceElement refElement = createReference();
if (refElement == null)
return null;
((PsiJavaCodeReferenceElementImpl) refElement).setKindWhenDummy(isOnDemand() ? PsiJavaCodeReferenceElementImpl.CLASS_FQ_OR_PACKAGE_NAME_KIND : PsiJavaCodeReferenceElementImpl.CLASS_FQ_NAME_KIND);
return refElement;
}
use of com.intellij.psi.PsiJavaCodeReferenceElement in project intellij-community by JetBrains.
the class PsiImportStatementStubImpl method getReference.
@Override
@Nullable
public PsiJavaCodeReferenceElement getReference() {
PsiJavaCodeReferenceElement ref = SoftReference.dereference(myReference);
if (ref == null) {
ref = isStatic() ? getStaticReference() : getRegularReference();
myReference = new SoftReference<>(ref);
}
return ref;
}
use of com.intellij.psi.PsiJavaCodeReferenceElement in project intellij-community by JetBrains.
the class CreateClassFromUsageFix method invoke.
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) {
PsiDocumentManager.getInstance(project).commitAllDocuments();
final PsiJavaCodeReferenceElement element = getRefElement();
if (element == null)
return;
if (!FileModificationService.getInstance().preparePsiElementForWrite(element))
return;
final String superClassName = getSuperClassName(element);
final PsiClass aClass = CreateFromUsageUtils.createClass(element, myKind, superClassName);
if (aClass == null)
return;
ApplicationManager.getApplication().runWriteAction(() -> {
PsiJavaCodeReferenceElement refElement = element;
try {
refElement = (PsiJavaCodeReferenceElement) refElement.bindToElement(aClass);
} catch (IncorrectOperationException e) {
LOG.error(e);
}
IdeDocumentHistory.getInstance(project).includeCurrentPlaceAsChangePlace();
OpenFileDescriptor descriptor = new OpenFileDescriptor(refElement.getProject(), aClass.getContainingFile().getVirtualFile(), aClass.getTextOffset());
FileEditorManager.getInstance(aClass.getProject()).openTextEditor(descriptor, true);
});
}
Aggregations