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 @@ -17,17 +17,18 @@
*/
@ExtensionImpl
public class AopHighlightErrorFilter extends HighlightErrorFilter {
@Override
public boolean shouldHighlightErrorElement(@Nonnull PsiErrorElement element) {
return !value(element);
}

public boolean shouldHighlightErrorElement(@Nonnull PsiErrorElement element) {
return !value(element);
}
public static boolean value(PsiErrorElement psiErrorElement) {
if (psiErrorElement.getContainingFile() instanceof AopPointcutExpressionFile pointcutExpressionFile) {
if (pointcutExpressionFile.getAopModel().getAdvisedElementsSearcher().shouldSuppressErrors()) {
return true;
}
}

public static boolean value(PsiErrorElement psiErrorElement) {
PsiFile file = psiErrorElement.getContainingFile();
if (file instanceof AopPointcutExpressionFile) {
if (((AopPointcutExpressionFile)file).getAopModel().getAdvisedElementsSearcher().shouldSuppressErrors()) return true;
return false;
}

return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved.
*/

package com.intellij.aop.jam;

import com.intellij.aop.AopIntroduction;
Expand All @@ -20,6 +19,7 @@
import com.intellij.jam.reflect.JamAttributeMeta;
import com.intellij.jam.reflect.JamStringAttributeMeta;
import com.intellij.java.language.psi.*;
import consulo.annotation.access.RequiredReadAction;
import consulo.language.psi.PsiElement;
import consulo.language.psi.PsiFile;
import consulo.language.psi.PsiManager;
Expand Down Expand Up @@ -49,49 +49,59 @@ public AopReferenceHolder fromString(@Nullable String s, JamStringAttributeEleme
@Nonnull
@JamAnnotation(AopConstants.DECLARE_PARENTS_ANNO)
@JamAttribute(AopConstants.DEFAULT_IMPL_PARAM)
@Override
public abstract JamClassAttributeElement getDefaultImpl();

@Override
public XmlTag getXmlTag() {
return null;
}

@Override
public Module getModule() {
return null;
}

@Override
public PsiAnnotation getIdentifyingPsiElement() {
return DECLARE_PARENTS_META.getAnnotation(getPsiElement());
}

@Override
public PsiFile getContainingFile() {
return getPsiElement().getContainingFile();
}

@Nonnull
@Override
public GenericValue<PsiClass> getImplementInterface() {
return new ReadOnlyGenericValue<PsiClass>() {
return new ReadOnlyGenericValue<>() {
@Override
public PsiClass getValue() {
PsiType type = getPsiElement().getType();
return type instanceof PsiClassType ? ((PsiClassType)type).resolve() : null;
}

@Override
public String getStringValue() {
return getPsiElement().getType().getCanonicalText();
}
};
}

@Nonnull
@Override
public GenericValue<AopReferenceHolder> getTypesMatching() {
return DECLARE_PARENTS_META.getAttribute(getPsiElement(), VALUE_META);
}

@Nullable
public static AopReferenceHolder getTypesMatchingPattern(@Nullable PsiElement value) {
PsiPointcutExpression expression = AopPointcutImpl.getPsiPointcutExpression(value);
return expression instanceof PsiTargetExpression ? ((PsiTargetExpression)expression).getTypeReference() : null;
return expression instanceof PsiTargetExpression target ? target.getTypeReference() : null;
}

@Override
public PsiManager getPsiManager() {
return getPsiElement().getManager();
}
Expand All @@ -100,6 +110,8 @@ public PsiManager getPsiManager() {
@JamPsiConnector
public abstract PsiField getPsiElement();

@Override
@RequiredReadAction
public boolean isValid() {
return getPsiElement().isValid();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
@ExtensionImpl
public class AopJamContributor extends SemContributor {
@Override
public void registerSemProviders(SemRegistrar registrar) {
AopAspectImpl.ASPECT_META.register(registrar, psiClass().withAnnotation(AopConstants.ASPECT_ANNO).andNot(psiElement().compiled()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,9 @@ public static NavigationGutterIconBuilder<PsiElement> addNavigationToIntercepted
final AopAdvisedElementsSearcher searcher) {
NavigationGutterIconBuilder<PsiElement> builder =
NavigationGutterIconBuilder.create(createFromIcon(advice.getAdviceType().getAdviceIcon()))
.setTargets(new NotNullLazyValue<Collection<? extends PsiElement>>() {
.setTargets(new NotNullLazyValue<>() {
@Nonnull
@Override
public Collection<? extends PsiElement> compute() {
if (!advice.isValid()) return Collections.emptyList();

Expand Down Expand Up @@ -398,7 +399,7 @@ public static Map<AopAdvice, Integer> getBoundAdvices(PsiClass psiClass) {
CachedValue<Map<AopAdvice, Integer>> value = psiClass.getUserData(BOUND_ADVICES_KEY);
if (value == null) {
psiClass.putUserData(BOUND_ADVICES_KEY, value = CachedValuesManager.getManager(psiClass.getProject()).createCachedValue(() -> {
Module module = psiClass.getModule();
Module module = psiClass.getModule();
if (module == null)
return CachedValueProvider.Result.create(Collections.<AopAdvice, Integer>emptyMap(),
PsiModificationTracker.MODIFICATION_COUNT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,27 @@
public class AopMetaData implements PsiMetaData {
private PsiAnnotation myAnnotation;

@Override
public PsiElement getDeclaration() {
return myAnnotation;
}

@NonNls
@Override
public String getName(PsiElement context) {
return getName();
}

@NonNls
@Override
public final String getName() {
return ((PsiMethod)myAnnotation.getParent().getParent()).getName();
}

@Override
public void init(PsiElement element) {
myAnnotation = (PsiAnnotation) element;
}

@Override
public Object[] getDependences() {
return new Object[]{myAnnotation};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ public AopModelImpl(@Nonnull consulo.module.Module module) {
myModule = module;
}

@Override
public List<AopAspectImpl> getAspects() {
return JamService.getJamService(myModule.getProject()).getJamClassElements(AopAspectImpl.ASPECT_META, AopConstants.ASPECT_ANNO, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(myModule));
}

@Override
public List<AopPointcutImpl> getPointcuts() {
return JamService.getJamService(myModule.getProject()).getJamMethodElements(AopPointcutImpl.POINTCUT_METHOD_META, AopConstants.POINTCUT_ANNO, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(myModule));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
public class AopModuleService implements Disposable {
private final NotNullLazyValue<AopModelImpl> myModel;
private static final AopModel EMPTY_AOP_MODEL = new AopModel() {
@Override
public List<? extends AopAspect> getAspects() {
return Collections.emptyList();
}

@Override
public List<? extends AopPointcut> getPointcuts() {
return Collections.emptyList();
}
Expand All @@ -55,8 +57,9 @@ public static AopModel getAopModel(@Nullable Module module) {

@Inject
public AopModuleService(final @Nonnull Module module) {
myModel = new NotNullLazyValue<AopModelImpl>() {
myModel = new NotNullLazyValue<>() {
@Nonnull
@Override
protected AopModelImpl compute() {
return new AopModelImpl(module);
}
Expand Down Expand Up @@ -88,6 +91,7 @@ public synchronized AopModelImpl getModel() {
return myModel.getValue();
}

@Override
public void dispose() {
}
}
17 changes: 14 additions & 3 deletions aop-common/src/main/java/com/intellij/aop/jam/AopPointcutImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.intellij.java.language.psi.PsiAnnotationMemberValue;
import com.intellij.java.language.psi.PsiBinaryExpression;
import com.intellij.java.language.psi.PsiMethod;
import consulo.annotation.access.RequiredReadAction;
import consulo.document.util.TextRange;
import consulo.language.inject.InjectedLanguageManager;
import consulo.language.psi.PsiElement;
Expand All @@ -37,10 +38,12 @@
*/
public abstract class AopPointcutImpl implements JamElement, AopPointcut, PointcutContainer {
private static final JamAnnotationMeta POINTCUT_META = new JamAnnotationMeta(AopConstants.POINTCUT_ANNO);
public static final JamMethodMeta<AopPointcutImpl> POINTCUT_METHOD_META = new JamMethodMeta<AopPointcutImpl>(AopPointcutImpl.class);
public static final JamMethodMeta<AopPointcutImpl> POINTCUT_METHOD_META = new JamMethodMeta<>(AopPointcutImpl.class);

private static final JamStringAttributeMeta.Single<String> ARG_NAMES_META = JamAttributeMeta.singleString("argNames");

@Override
@RequiredReadAction
public GenericValue<PsiPointcutExpression> getExpression() {
JamStringAttributeMeta.Single<PsiPointcutExpression> meta =
JamAttributeMeta.singleString("value", new JamConverter<PsiPointcutExpression>() {
Expand All @@ -52,32 +55,38 @@ public PsiPointcutExpression fromString(@Nullable String s, JamStringAttributeEl
return POINTCUT_META.getAttribute(getPsiElement(), meta);
}

@Override
public PsiElement getIdentifyingPsiElement() {
PsiAnnotation annotation = getAnnotation();
return annotation == null ? getPsiElement() : annotation;
}

@Override
public JamStringAttributeElement<String> getArgNames() {
return POINTCUT_META.getAttribute(getPsiElement(), ARG_NAMES_META);
}

@Override
public GenericValue<String> getQualifiedName() {
return ReadOnlyGenericValue.getInstance(getPsiElement().getContainingClass().getQualifiedName() + "." + getPsiElement().getName());
}

@Override
public int getParameterCount() {
return getPsiElement().getParameterList().getParametersCount();
}

@Nullable
@RequiredReadAction
protected PsiPointcutExpression getPointcutExpression(@Nullable PsiAnnotationMemberValue value) {
return getPsiPointcutExpression(value);
}

@Nullable
@RequiredReadAction
public static PsiPointcutExpression getPsiPointcutExpression(@Nullable PsiElement value) {
if (value instanceof PsiBinaryExpression) {
return getPsiPointcutExpression(((PsiBinaryExpression)value).getLOperand());
if (value instanceof PsiBinaryExpression binaryExpr) {
return getPsiPointcutExpression(binaryExpr.getLOperand());
}

if (value instanceof PsiLanguageInjectionHost) {
Expand All @@ -93,6 +102,7 @@ public static PsiPointcutExpression getPsiPointcutExpression(@Nullable PsiElemen
}

@Nullable
@Override
public PsiAnnotation getAnnotation() {
return POINTCUT_META.getAnnotation(getPsiElement());
}
Expand All @@ -105,6 +115,7 @@ public PsiManager getPsiManager() {
@JamPsiConnector
public abstract PsiMethod getPsiElement();

@RequiredReadAction
public boolean isValid() {
return getPsiElement().isValid();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import consulo.annotation.access.RequiredReadAction;
import consulo.annotation.component.ExtensionImpl;
import consulo.aop.localize.AopLocalize;
import consulo.application.util.function.Processor;
import consulo.document.util.TextRange;
import consulo.language.editor.inspection.ProblemHighlightType;
import consulo.language.editor.inspection.ProblemsHolder;
Expand All @@ -35,14 +34,14 @@
@ExtensionImpl
public class ArgNamesErrorsInspection extends AbstractArgNamesInspection {
@Nonnull
@Override
public HighlightDisplayLevel getDefaultLevel() {
return HighlightDisplayLevel.ERROR;
}

protected void checkAnnotation(
PsiParameter[] parameters, ProblemsHolder holder,
ArgNamesManipulator manipulator, PsiMethod method
) {
@Override
@RequiredReadAction
protected void checkAnnotation(PsiParameter[] parameters, ProblemsHolder holder, ArgNamesManipulator manipulator, PsiMethod method) {
String names = manipulator.getArgNames();
if (names != null) {
String[] strings = names.trim().split(",");
Expand Down Expand Up @@ -102,11 +101,8 @@ else if (psiElement instanceof PsiParameter) {

for (PsiParameter parameter : parameters) {
if (!LocalAopModel.isJoinPointParamer(parameter)) {
boolean hasRef = !ReferencesSearch.search(parameter).forEach(new Processor<PsiReference>() {
public boolean process(PsiReference reference) {
return !(reference.getElement().getContainingFile() instanceof AopPointcutExpressionFile);
}
});
boolean hasRef = !ReferencesSearch.search(parameter)
.forEach(reference -> !(reference.getElement().getContainingFile() instanceof AopPointcutExpressionFile));
if (!hasRef && !parameter.equals(manipulator.getReturningParameter()) && !parameter.equals(manipulator.getThrowingParameter())) {
holder.newProblem(AopLocalize.unboundPointcutParameter(parameter.getName()))
.range(manipulator.getArgNamesProblemElement())
Expand All @@ -127,13 +123,12 @@ private static void addAnnoReferenceProblem(ProblemsHolder holder, PsiReference
LocalizeValue message = ProblemsHolder.unresolvedReferenceMessage(returningReference);
ProblemHighlightType highlightType = emptyRange || !(element instanceof PsiLiteralExpression || element instanceof XmlElement)
? ProblemHighlightType.GENERIC_ERROR_OR_WARNING : ProblemHighlightType.LIKE_UNKNOWN_SYMBOL;
holder.registerProblem(InspectionManager.getInstance(element.getProject()).createProblemDescriptor(element, range, message.get(),
highlightType
));
holder.registerProblem(InspectionManager.getInstance(element.getProject())
.createProblemDescriptor(element, range, message.get(), highlightType));
}

public static List<String> getGeneralArgumentNames(PsiParameter[] parameters) {
List<String> actualNames = new ArrayList<String>();
List<String> actualNames = new ArrayList<>();
for (PsiParameter parameter : parameters) {
actualNames.add(parameter.getName());
}
Expand Down
Loading
Loading