Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A couple of fixes in MoreAnnotations #4620

Closed
wants to merge 3 commits into from
Closed
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 @@ -30,6 +30,8 @@
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.TypeAnnotationPosition;
import com.sun.tools.javac.code.TypeTag;
import com.sun.tools.javac.tree.JCTree;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -130,15 +132,24 @@ private static boolean targetTypeMatches(Symbol sym, TypeAnnotationPosition posi
case LOCAL_VARIABLE:
return position.type == TargetType.LOCAL_VARIABLE;
case FIELD:
// treated like a field
case ENUM_CONSTANT:
return position.type == TargetType.FIELD;
case CONSTRUCTOR:
case METHOD:
return position.type == TargetType.METHOD_RETURN;
case PARAMETER:
switch (position.type) {
case METHOD_FORMAL_PARAMETER:
return ((MethodSymbol) sym.owner).getParameters().indexOf(sym)
== position.parameter_index;
int parameterIndex = position.parameter_index;
if (position.onLambda != null) {
com.sun.tools.javac.util.List<JCTree.JCVariableDecl> lambdaParams =
position.onLambda.params;
return parameterIndex < lambdaParams.size()
&& lambdaParams.get(parameterIndex).sym.equals(sym);
} else {
return ((Symbol.MethodSymbol) sym.owner).getParameters().indexOf(sym) == parameterIndex;
}
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,29 @@ class InnerStatic {}
""")
.doTest();
}

@Test
public void explicitlyAnnotatedLambdaTest() {
CompilationTestHelper.newInstance(GetTopLevelTypeAttributesTester.class, getClass())
.addSourceLines(
"Annos.java",
"""
import static java.lang.annotation.ElementType.TYPE_USE;
import java.lang.annotation.Target;
@Target(TYPE_USE) @interface A {}
""")
.addSourceLines(
"Test.java",
"""
import java.util.function.Consumer;
class Test {
Consumer<@A String> c;
void test() {
// BUG: Diagnostic contains: A
c = (@A String s) -> {};
}
}
""")
.doTest();
}
}