-
Notifications
You must be signed in to change notification settings - Fork 745
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
Moe Sync #1023
Merged
Merged
Moe Sync #1023
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9f94242
Improve error handling in compilesWithFix
cushon 97f316e
Call out UncheckedIOException as a java8 addition
nick-someone 342d17c
Make SuggestedFixes.removeModifiers remove all modifiers specified, n…
awturner 65efe1e
Make the opensource filegroup depend on compiled proto jars so we don…
epmjohnston b1f0436
Update documentation around CheckReturnValueIgnored
nick-someone d2a0a39
Add fix suggestions to UngroupedOverloads summary
epmjohnston e00f68e
Internal change to the documentation generator
nick-someone 1684e4c
Make ByteBufferBackingArray documentation of restrictions clearer
epmjohnston b86e2f5
Add support for detecting type annotations across compilation boundaries
cushon 2f24601
SuggestedFixes: make addModifiers and removeModifiers emit whitespace…
awturner b1ba43d
Handle empty replacement ranges correctly in Replacements.overlap
awturner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
check_api/src/main/java/com/google/errorprone/util/MoreAnnotations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright 2012 The Error Prone Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.errorprone.util; | ||
|
||
import com.google.common.collect.Streams; | ||
import com.sun.tools.javac.code.Attribute; | ||
import com.sun.tools.javac.code.Symbol; | ||
import com.sun.tools.javac.code.Symbol.MethodSymbol; | ||
import com.sun.tools.javac.code.TargetType; | ||
import com.sun.tools.javac.code.TypeAnnotationPosition; | ||
import java.util.stream.Stream; | ||
|
||
/** Annotation-related utilities. */ | ||
public final class MoreAnnotations { | ||
|
||
/** | ||
* Returns declaration annotations of the given symbol, as well as 'top-level' type annotations, | ||
* including : | ||
* | ||
* <ul> | ||
* <li>Type annotations of the return type of a method. | ||
* <li>Type annotations on the type of a formal parameter or field. | ||
* </ul> | ||
* | ||
* <p>One might expect this to be equivalent to information returned by {@link | ||
* com.sun.tools.javac.code.Type#getAnnotationMirrors}, but javac doesn't associate type | ||
* annotation information with types for symbols completed from class files, so that approach | ||
* doesn't work across compilation boundaries. | ||
*/ | ||
public static Stream<Attribute.Compound> getDeclarationAndTypeAttributes(Symbol sym) { | ||
Symbol typeAnnotationOwner; | ||
switch (sym.getKind()) { | ||
case PARAMETER: | ||
typeAnnotationOwner = sym.owner; | ||
break; | ||
default: | ||
typeAnnotationOwner = sym; | ||
} | ||
return Streams.concat( | ||
sym.getRawAttributes().stream(), | ||
typeAnnotationOwner | ||
.getRawTypeAttributes() | ||
.stream() | ||
.filter(anno -> isAnnotationOnType(sym, anno.position))); | ||
} | ||
|
||
private static boolean isAnnotationOnType(Symbol sym, TypeAnnotationPosition position) { | ||
if (!position.location.isEmpty()) { | ||
return false; | ||
} | ||
switch (sym.getKind()) { | ||
case LOCAL_VARIABLE: | ||
return position.type == TargetType.LOCAL_VARIABLE; | ||
case FIELD: | ||
return position.type == TargetType.FIELD; | ||
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; | ||
default: | ||
return false; | ||
} | ||
default: | ||
throw new AssertionError(sym.getKind()); | ||
} | ||
} | ||
|
||
private MoreAnnotations() {} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😆 Thanks @cushon!