Skip to content

Commit 4f8527d

Browse files
committed
fix or silence generics warnings
First I fixed all warnings that could be fixed by adding generic type arguments. Only afterwards I silenced the remaining warnings (basically in all the AST visit() methods which operate with the non generic JDT API).
1 parent 4bddb65 commit 4f8527d

28 files changed

+132
-107
lines changed

net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/meta/MetadataFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,9 @@ private static void processProperties(Element moduleElement, RuleMetadata module
555555
property.getPropertyEnumeration().addAll(provider.getOptions());
556556
} else if (Enum.class.isAssignableFrom(providerClass)) {
557557

558+
@SuppressWarnings("rawtypes")
558559
EnumSet<?> values = EnumSet.allOf((Class<Enum>) providerClass);
559-
for (Enum e : values) {
560+
for (Enum<?> e : values) {
560561
property.getPropertyEnumeration().add(e.name().toLowerCase());
561562
}
562563
}

net.sf.eclipsecs.sample/src/net/sf/eclipsecs/sample/checks/MethodLimitQuickfix.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo,
2020

2121
return new ASTVisitor() {
2222

23+
@SuppressWarnings("unchecked")
2324
public boolean visit(MethodDeclaration node) {
2425

2526
Javadoc doc = node.getJavadoc();

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/CheckConfigurationConfigureDialog.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ private void newModule(ISelection selection) {
675675
boolean openOnAdd = CheckstyleUIPluginPrefs
676676
.getBoolean(CheckstyleUIPluginPrefs.PREF_OPEN_MODULE_EDITOR);
677677

678-
Iterator it = ((IStructuredSelection) selection).iterator();
678+
Iterator<?> it = ((IStructuredSelection) selection).iterator();
679679
while (it.hasNext()) {
680680
Object selectedElement = it.next();
681681
if (selectedElement instanceof RuleGroupMetadata) {
@@ -736,6 +736,7 @@ private void removeModule(ISelection selection) {
736736
Messages.CheckConfigurationConfigureDialog_titleRemoveModules,
737737
Messages.CheckConfigurationConfigureDialog_msgRemoveModules)) {
738738

739+
@SuppressWarnings("unchecked")
739740
Iterator<Module> it = ((IStructuredSelection) selection).iterator();
740741
while (it.hasNext()) {
741742
Module m = it.next();
@@ -806,7 +807,7 @@ private class MetaDataContentProvider implements ITreeContentProvider {
806807
public Object[] getElements(Object inputElement) {
807808
Object[] ruleGroups = null;
808809
if (inputElement instanceof List) {
809-
ruleGroups = ((List) inputElement).toArray();
810+
ruleGroups = ((List<?>) inputElement).toArray();
810811
}
811812
return ruleGroups;
812813
}
@@ -993,7 +994,7 @@ public String getColumnText(Object element, int columnIndex) {
993994
* {@inheritDoc}
994995
*/
995996
@Override
996-
public Comparable getComparableValue(Object element, int col) {
997+
public Comparable<?> getComparableValue(Object element, int col) {
997998
if (element instanceof Module && col == 0) {
998999
return Severity.ignore.equals(((Module) element).getSeverity()) ? new Integer(0)
9991000
: new Integer(1);

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/FixCheckstyleMarkersAction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public void run(IAction action) {
7777

7878
Object element = selection.getFirstElement();
7979

80+
@SuppressWarnings("cast")
8081
IFile file = (IFile) ((IAdaptable) element).getAdapter(IFile.class);
8182
if (file != null) {
8283

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/blocks/AvoidNestedBlocksQuickfix.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,23 @@ protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo,
4949

5050
return new ASTVisitor() {
5151

52+
@SuppressWarnings("unchecked")
5253
@Override
5354
public boolean visit(Block node) {
5455

5556
if (containsPosition(lineInfo, node.getStartPosition())) {
5657

5758
if (node.getParent() instanceof Block) {
5859

59-
List statements = ((Block) node.getParent()).statements();
60+
List<?> statements = ((Block) node.getParent()).statements();
6061
int index = statements.indexOf(node);
6162

6263
statements.remove(node);
6364
statements.addAll(index, ASTNode.copySubtrees(node.getAST(), node.statements()));
6465

6566
} else if (node.getParent() instanceof SwitchStatement) {
6667

67-
List statements = ((SwitchStatement) node.getParent()).statements();
68+
List<?> statements = ((SwitchStatement) node.getParent()).statements();
6869
int index = statements.indexOf(node);
6970

7071
statements.remove(node);

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/blocks/NeedBracesQuickfix.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ private void bracifyIfStatement(IfStatement ifStatement) {
133133
}
134134
}
135135

136+
@SuppressWarnings("unchecked")
136137
private Block createBracifiedCopy(AST ast, Statement body) {
137138
Block block = ast.newBlock();
138139
block.statements().add(ASTNode.copySubtree(block.getAST(), body));

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/coding/DefaultComesLastQuickfix.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo,
5151

5252
return new ASTVisitor() {
5353

54+
@SuppressWarnings("unchecked")
5455
@Override
5556
public boolean visit(SwitchCase node) {
5657

@@ -59,7 +60,7 @@ public boolean visit(SwitchCase node) {
5960
if (node.isDefault() && !isLastSwitchCase(node)) {
6061
SwitchStatement switchStatement = (SwitchStatement) node.getParent();
6162

62-
List defaultCaseStatements = new ArrayList();
63+
List<ASTNode> defaultCaseStatements = new ArrayList<>();
6364
defaultCaseStatements.add(node);
6465

6566
// collect all statements belonging to the default case

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/coding/FinalLocalVariableQuickfix.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo,
4949
final int markerStartOffset) {
5050
return new ASTVisitor() {
5151

52+
@SuppressWarnings("unchecked")
5253
@Override
5354
public boolean visit(SingleVariableDeclaration node) {
5455
if (containsPosition(node, markerStartOffset) && !Modifier.isFinal(node.getModifiers())) {
@@ -60,6 +61,7 @@ public boolean visit(SingleVariableDeclaration node) {
6061
return true;
6162
}
6263

64+
@SuppressWarnings("unchecked")
6365
@Override
6466
public boolean visit(VariableDeclarationStatement node) {
6567
if (containsPosition(node, markerStartOffset) && !Modifier.isFinal(node.getModifiers())) {

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/coding/MissingSwitchDefaultQuickfix.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo,
4747

4848
return new ASTVisitor() {
4949

50+
@SuppressWarnings("unchecked")
5051
@Override
5152
public boolean visit(SwitchStatement node) {
5253
if (containsPosition(lineInfo, node.getStartPosition())) {

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/coding/StringLiteralEqualityQuickfix.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo,
5656

5757
return new ASTVisitor() {
5858

59+
@SuppressWarnings("unchecked")
5960
@Override
6061
public boolean visit(InfixExpression node) {
6162

@@ -117,7 +118,7 @@ private void replaceNode(ASTNode node, ASTNode replacementNode) {
117118
+ property.substring(1);
118119
String setterMethodName = "set" + capitalizedProperty;
119120

120-
Class testClass = node.getClass();
121+
Class<?> testClass = node.getClass();
121122

122123
while (testClass != null) {
123124

@@ -134,7 +135,8 @@ private void replaceNode(ASTNode node, ASTNode replacementNode) {
134135
} else if (node.getLocationInParent().isChildListProperty()) {
135136
Method listMethod = node.getParent().getClass()
136137
.getMethod(node.getLocationInParent().getId(), (Class<?>[]) null);
137-
List list = (List) listMethod.invoke(node.getParent(), (Object[]) null);
138+
@SuppressWarnings("unchecked")
139+
List<ASTNode> list = (List<ASTNode>) listMethod.invoke(node.getParent(), (Object[]) null);
138140
list.set(list.indexOf(node), replacementNode);
139141
}
140142
} catch (InvocationTargetException e) {

0 commit comments

Comments
 (0)