Skip to content

Commit

Permalink
Fixed wrong attributes names
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneDev6 committed Sep 6, 2021
1 parent 38f8588 commit 8ed9078
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
11 changes: 11 additions & 0 deletions src/main/java/asteroids/Expensive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package asteroids;

/**
* Expensive method invocation
*/
public @interface Expensive
{
boolean singleCall() default true;
boolean calledInLoop() default true;
boolean calledInLambda() default true;
}
32 changes: 16 additions & 16 deletions src/main/kotlin/devs/beer/asteroids/ExpensiveApiUsageInspection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import javax.swing.JPanel

enum class MsgType {
SINGLE_CALL,
LOOPS,
LOOP,
LAMBDA
}

Expand Down Expand Up @@ -147,11 +147,11 @@ private class ExpensiveApiUsageProcessor(
val messageProvider = getMessageProvider(annotatedContainingDeclaration.psiAnnotation) ?: return false
val elementToHighlight = getElementToHighlight(sourceNode) ?: return false

val singleCall = getAnnotationBooleanAttributeValue(annotatedContainingDeclaration, "generic", true);
val calledInLoops = getAnnotationBooleanAttributeValue(annotatedContainingDeclaration, "calledInLoops", true)
val calledInLambdas = getAnnotationBooleanAttributeValue(annotatedContainingDeclaration, "calledInLambdas", true)
val singleCall = getAnnotationBooleanAttributeValue(annotatedContainingDeclaration, "singleCall", true);
val calledInLoop = getAnnotationBooleanAttributeValue(annotatedContainingDeclaration, "calledInLoop", true)
val calledInLambda = getAnnotationBooleanAttributeValue(annotatedContainingDeclaration, "calledInLambda", true)

if(calledInLoops == true)
if(calledInLoop == true)
{
for (parent in elementToHighlight.parents) {
if(parent is PsiForStatement
Expand All @@ -161,24 +161,24 @@ private class ExpensiveApiUsageProcessor(
{
return registerProblem(
elementToHighlight,
messageProvider.highlightTypeLoops,
messageProvider.highlightTypeLoop,
isMethodOverriding,
messageProvider,
annotatedContainingDeclaration,
MsgType.LOOPS
MsgType.LOOP
)
}
}
}

if(calledInLambdas == true)
if(calledInLambda == true)
{
for (parent in elementToHighlight.parents) {
if(parent is PsiLambdaExpression)
{
return registerProblem(
elementToHighlight,
messageProvider.highlightTypeLambdas,
messageProvider.highlightTypeLambda,
isMethodOverriding,
messageProvider,
annotatedContainingDeclaration,
Expand All @@ -196,7 +196,7 @@ private class ExpensiveApiUsageProcessor(
messageProvider,
annotatedContainingDeclaration,
MsgType.SINGLE_CALL
);
)
}
return false
}
Expand Down Expand Up @@ -256,8 +256,8 @@ private class ExpensiveApiUsageProcessor(
private interface ExpensiveApiUsageMessageProvider {

val highlightTypeSingleCall: ProblemHighlightType
val highlightTypeLoops: ProblemHighlightType
val highlightTypeLambdas: ProblemHighlightType
val highlightTypeLoop: ProblemHighlightType
val highlightTypeLambda: ProblemHighlightType

fun buildMessageExpensiveMethodOverridden(
annotatedContainingDeclaration: AnnotatedContainingDeclaration,
Expand All @@ -280,10 +280,10 @@ private object DefaultExpensiveApiUsageMessageProvider : ExpensiveApiUsageMessag
override val highlightTypeSingleCall
get() = ProblemHighlightType.WEAK_WARNING

override val highlightTypeLoops
override val highlightTypeLoop
get() = ProblemHighlightType.GENERIC_ERROR_OR_WARNING

override val highlightTypeLambdas
override val highlightTypeLambda
get() = ProblemHighlightType.GENERIC_ERROR_OR_WARNING

override fun buildMessageExpensiveMethodOverridden(
Expand All @@ -293,7 +293,7 @@ private object DefaultExpensiveApiUsageMessageProvider : ExpensiveApiUsageMessag
with(annotatedContainingDeclaration) {
if (isOwnAnnotation) {
when (msgType) {
MsgType.LOOPS -> {
MsgType.LOOP -> {
AnnotationsOnSteroidsBundle.message(
"jvm.inspections.expensive.api.usage.overridden.method.is.marked.expensive.itself.called_in_loops",
targetName,
Expand Down Expand Up @@ -335,7 +335,7 @@ private object DefaultExpensiveApiUsageMessageProvider : ExpensiveApiUsageMessag
if (isOwnAnnotation) {
when(msgType)
{
MsgType.LOOPS -> {
MsgType.LOOP -> {
AnnotationsOnSteroidsBundle.message(
"jvm.inspections.expensive.api.usage.api.is.marked.expensive.itself.called_in_loops",
targetName,
Expand Down

0 comments on commit 8ed9078

Please sign in to comment.