use of org.eclipse.jdt.core.dom.rewrite.ImportRewrite.TypeLocation in project eclipse.jdt.ls by eclipse.
the class RedundantNullnessTypeAnnotationsFilter method createIfConfigured.
public static /* @Nullable */
RedundantNullnessTypeAnnotationsFilter createIfConfigured(/* @Nullable */
ASTNode node) {
if (node == null) {
return null;
}
final ASTNode root = node.getRoot();
if (root instanceof CompilationUnit) {
CompilationUnit compilationUnit = (CompilationUnit) root;
IJavaElement javaElement = compilationUnit.getJavaElement();
IJavaProject javaProject = javaElement == null ? null : javaElement.getJavaProject();
if (javaProject != null) {
if (JavaCore.ENABLED.equals(javaProject.getOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, true))) {
String nonNullAnnotationName = javaProject.getOption(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, true);
String nullableAnnotationName = javaProject.getOption(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, true);
String nonNullByDefaultName = javaProject.getOption(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, true);
if (nonNullAnnotationName == null || nullableAnnotationName == null || nonNullByDefaultName == null) {
return null;
}
EnumSet<TypeLocation> nonNullByDefaultLocations = determineNonNullByDefaultLocations(node, nonNullByDefaultName);
return new RedundantNullnessTypeAnnotationsFilter(nonNullAnnotationName, nullableAnnotationName, nonNullByDefaultLocations);
}
}
}
return null;
}
use of org.eclipse.jdt.core.dom.rewrite.ImportRewrite.TypeLocation in project eclipse.jdt.ls by eclipse.
the class RedundantNullnessTypeAnnotationsFilter method determineNNBDValue.
private static EnumSet<TypeLocation> determineNNBDValue(IAnnotationBinding annot) {
EnumSet<TypeLocation> result = EnumSet.noneOf(TypeLocation.class);
IMemberValuePairBinding[] pairs = annot.getAllMemberValuePairs();
for (final IMemberValuePairBinding pair : pairs) {
if (pair.getKey() == null || pair.getKey().equals("value")) {
// $NON-NLS-1$
Object value = pair.getValue();
if (value instanceof Object[]) {
Object[] values = (Object[]) value;
for (int k = 0; k < values.length; k++) {
if (values[k] instanceof IVariableBinding) {
String name = ((IVariableBinding) values[k]).getName();
try {
result.add(TypeLocation.valueOf(name));
} catch (IllegalArgumentException e) {
// ignore
}
}
}
} else if (value instanceof IVariableBinding) {
String name = ((IVariableBinding) value).getName();
try {
result.add(TypeLocation.valueOf(name));
} catch (IllegalArgumentException e) {
// ignore
}
}
}
}
return result;
}
Aggregations