Skip to content

Commit

Permalink
Always propose generics
Browse files Browse the repository at this point in the history
Java 8 is the min version supported by ECJ thus generics are always
supported.
  • Loading branch information
akurtakov committed Dec 26, 2024
1 parent 4ced3ee commit d55c9f0
Showing 1 changed file with 1 addition and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -18,12 +18,8 @@
import org.eclipse.jdt.core.CompletionContext;
import org.eclipse.jdt.core.CompletionProposal;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.Signature;

import org.eclipse.jdt.internal.corext.util.JavaModelUtil;

import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jdt.ui.text.java.CompletionProposalCollector;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
Expand Down Expand Up @@ -91,10 +87,6 @@ IJavaCompletionProposal createTypeProposal(CompletionProposal typeProposal) {
if (cu == null || getContext() != null && getContext().isInJavadoc())
return super.createJavaCompletionProposal(typeProposal);

IJavaProject project= cu.getJavaProject();
if (!shouldProposeGenerics(project))
return super.createJavaCompletionProposal(typeProposal);

char[] completion= typeProposal.getCompletion();
// don't add parameters for import-completions nor for proposals with an empty completion (e.g. inside the type argument list)
if (completion.length > 0 && completion[completion.length - 1] == '.')
Expand All @@ -106,23 +98,4 @@ IJavaCompletionProposal createTypeProposal(CompletionProposal typeProposal) {
return newProposal;
}

/**
* Returns <code>true</code> if generic proposals should be allowed,
* <code>false</code> if not. Note that even though code (in a library)
* may be referenced that uses generics, it is still possible that the
* current source does not allow generics.
*
* @param project the Java project
* @return <code>true</code> if the generic proposals should be allowed,
* <code>false</code> if not
*/
private boolean shouldProposeGenerics(IJavaProject project) {
String sourceVersion;
if (project != null)
sourceVersion= project.getOption(JavaCore.COMPILER_SOURCE, true);
else
sourceVersion= JavaCore.getOption(JavaCore.COMPILER_SOURCE);

return JavaModelUtil.is50OrHigher(sourceVersion);
}
}

0 comments on commit d55c9f0

Please sign in to comment.