Skip to content

Commit

Permalink
Code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
akurtakov committed Sep 5, 2024
1 parent d4f3ba7 commit 744058f
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 33 deletions.
144 changes: 144 additions & 0 deletions org.eclipse.jdt.core.javac/.settings/org.eclipse.jdt.ui.prefs
Original file line number Diff line number Diff line change
@@ -1,3 +1,147 @@
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile
formatter_settings_version=23
sp_cleanup.add_all=false
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
sp_cleanup.add_missing_deprecated_annotations=true
sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
sp_cleanup.add_missing_override_annotations_interface_methods=true
sp_cleanup.add_serial_version_id=false
sp_cleanup.also_simplify_lambda=true
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=false
sp_cleanup.always_use_this_for_non_static_field_access=false
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.array_with_curly=false
sp_cleanup.arrays_fill=false
sp_cleanup.bitwise_conditional_expression=false
sp_cleanup.boolean_literal=false
sp_cleanup.boolean_value_rather_than_comparison=false
sp_cleanup.break_loop=false
sp_cleanup.collection_cloning=false
sp_cleanup.comparing_on_criteria=false
sp_cleanup.comparison_statement=false
sp_cleanup.controlflow_merge=false
sp_cleanup.convert_functional_interfaces=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.convert_to_enhanced_for_loop_if_loop_var_used=false
sp_cleanup.convert_to_switch_expressions=false
sp_cleanup.correct_indentation=false
sp_cleanup.do_while_rather_than_while=false
sp_cleanup.double_negation=false
sp_cleanup.else_if=false
sp_cleanup.embedded_if=false
sp_cleanup.evaluate_nullable=false
sp_cleanup.extract_increment=false
sp_cleanup.format_source_code=false
sp_cleanup.format_source_code_changes_only=false
sp_cleanup.hash=false
sp_cleanup.if_condition=false
sp_cleanup.insert_inferred_type_arguments=false
sp_cleanup.instanceof=false
sp_cleanup.instanceof_keyword=false
sp_cleanup.invert_equals=false
sp_cleanup.join=false
sp_cleanup.lazy_logical_operator=false
sp_cleanup.make_local_variable_final=true
sp_cleanup.make_parameters_final=false
sp_cleanup.make_private_fields_final=true
sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=false
sp_cleanup.map_cloning=false
sp_cleanup.merge_conditional_blocks=false
sp_cleanup.multi_catch=false
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=true
sp_cleanup.no_string_creation=false
sp_cleanup.no_super=false
sp_cleanup.number_suffix=false
sp_cleanup.objects_equals=false
sp_cleanup.on_save_use_additional_actions=false
sp_cleanup.one_if_rather_than_duplicate_blocks_that_fall_through=false
sp_cleanup.operand_factorization=false
sp_cleanup.organize_imports=true
sp_cleanup.overridden_assignment=false
sp_cleanup.overridden_assignment_move_decl=true
sp_cleanup.plain_replacement=false
sp_cleanup.precompile_regex=false
sp_cleanup.primitive_comparison=false
sp_cleanup.primitive_parsing=false
sp_cleanup.primitive_rather_than_wrapper=false
sp_cleanup.primitive_serialization=false
sp_cleanup.pull_out_if_from_if_else=false
sp_cleanup.pull_up_assignment=false
sp_cleanup.push_down_negation=false
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.reduce_indentation=false
sp_cleanup.redundant_comparator=false
sp_cleanup.redundant_falling_through_block_end=false
sp_cleanup.remove_private_constructors=true
sp_cleanup.remove_redundant_modifiers=false
sp_cleanup.remove_redundant_semicolons=false
sp_cleanup.remove_redundant_type_arguments=false
sp_cleanup.remove_trailing_whitespaces=false
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
sp_cleanup.remove_unnecessary_array_creation=false
sp_cleanup.remove_unnecessary_casts=true
sp_cleanup.remove_unnecessary_nls_tags=false
sp_cleanup.remove_unused_imports=false
sp_cleanup.remove_unused_local_variables=false
sp_cleanup.remove_unused_method_parameters=false
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=false
sp_cleanup.remove_unused_private_methods=true
sp_cleanup.remove_unused_private_types=true
sp_cleanup.replace_deprecated_calls=false
sp_cleanup.return_expression=false
sp_cleanup.simplify_lambda_expression_and_method_ref=false
sp_cleanup.single_used_field=false
sp_cleanup.sort_members=false
sp_cleanup.sort_members_all=false
sp_cleanup.standard_comparison=false
sp_cleanup.static_inner_class=false
sp_cleanup.strictly_equal_or_different=false
sp_cleanup.stringbuffer_to_stringbuilder=false
sp_cleanup.stringbuilder=false
sp_cleanup.stringbuilder_for_local_vars=true
sp_cleanup.stringconcat_stringbuffer_stringbuilder=false
sp_cleanup.stringconcat_to_textblock=false
sp_cleanup.substring=false
sp_cleanup.switch=false
sp_cleanup.system_property=false
sp_cleanup.system_property_boolean=false
sp_cleanup.system_property_file_encoding=false
sp_cleanup.system_property_file_separator=false
sp_cleanup.system_property_line_separator=false
sp_cleanup.system_property_path_separator=false
sp_cleanup.ternary_operator=false
sp_cleanup.try_with_resource=false
sp_cleanup.unlooped_while=false
sp_cleanup.unreachable_block=false
sp_cleanup.use_anonymous_class_creation=false
sp_cleanup.use_autoboxing=false
sp_cleanup.use_blocks=true
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_directly_map_method=false
sp_cleanup.use_lambda=true
sp_cleanup.use_parentheses_in_expressions=false
sp_cleanup.use_string_is_blank=false
sp_cleanup.use_this_for_non_static_field_access=false
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
sp_cleanup.use_unboxing=false
sp_cleanup.use_var=false
sp_cleanup.useless_continue=false
sp_cleanup.useless_return=false
sp_cleanup.valueof_rather_than_instantiation=false
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import org.eclipse.jdt.internal.core.JavaProject;
import org.eclipse.jdt.internal.core.dom.ICompilationUnitResolver;
import org.eclipse.jdt.internal.core.util.BindingKeyParser;
import org.eclipse.jdt.internal.javac.JavacConfig;
import org.eclipse.jdt.internal.javac.JavacProblemConverter;
import org.eclipse.jdt.internal.javac.JavacUtils;
import org.eclipse.jdt.internal.javac.UnusedProblemFactory;
Expand Down Expand Up @@ -414,7 +413,7 @@ private void resolveBindings(CompilationUnit unit, Map<String, IBinding> binding
if (!unit.types().isEmpty()) {
List<AbstractTypeDeclaration> types = unit.types();
for( int i = 0; i < types.size(); i++ ) {
ITypeBinding tb = ((AbstractTypeDeclaration) types.get(i)).resolveBinding();
ITypeBinding tb = types.get(i).resolveBinding();
if (tb != null) {
bindingMap.put(tb.getKey(), tb);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.tree.JCTree.JCConditional;
import com.sun.tools.javac.tree.JCTree.JCConstantCaseLabel;
import com.sun.tools.javac.tree.JCTree.JCContinue;
import com.sun.tools.javac.tree.JCTree.JCDefaultCaseLabel;
import com.sun.tools.javac.tree.JCTree.JCDirective;
import com.sun.tools.javac.tree.JCTree.JCDoWhileLoop;
import com.sun.tools.javac.tree.JCTree.JCEnhancedForLoop;
Expand Down Expand Up @@ -97,8 +99,6 @@
import com.sun.tools.javac.tree.JCTree.JCParens;
import com.sun.tools.javac.tree.JCTree.JCPattern;
import com.sun.tools.javac.tree.JCTree.JCPatternCaseLabel;
import com.sun.tools.javac.tree.JCTree.JCConstantCaseLabel;
import com.sun.tools.javac.tree.JCTree.JCDefaultCaseLabel;
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree;
import com.sun.tools.javac.tree.JCTree.JCProvides;
import com.sun.tools.javac.tree.JCTree.JCRecordPattern;
Expand Down Expand Up @@ -340,7 +340,7 @@ private RequiresDirective convert(JCRequires javac) {
RequiresDirective res = this.ast.newRequiresDirective();
res.setName(toName(javac.getModuleName()));
int javacStart = javac.getStartPosition();
List modifiersToAdd = new ArrayList<>();
List<ASTNode> modifiersToAdd = new ArrayList<>();
if (javac.isTransitive()) {
ModuleModifier trans = this.ast.newModuleModifier(ModuleModifierKeyword.TRANSITIVE_KEYWORD);
int transStart = this.rawText.substring(javacStart).indexOf(ModuleModifierKeyword.TRANSITIVE_KEYWORD.toString());
Expand All @@ -359,7 +359,7 @@ private RequiresDirective convert(JCRequires javac) {
}
modifiersToAdd.add(stat);
}
modifiersToAdd.sort((a, b) -> ((ASTNode)a).getStartPosition() - ((ASTNode)b).getStartPosition());
modifiersToAdd.sort((a, b) -> a.getStartPosition() - b.getStartPosition());
modifiersToAdd.stream().forEach(res.modifiers()::add);
commonSettings(res, javac);
return res;
Expand Down Expand Up @@ -694,7 +694,7 @@ private TypeParameter convert(JCTypeParameter typeParameter) {
List<JCExpression> bounds = typeParameter.getBounds();
Iterator<JCExpression> i = bounds.iterator();
while(i.hasNext()) {
JCTree t = (JCTree)i.next();
JCTree t = i.next();
Type type = convertToType(t);
ret.typeBounds().add(type);
end = typeParameter.getEndPosition(this.javacCompilationUnit.endPositions);
Expand Down Expand Up @@ -1274,7 +1274,7 @@ private Expression convertExpressionImpl(JCExpression javac) {
if (nameExpr instanceof JCFieldAccess access) {
// Handle super method calls first
boolean superCall1 = access.getExpression() instanceof JCFieldAccess && Objects.equals(Names.instance(this.context)._super, ((JCFieldAccess)access.getExpression()).getIdentifier());
boolean superCall2 = access instanceof JCFieldAccess && Objects.equals(Names.instance(this.context)._super.toString(), access.getExpression().toString());
boolean superCall2 = Objects.equals(Names.instance(this.context)._super.toString(), access.getExpression().toString());
if (superCall1 || superCall2) {
JCFieldAccess fa = superCall1 ? ((JCFieldAccess)access.getExpression()) : access;
SuperMethodInvocation res2 = this.ast.newSuperMethodInvocation();
Expand Down Expand Up @@ -1305,7 +1305,7 @@ private Expression convertExpressionImpl(JCExpression javac) {
res.setName(name);
} else if (nameExpr instanceof JCFieldAccess access) {
boolean superCall1 = access.getExpression() instanceof JCFieldAccess && Objects.equals(Names.instance(this.context)._super, ((JCFieldAccess)access.getExpression()).getIdentifier());
boolean superCall2 = access instanceof JCFieldAccess && Objects.equals(Names.instance(this.context)._super.toString(), access.getExpression().toString());
boolean superCall2 = Objects.equals(Names.instance(this.context)._super.toString(), access.getExpression().toString());
if (superCall1 || superCall2) {
JCFieldAccess fa = superCall1 ? ((JCFieldAccess)access.getExpression()) : access;
SuperMethodInvocation res2 = this.ast.newSuperMethodInvocation();
Expand Down Expand Up @@ -2285,7 +2285,7 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) {
res.setBody(stmt);
var initializerIt = jcForLoop.getInitializer().iterator();
while(initializerIt.hasNext()) {
Expression expr = convertStatementToExpression((JCStatement)initializerIt.next(), res);
Expression expr = convertStatementToExpression(initializerIt.next(), res);
if( expr != null )
res.initializers().add(expr);
}
Expand All @@ -2295,9 +2295,9 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) {
res.setExpression(expr);
}

Iterator updateIt = jcForLoop.getUpdate().iterator();
Iterator<JCExpressionStatement> updateIt = jcForLoop.getUpdate().iterator();
while(updateIt.hasNext()) {
Expression expr = convertStatementToExpression((JCStatement)updateIt.next(), res);
Expression expr = convertStatementToExpression(updateIt.next(), res);
if( expr != null )
res.updaters().add(expr);
}
Expand Down Expand Up @@ -2579,8 +2579,7 @@ private Block convertBlock(JCBlock javac) {
Block res = this.ast.newBlock();
commonSettings(res, javac);
if (javac.getStatements() != null) {
for( Iterator i = javac.getStatements().iterator(); i.hasNext();) {
JCStatement next = (JCStatement)i.next();
for (JCStatement next : javac.getStatements()) {
Statement s = convertStatement(next, res);
if( s != null ) {
res.statements().add(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;

import com.sun.source.tree.ClassTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.Tree.Kind;
import com.sun.source.util.TreePath;
import com.sun.source.util.TreeScanner;
import com.sun.tools.javac.api.JavacTrees;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Kinds;
Expand Down Expand Up @@ -342,7 +340,7 @@ private org.eclipse.jface.text.Position getDiagnosticPosition(Diagnostic<? exten
}
if (element != null) {
switch (element) {
case JCTree.JCTypeApply jcTypeApply: return getPositionByNodeRangeOnly(jcDiagnostic, (JCTree)jcTypeApply.clazz);
case JCTree.JCTypeApply jcTypeApply: return getPositionByNodeRangeOnly(jcDiagnostic, jcTypeApply.clazz);
case JCClassDecl jcClassDecl: return getDiagnosticPosition(jcDiagnostic, jcClassDecl);
case JCVariableDecl jcVariableDecl: return getDiagnosticPosition(jcDiagnostic, jcVariableDecl);
case JCMethodDecl jcMethodDecl: return getDiagnosticPosition(jcDiagnostic, jcMethodDecl, problemId);
Expand Down Expand Up @@ -672,7 +670,7 @@ public int toProblemId(Diagnostic<? extends JavaFileObject> diagnostic) {
case "compiler.err.cant.apply.symbols", "compiler.err.cant.apply.symbol" ->
switch (getDiagnosticArgumentByType(diagnostic, Kinds.KindName.class)) {
case CONSTRUCTOR -> {
TreePath treePath = getTreePath((JCDiagnostic)diagnostic);
TreePath treePath = getTreePath(diagnostic);
while (treePath != null && !(treePath.getLeaf() instanceof JCMethodDecl) && treePath != null) {
treePath = treePath.getParentPath();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,13 @@
import javax.tools.JavaFileManager;
import javax.tools.StandardLocation;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.TypeParameter;
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.core.Member;
import org.eclipse.jdt.internal.core.util.Util;

Expand Down Expand Up @@ -245,19 +244,19 @@ public IJavaElement getJavaElement() {

private IJavaElement getJavaElementForMethodDeclaration(IType currentType, MethodDeclaration methodDeclaration) {
ArrayList<String> typeParamsList = new ArrayList<>();
List typeParams = null;
List<TypeParameter> typeParams = null;
if (methodDeclaration.getAST().apiLevel() > AST.JLS2) {
typeParams = methodDeclaration.typeParameters();
}
if( typeParams == null ) {
typeParams = new ArrayList<>();
}
for( int i = 0; i < typeParams.size(); i++ ) {
typeParamsList.add(((TypeParameter)typeParams.get(i)).getName().toString());
typeParamsList.add(typeParams.get(i).getName().toString());
}

List<SingleVariableDeclaration> p = methodDeclaration.parameters();
String[] params = ((List<SingleVariableDeclaration>)p).stream() //
String[] params = p.stream() //
.map(param -> {
String sig = Util.getSignature(param.getType());
if (param.getAST().apiLevel() > AST.JLS2 && param.isVarargs()) {
Expand All @@ -279,7 +278,7 @@ private IJavaElement getJavaElementForMethodDeclaration(IType currentType, Metho
IMethod[] candidates = Member.findMethods(result, methods);
if (candidates == null || candidates.length == 0)
return null;
return (JavaElement) candidates[0];
return candidates[0];
}

private String resolveTypeName(com.sun.tools.javac.code.Type type, boolean binary) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
package org.eclipse.jdt.internal.javac.dom;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import javax.lang.model.element.ModuleElement.DirectiveKind;

Expand All @@ -35,7 +33,6 @@
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Kinds;
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.code.Type.ModuleType;
import com.sun.tools.javac.tree.JCTree.JCDirective;
import com.sun.tools.javac.tree.JCTree.JCExpression;
Expand Down Expand Up @@ -227,7 +224,7 @@ public ITypeBinding[] getImplementations(ITypeBinding service) {
JavacTypeBinding tmp = this.resolver.bindings.getTypeBinding(arr[i].getService().type);
if(service.getKey().equals(tmp.getKey())) {
// we have our match
JavacTypeBinding[] ret = arr[i].getImplementations().stream().map(x -> this.resolver.bindings.getTypeBinding((ClassType)x.type)).toArray(JavacTypeBinding[]::new);
JavacTypeBinding[] ret = arr[i].getImplementations().stream().map(x -> this.resolver.bindings.getTypeBinding(x.type)).toArray(JavacTypeBinding[]::new);
return ret;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public IJavaElement getJavaElement() {
return null;
}
if (this.isArray()) {
return (IType) this.getElementType().getJavaElement();
return this.getElementType().getJavaElement();
}
if (this.typeSymbol instanceof final ClassSymbol classSymbol) {
if (isAnonymous()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import junit.framework.Test;

@SuppressWarnings("rawtypes")
public class ASTConverterBugsTestSetup extends ConverterTestSetup {

@Override
Expand Down

0 comments on commit 744058f

Please sign in to comment.