Search in sources :

Example 6 with PsiJavaCodeReferenceElement

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()]);
}
Also used : ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) PsiClass(com.intellij.psi.PsiClass) LinkedList(java.util.LinkedList) PsiAnnotationMemberValue(com.intellij.psi.PsiAnnotationMemberValue)

Example 7 with PsiJavaCodeReferenceElement

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);
}
Also used : PsiImportStatementStub(com.intellij.psi.impl.java.stubs.PsiImportStatementStub) PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement)

Example 8 with PsiJavaCodeReferenceElement

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;
}
Also used : PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) PsiJavaCodeReferenceElementImpl(com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with PsiJavaCodeReferenceElement

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;
}
Also used : PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with PsiJavaCodeReferenceElement

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);
    });
}
Also used : PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) PsiClass(com.intellij.psi.PsiClass) IncorrectOperationException(com.intellij.util.IncorrectOperationException) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Aggregations

PsiJavaCodeReferenceElement (com.intellij.psi.PsiJavaCodeReferenceElement)14 PsiClass (com.intellij.psi.PsiClass)7 PsiElement (com.intellij.psi.PsiElement)4 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)3 PsiAnnotationMemberValue (com.intellij.psi.PsiAnnotationMemberValue)3 LinkedList (java.util.LinkedList)3 Nullable (org.jetbrains.annotations.Nullable)3 Project (com.intellij.openapi.project.Project)2 PsiAnnotation (com.intellij.psi.PsiAnnotation)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 PsiClassType (com.intellij.psi.PsiClassType)1 PsiImportStaticStatement (com.intellij.psi.PsiImportStaticStatement)1 PsiJavaFile (com.intellij.psi.PsiJavaFile)1 PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)1 PsiImportStatementStub (com.intellij.psi.impl.java.stubs.PsiImportStatementStub)1 LightClassReference (com.intellij.psi.impl.light.LightClassReference)1 PsiJavaCodeReferenceElementImpl (com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl)1