Skip to content

Commit

Permalink
remove unnecessary casts (#1473)
Browse files Browse the repository at this point in the history
* remove unnecessary casts
* version bumps
  • Loading branch information
stephan-herrmann authored Jun 21, 2024
1 parent 909a26b commit 690340f
Show file tree
Hide file tree
Showing 47 changed files with 60 additions and 72 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.jdt.astview.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.eclipse.jdt.astview.feature"
label="Java AST View"
version="1.2.250.qualifier"
version="1.2.300.qualifier"
provider-name="Eclipse.org"
license-feature="org.eclipse.license"
license-feature-version="0.0.0">
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.astview/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.astview
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.astview; singleton:=true
Bundle-Version: 1.6.150.qualifier
Bundle-Version: 1.6.200.qualifier
Bundle-Activator: org.eclipse.jdt.astview.ASTViewPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public String getText(Object obj) {
} else if (obj instanceof ASTAttribute) {
return ((ASTAttribute) obj).getLabel();
} else if (obj instanceof ASTNode) {
return Signature.getSimpleName(((ASTNode) obj).getClass().getName());
return Signature.getSimpleName(obj.getClass().getName());
} else {
return ""; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=126017
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private void possibleStaticImportFound(Name name) {
private void doVisitChildren(List<? extends ASTNode> elements) {
int nElements= elements.size();
for (int i= 0; i < nElements; i++) {
((ASTNode) elements.get(i)).accept(this);
elements.get(i).accept(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static IResource getResource(Object o){
*/
public static IResource getResource(IJavaElement element){
if (element.getElementType() == IJavaElement.COMPILATION_UNIT)
return ((ICompilationUnit) element).getResource();
return element.getResource();
else if (element instanceof IOpenable)
return element.getResource();
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private static ITypeBinding getPossibleReferenceBinding(ASTNode node) {
}
}
if (creationType instanceof ArrayType) {
ITypeBinding creationTypeBinding= ((ArrayType) creationType).resolveBinding();
ITypeBinding creationTypeBinding= creationType.resolveBinding();
if (creationTypeBinding != null) {
return Bindings.getComponentType(creationTypeBinding, dim);
}
Expand Down Expand Up @@ -883,7 +883,7 @@ public static boolean isInStaticContext(ASTNode selectedNode) {
}
return Modifier.isStatic(decl.getModifiers());
} else if (decl instanceof Initializer) {
return Modifier.isStatic(((Initializer)decl).getModifiers());
return Modifier.isStatic(decl.getModifiers());
} else if (decl instanceof FieldDeclaration) {
return JdtFlags.isStatic(decl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private void handleResourceDeclarations(TryStatement tryStatement) {
if (variable instanceof VariableDeclarationExpression) {
typeBinding= ((VariableDeclarationExpression) variable).getType().resolveBinding();
} else if (variable instanceof Name) {
typeBinding= ((Name) variable).resolveTypeBinding();
typeBinding= variable.resolveTypeBinding();
}
if (typeBinding != null) {
IMethodBinding methodBinding= Bindings.findMethodInHierarchy(typeBinding, "close", new ITypeBinding[0]); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public boolean visit(TryStatement node) {
if (variable instanceof VariableDeclarationExpression) {
typeBinding= ((VariableDeclarationExpression) variable).getType().resolveBinding();
} else if (variable instanceof Name) {
typeBinding= ((Name) variable).resolveTypeBinding();
typeBinding= variable.resolveTypeBinding();
}
if (typeBinding != null) {
IMethodBinding methodBinding= Bindings.findMethodInHierarchy(typeBinding, "close", new ITypeBinding[0]); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private static boolean isStaticImport(ASTNode node) {
if (!(node instanceof QualifiedName))
return false;

ASTNode parent= ((QualifiedName)node).getParent();
ASTNode parent= node.getParent();
return parent instanceof ImportDeclaration && ((ImportDeclaration) parent).isStatic();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.eclipse.jdt.core.dom.PackageDeclaration;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.TypeLocation;

Expand Down Expand Up @@ -262,7 +261,7 @@ private static void addElementTypesAsTypeLocationValues(EnumSet<TypeLocation> re
extendsMods= ((SingleVariableDeclaration) astNode).modifiers();
break;
case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
final ASTNode parent= ((VariableDeclarationFragment) astNode).getParent();
final ASTNode parent= astNode.getParent();
if (parent instanceof BodyDeclaration)
extendsMods= ((BodyDeclaration) parent).modifiers();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ public static Type getType(VariableDeclaration declaration) {
if (declaration instanceof SingleVariableDeclaration) {
return ((SingleVariableDeclaration)declaration).getType();
} else if (declaration instanceof VariableDeclarationFragment) {
ASTNode parent= ((VariableDeclarationFragment)declaration).getParent();
ASTNode parent= declaration.getParent();
if (parent instanceof VariableDeclarationExpression)
return ((VariableDeclarationExpression)parent).getType();
else if (parent instanceof VariableDeclarationStatement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,15 @@ private boolean isPrimitiveAllowed(final ASTNode node) {

if (assignment.getRightHandSide().equals(node)) {
if (assignment.getLeftHandSide() instanceof Name) {
return isOfType(((Name) assignment.getLeftHandSide()).resolveTypeBinding());
return isOfType(assignment.getLeftHandSide().resolveTypeBinding());
}

if (assignment.getLeftHandSide() instanceof FieldAccess) {
return isOfType(((FieldAccess) assignment.getLeftHandSide()).resolveTypeBinding());
return isOfType(assignment.getLeftHandSide().resolveTypeBinding());
}

if (assignment.getLeftHandSide() instanceof SuperFieldAccess) {
return isOfType(((SuperFieldAccess) assignment.getLeftHandSide()).resolveTypeBinding());
return isOfType(assignment.getLeftHandSide().resolveTypeBinding());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private static SimpleType createRawTypeReferenceOperations(CompilationUnit compi

private static boolean hasFatalError(CompilationUnit compilationUnit) {
try {
if (!((ICompilationUnit) compilationUnit.getJavaElement()).isStructureKnown())
if (!compilationUnit.getJavaElement().isStructureKnown())
return true;
} catch (JavaModelException e) {
JavaManipulationPlugin.log(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public boolean visit(MethodDeclaration node) {

private void checkForUninitializedFinalReference(IBinding binding) {
if (binding instanceof IVariableBinding) {
int modifiers= ((IVariableBinding)binding).getModifiers();
int modifiers= binding.getModifiers();
if ((modifiers & IModifierConstants.ACC_FINAL) == IModifierConstants.ACC_FINAL) {
if (((IVariableBinding) binding).isField()) {
ASTNode decl= ((CompilationUnit)fMethodDeclaration.getRoot()).findDeclaringNode(binding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static RemoveVarOrInferredLambdaParameterTypesFixCore createRemoveVarOrIn
if (node instanceof LambdaExpression) {
lambda= (LambdaExpression) node;
} else if (node.getLocationInParent() == SingleVariableDeclaration.NAME_PROPERTY &&
((SingleVariableDeclaration) parent).getLocationInParent() == LambdaExpression.PARAMETERS_PROPERTY) {
parent.getLocationInParent() == LambdaExpression.PARAMETERS_PROPERTY) {
lambda= (LambdaExpression) node.getParent().getParent();
} else {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws Core
}

private RefactoringStatus findField() {
fField= (IField) ((IVariableBinding) fSelectedConstantName.resolveBinding()).getJavaElement();
fField= (IField) fSelectedConstantName.resolveBinding().getJavaElement();
if (fField != null && ! fField.exists())
return RefactoringStatus.createStatus(RefactoringStatus.FATAL, RefactoringCoreMessages.InlineConstantRefactoring_local_anonymous_unsupported, null, CorextCore.getPluginId(), RefactoringStatusCodes.LOCAL_AND_ANONYMOUS_NOT_SUPPORTED, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreEx
}
if (rewrite.hasRecordedChanges()) {
TextEdit edit= rewrite.rewriteImports(null);
if (edit instanceof MultiTextEdit ? ((MultiTextEdit)edit).getChildrenSize() > 0 : true) {
if (edit instanceof MultiTextEdit ? edit.getChildrenSize() > 0 : true) {
root.addChild(edit);
change.addTextEditGroup(
new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_import, new TextEdit[] {edit}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ private void adjustMemberVisibility(final IMember member, final IProgressMonitor

if (member instanceof IType) {
// recursively check accessibility of member type's members
final IJavaElement[] typeMembers= ((IType) member).getChildren();
final IJavaElement[] typeMembers= member.getChildren();
for (IJavaElement typeMember : typeMembers) {
if (! (typeMember instanceof IInitializer))
adjustMemberVisibility((IMember) typeMember, monitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ private boolean canMoveToInterface(IMember member, boolean is18OrHigher) throws
private RefactoringStatus checkMovedMemberAvailability(IMember memberToMove, IProgressMonitor pm) throws JavaModelException{
RefactoringStatus result= new RefactoringStatus();
if (memberToMove instanceof IType) { // recursively check accessibility of member type's members
IJavaElement[] typeMembers= ((IType) memberToMove).getChildren();
IJavaElement[] typeMembers= memberToMove.getChildren();
pm.beginTask(RefactoringCoreMessages.MoveMembersRefactoring_checking, typeMembers.length + 1);
for (IJavaElement typeMember : typeMembers) {
if (typeMember instanceof IInitializer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ protected final void rewriteTypeOccurrence(final CompilationUnitRange range, fin
binding= ((VariableDeclaration) ((VariableDeclarationStatement) node).fragments().get(0)).resolveBinding();
node= target.findDeclaringNode(binding.getKey());
if (node instanceof VariableDeclarationFragment)
rewriteTypeOccurrence(estimate, rewrite, ((VariableDeclarationStatement) ((VariableDeclarationFragment) node).getParent()).getType(), group);
rewriteTypeOccurrence(estimate, rewrite, ((VariableDeclarationStatement) node.getParent()).getType(), group);
} else if (node instanceof MethodDeclaration) {
binding= ((MethodDeclaration) node).resolveBinding();
node= target.findDeclaringNode(binding.getKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public WildcardType getWildcard() {

@Override
public boolean doEquals(TType type) {
return getBindingKey().equals(((CaptureType)type).getBindingKey())
return getBindingKey().equals(type.getBindingKey())
&& fJavaProject.equals(((CaptureType)type).fJavaProject);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private int evaluateModifiers(AnnotationTypeDeclaration targetTypeDecl) {
List<BodyDeclaration> methodDecls= targetTypeDecl.bodyDeclarations();
for (BodyDeclaration curr : methodDecls) {
if (curr instanceof AnnotationTypeMemberDeclaration) {
return ((AnnotationTypeMemberDeclaration) curr).getModifiers();
return curr.getModifiers();
}
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,9 @@ private void computeConstantDeclarationLocation() throws JavaModelException {

int modifiers;
if (decl instanceof FieldDeclaration)
modifiers= ((FieldDeclaration) decl).getModifiers();
modifiers= decl.getModifiers();
else if (decl instanceof Initializer)
modifiers= ((Initializer) decl).getModifiers();
modifiers= decl.getModifiers();
else {
continue; /* this declaration is not a field declaration
or initializer, so the placement of the constant
Expand Down Expand Up @@ -727,9 +727,9 @@ private static boolean isStaticFieldOrStaticInitializer(BodyDeclaration node) {

int modifiers;
if(node instanceof FieldDeclaration) {
modifiers = ((FieldDeclaration) node).getModifiers();
modifiers = node.getModifiers();
} else if(node instanceof Initializer) {
modifiers = ((Initializer) node).getModifiers();
modifiers = node.getModifiers();
} else {
Assert.isTrue(false);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreEx
ImportRewrite rewrite= inliner.getImportEdit();
if (rewrite.hasRecordedChanges()) {
TextEdit edit= rewrite.rewriteImports(null);
if (edit instanceof MultiTextEdit ? ((MultiTextEdit)edit).getChildrenSize() > 0 : true) {
if (edit instanceof MultiTextEdit ? edit.getChildrenSize() > 0 : true) {
root.addChild(edit);
change.addTextEditGroup(
new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_import, new TextEdit[] {edit}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.eclipse.ltk.core.refactoring.TextFileChange;
import org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange;

import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragment;
Expand Down Expand Up @@ -172,8 +171,8 @@ private static Change createDeleteChange(IJavaElement javaElement) throws JavaMo

case IJavaElement.CLASS_FILE:
//if this assert fails, it means that a precondition is missing
Assert.isTrue(((IClassFile)javaElement).getResource() instanceof IFile);
return createDeleteChange(((IClassFile)javaElement).getResource());
Assert.isTrue(javaElement.getResource() instanceof IFile);
return createDeleteChange(javaElement.getResource());

case IJavaElement.JAVA_MODEL: //cannot be done
case IJavaElement.JAVA_PROJECT: //handled differently
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ private static IContainer getAsContainer(IResource resDest) {
if (resDest instanceof IContainer)
return (IContainer) resDest;
if (resDest instanceof IFile)
return ((IFile) resDest).getParent();
return resDest.getParent();
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.eclipse.ltk.core.refactoring.GroupCategorySet;
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.TextChange;
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;

import org.eclipse.jdt.core.Flags;
Expand Down Expand Up @@ -1320,7 +1319,7 @@ protected void registerChanges(final TextEditBasedChangeManager manager) throws
CompilationUnitChange change= rewrite.createChange(true);

if (change != null) {
final TextEdit edit= ((TextChange) change).getEdit();
final TextEdit edit= change.getEdit();
if (edit != null) {
final IDocument document= new Document(fSuperSource);
try {
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.junit.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.junit.core
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.junit.core;singleton:=true
Bundle-Version: 3.13.200.qualifier
Bundle-Version: 3.13.300.qualifier
Bundle-Activator: org.eclipse.jdt.internal.junit.JUnitCorePlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public boolean isRunning() {
*/
public boolean rerunTest(String testId, String className, String testName) {
if (isKeptAlive()) {
Status status= ((TestCaseElement) getTestElement(testId)).getStatus();
Status status= getTestElement(testId).getStatus();
if (status == Status.ERROR) {
fErrorCount--;
} else if (status == Status.FAILURE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private IStatus checkRecursiveSuiteInclusion(Object[] selection){
}
for (Object element : selection) {
if (element instanceof IType){
if (((IType)element).equals(suiteClass)){
if (element.equals(suiteClass)){
return new JUnitStatus(IStatus.WARNING, WizardMessages.UpdateTestSuite_infinite_recursion);
}
}
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.text.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.text.tests
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.jdt.text.tests;singleton:=true
Bundle-Version: 3.14.400.qualifier
Bundle-Version: 3.14.500.qualifier
Bundle-Activator: org.eclipse.jdt.text.tests.JdtTextTestPlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %Plugin.providerName
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.text.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.text.tests</artifactId>
<version>3.14.400-SNAPSHOT</version>
<version>3.14.500-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.jface.text.DocumentRewriteSessionType;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension4;
import org.eclipse.jface.text.ITextViewerExtension;
import org.eclipse.jface.text.source.SourceViewer;

import org.eclipse.ui.internal.texteditor.quickdiff.QuickDiffRangeDifference;
Expand Down Expand Up @@ -66,7 +65,7 @@ protected void setUp() throws Exception {
DocumentRewriteSession rewriteSession= null;
try {
if (viewer != null)
((ITextViewerExtension) viewer).getRewriteTarget().beginCompoundChange();
viewer.getRewriteTarget().beginCompoundChange();
if (document instanceof IDocumentExtension4)
rewriteSession= ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.STRICTLY_SEQUENTIAL);
for (int i= 0; i < document.getNumberOfLines(); i += 2) {
Expand All @@ -76,7 +75,7 @@ protected void setUp() throws Exception {
if (document instanceof IDocumentExtension4)
((IDocumentExtension4) document).stopRewriteSession(rewriteSession);
if (viewer != null)
((ITextViewerExtension) viewer).getRewriteTarget().endCompoundChange();
viewer.getRewriteTarget().endCompoundChange();
}
EditorTestHelper.joinBackgroundActivities(fEditor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void testEnumWithAnonymousClass() throws Exception {
IType type= myEnumCu.getType("MyEnum");
IField field = type.getField("ENUM1");
IJavaElement[] elements= { field };
ISourceRange range= ((ISourceReference) field).getNameRange();
ISourceRange range= field.getNameRange();
// Should not throw ClassCastException
JavadocHover.getHoverInfo(elements, myEnumCu, new Region(range.getOffset(), range.getLength()), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.eclipse.jdt.core.dom.BodyDeclaration;
import org.eclipse.jdt.core.dom.EnumConstantDeclaration;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.Initializer;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
Expand Down Expand Up @@ -92,7 +91,7 @@ private int category(BodyDeclaration bodyDeclaration) {
}
case ASTNode.INITIALIZER :
{
int flags= ((Initializer) bodyDeclaration).getModifiers();
int flags= bodyDeclaration.getModifiers();
if (Modifier.isStatic(flags))
return MembersOrderPreferenceCacheCommon.STATIC_INIT_INDEX;
else
Expand Down
Loading

0 comments on commit 690340f

Please sign in to comment.