|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2024 Red Hat Inc. and others. |
| 3 | + * All rights reserved. This program and the accompanying materials |
| 4 | + * are made available under the terms of the Eclipse Public License 2.0 |
| 5 | + * which accompanies this distribution, and is available at |
| 6 | + * http://www.eclipse.org/legal/epl-2.0 |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: EPL-2.0 |
| 9 | + * |
| 10 | + * Contributors: |
| 11 | + * Red Hat Inc. - initial API and implementation |
| 12 | + *******************************************************************************/ |
| 13 | +package org.eclipse.jdt.ls.core.internal.cleanup; |
| 14 | + |
| 15 | +import java.util.Arrays; |
| 16 | +import java.util.Collection; |
| 17 | +import java.util.List; |
| 18 | + |
| 19 | +import org.eclipse.core.runtime.CoreException; |
| 20 | +import org.eclipse.jdt.core.JavaCore; |
| 21 | +import org.eclipse.jdt.internal.corext.fix.CleanUpConstants; |
| 22 | +import org.eclipse.jdt.internal.corext.fix.RenameUnusedVariableFixCore; |
| 23 | +import org.eclipse.jdt.ui.cleanup.CleanUpContext; |
| 24 | +import org.eclipse.jdt.ui.cleanup.ICleanUpFix; |
| 25 | + |
| 26 | +/** |
| 27 | + * Represents a clean up that renames unused lambda parameter identifier to an |
| 28 | + * underscore (_) |
| 29 | + */ |
| 30 | +public class RenameUnusedLocalVariableCleanup implements ISimpleCleanUp { |
| 31 | + |
| 32 | + private static final List<String> COMPILER_OPTS = Arrays.asList(JavaCore.COMPILER_PB_UNUSED_LAMBDA_PARAMETER, JavaCore.COMPILER_PB_UNUSED_LOCAL); |
| 33 | + |
| 34 | + @Override |
| 35 | + public Collection<String> getIdentifiers() { |
| 36 | + return List.of("removeUnusedLambdaParameters", CleanUpConstants.REMOVE_UNUSED_CODE_LOCAL_VARIABLES); |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public ICleanUpFix createFix(CleanUpContext context) throws CoreException { |
| 41 | + return RenameUnusedVariableFixCore.createCleanUp(context.getAST(), true); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public List<String> getRequiredCompilerMarkers() { |
| 46 | + return COMPILER_OPTS; |
| 47 | + } |
| 48 | + |
| 49 | +} |
0 commit comments