Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
import com.intellij.jam.JamStringAttributeElement;
import com.intellij.java.language.psi.PsiAnnotationMemberValue;
import com.intellij.java.language.psi.PsiParameter;
import consulo.annotation.access.RequiredReadAction;
import consulo.language.psi.PsiElement;
import consulo.language.psi.PsiReference;
import consulo.language.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

Expand All @@ -30,39 +29,44 @@ public JavaArgNamesManipulator(@Nonnull PointcutContainer advice) {
}

@Nullable
@Override
public String getArgNames() {
return myContainer.getArgNames().getStringValue();
}

@Nonnull
@Override
@RequiredReadAction
public PsiElement getArgNamesProblemElement() {
PsiAnnotationMemberValue value = myContainer.getArgNames().getPsiElement();
return value == null ? getCommonProblemElement() : value;
}

@Nonnull
@Override
@RequiredReadAction
public PsiElement getCommonProblemElement() {
return myContainer.getAnnotation().getNameReferenceElement();
}

@Override
public PsiParameter getReturningParameter() {
return myContainer instanceof AopAfterReturningAdviceImpl ? ((AopAfterReturningAdviceImpl)myContainer).getReturning().getValue() : null;

return myContainer instanceof AopAfterReturningAdviceImpl afterReturningAdvice ? afterReturningAdvice.getReturning().getValue() : null;
}

@Override
public PsiParameter getThrowingParameter() {
return myContainer instanceof AopAfterThrowingAdviceImpl ? ((AopAfterThrowingAdviceImpl)myContainer).getThrowing().getValue() : null;
return myContainer instanceof AopAfterThrowingAdviceImpl afterThrowingAdvice ? afterThrowingAdvice.getThrowing().getValue() : null;
}

@Nonnull
@NonNls
@Override
public String getArgNamesAttributeName() {
return AopConstants.ARG_NAMES_PARAM;
}

@Nullable
@Override
public PsiReference getReturningReference() {
if (!(myContainer instanceof AopAfterReturningAdviceImpl)) return null;

Expand All @@ -72,19 +76,21 @@ public PsiReference getReturningReference() {
}

@Nullable
@Override
public PsiReference getThrowingReference() {
if (!(myContainer instanceof AopAfterThrowingAdviceImpl)) return null;

JamStringAttributeElement<PsiParameter> throwing = ((AopAfterThrowingAdviceImpl)myContainer).getThrowing();
PsiReference[] references = throwing.getConverter().createReferences(throwing);
return references.length == 0 ? null : references[0];

}

@Override
public AopAdviceType getAdviceType() {
return myContainer instanceof AopAdvice ? ((AopAdvice)myContainer).getAdviceType() : null;
return myContainer instanceof AopAdvice advice ? advice.getAdviceType() : null;
}

@Override
public void setArgNames(@Nullable String argNames) throws IncorrectOperationException
{
myContainer.getArgNames().setStringValue(argNames);
Expand Down
18 changes: 11 additions & 7 deletions aop-common/src/main/java/com/intellij/aop/LocalAopModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,34 @@
import com.intellij.aop.jam.AopModuleService;
import com.intellij.java.language.psi.PsiMethod;
import com.intellij.java.language.psi.PsiParameter;
import consulo.annotation.access.RequiredReadAction;
import consulo.application.util.NotNullLazyValue;
import consulo.language.psi.PsiElement;
import consulo.language.util.ModuleUtilCore;
import consulo.util.collection.ContainerUtil;
import consulo.util.collection.SmartList;
import org.jetbrains.annotations.NonNls;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

import java.util.List;

/**
* @author peter
*/
public class LocalAopModel implements AopModel {
private final NotNullLazyValue<AopModel> myDelegate = new NotNullLazyValue<AopModel>() {
private final NotNullLazyValue<AopModel> myDelegate = new NotNullLazyValue<>() {
@Nonnull
@Override
@RequiredReadAction
protected AopModel compute() {
return getAopModel();
}
};
private final AopAdvisedElementsSearcher myAdvisedElementsSearcher;


@RequiredReadAction
private AopModel getAopModel() {
return AopModuleService.getAopModel(myHost != null ? ModuleUtilCore.findModuleForPsiElement(myHost) : null);
return AopModuleService.getAopModel(myHost != null ? myHost.getModule() : null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off here — this line uses 6 spaces while the rest of the method body should be 4 (the file uses 2-space indentation). The myHost.getModule() switch itself is fine and matches the same ModuleUtilCore.findModuleForPsiElement(...)getModule() migration done in MissingAspectjAutoproxyInspection in this PR.

Suggested change
return AopModuleService.getAopModel(myHost != null ? myHost.getModule() : null);
return AopModuleService.getAopModel(myHost != null ? myHost.getModule() : null);

}

private final PsiMethod myMethod;
Expand All @@ -52,16 +54,18 @@ protected PsiElement getHost() {
return myHost;
}

@Override
public List<? extends AopAspect> getAspects() {
return myDelegate.getValue().getAspects();
}

@Override
public List<? extends AopPointcut> getPointcuts() {
return myDelegate.getValue().getPointcuts();
}

public List<AopIntroduction> getIntroductions() {
consulo.util.collection.SmartList<AopIntroduction> introductions = new SmartList<AopIntroduction>();
List<AopIntroduction> introductions = new SmartList<>();
for (AopAspect aspect : getAspects()) {
introductions.addAll(aspect.getIntroductions());
}
Expand All @@ -74,7 +78,7 @@ public PsiMethod getPointcutMethod() {
}

@Nonnull
public List<PsiParameter> resolveParameters(@Nonnull @NonNls String name) {
public List<PsiParameter> resolveParameters(@Nonnull String name) {
return ContainerUtil.createMaybeSingletonList(findParameter(name, getPointcutMethod()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public AopPsiTypePattern[] getParameters() {
return myParameters;
}

@Override
public boolean accepts(@Nonnull PsiType type) {
return accepts(type, false);
}
Expand Down Expand Up @@ -55,6 +56,7 @@ private boolean accepts(@Nonnull PsiType type, boolean allowWildcardAssignabilit
}

@Nonnull
@Override
public PointcutMatchDegree canBeAssignableFrom(@Nonnull PsiType type) {
if (accepts(type, true)) return PointcutMatchDegree.TRUE;
boolean maybe = false;
Expand All @@ -65,5 +67,4 @@ public PointcutMatchDegree canBeAssignableFrom(@Nonnull PsiType type) {
}
return maybe ? PointcutMatchDegree.MAYBE : PointcutMatchDegree.FALSE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package com.intellij.aop.psi;

import consulo.annotation.access.RequiredReadAction;
import consulo.language.ast.ASTNode;

import jakarta.annotation.Nonnull;
Expand All @@ -16,44 +17,54 @@
* @author peter
*/
public abstract class MethodPatternPointcut extends AopElementBase implements PsiPointcutExpression {
public MethodPatternPointcut(@Nonnull ASTNode node) {
super(node);
}

@Nullable
public AopReferenceHolder getReturnType() {
return findChildByClass(AopReferenceHolder.class);
}

@Nullable
public AopModifierList getModifierList() {
return findChildByClass(AopModifierList.class);
}

@Nullable
public AopMemberReferenceExpression getMethodReference() {
return findChildByClass(AopMemberReferenceExpression.class);
}

@Nullable
public AopParameterList getParameterList() {
return findChildByClass(AopParameterList.class);
}

@Nullable
public AopThrowsList getThrowsList() {
return findChildByClass(AopThrowsList.class);
}

@Nullable
public AopAnnotationHolder getAnnotationHolder() {
return findChildByClass(AopAnnotationHolder.class);
}

@Nonnull
public Collection<AopPsiTypePattern> getPatterns() {
AopMemberReferenceExpression methodReference = getMethodReference();
if (methodReference == null) return Arrays.asList(AopPsiTypePattern.FALSE);
return methodReference.getQualifierPatterns();
}
public MethodPatternPointcut(@Nonnull ASTNode node) {
super(node);
}

@Nullable
@RequiredReadAction
public AopReferenceHolder getReturnType() {
return findChildByClass(AopReferenceHolder.class);
}

@Nullable
@RequiredReadAction
public AopModifierList getModifierList() {
return findChildByClass(AopModifierList.class);
}

@Nullable
@RequiredReadAction
public AopMemberReferenceExpression getMethodReference() {
return findChildByClass(AopMemberReferenceExpression.class);
}

@Nullable
@RequiredReadAction
public AopParameterList getParameterList() {
return findChildByClass(AopParameterList.class);
}

@Nullable
@RequiredReadAction
public AopThrowsList getThrowsList() {
return findChildByClass(AopThrowsList.class);
}

@Nullable
@RequiredReadAction
public AopAnnotationHolder getAnnotationHolder() {
return findChildByClass(AopAnnotationHolder.class);
}

@Nonnull
@Override
@RequiredReadAction
public Collection<AopPsiTypePattern> getPatterns() {
AopMemberReferenceExpression methodReference = getMethodReference();
if (methodReference == null) {
return Arrays.asList(AopPsiTypePattern.FALSE);
}
return methodReference.getQualifierPatterns();
}
}
Loading
Loading