diff options
| author | Kalyan Prasad Tatavarthi | 2019-05-16 07:58:28 +0000 |
|---|---|---|
| committer | Kalyan Prasad Tatavarthi | 2019-05-16 07:58:28 +0000 |
| commit | 36dbc24413b0d5c2977641cb4df2a318453ba140 (patch) | |
| tree | e60fdb730585c82a90942ff04851f68adedc9cd5 | |
| parent | 5d9ac75453e40030977cf42dab8bd0e476aee6e9 (diff) | |
| download | eclipse.jdt.ui-36dbc24413b0d5c2977641cb4df2a318453ba140.tar.gz eclipse.jdt.ui-36dbc24413b0d5c2977641cb4df2a318453ba140.tar.xz eclipse.jdt.ui-36dbc24413b0d5c2977641cb4df2a318453ba140.zip | |
Change-Id: I1b8cb0819e35deafd92c91b65a2fbca04c0b511e
Signed-off-by: Kalyan Prasad Tatavarthi <kalyan_prasad@in.ibm.com>
2 files changed, 42 insertions, 5 deletions
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java index 7c103c7f3d..317305603e 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. + * Copyright (c) 2000, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -885,6 +885,10 @@ public final class JavaModelUtil { public static boolean is11OrHigher(IJavaProject project) { return is11OrHigher(getSourceCompliance(project)); } + + public static boolean is12OrHigher(IJavaProject project) { + return is12OrHigher(getSourceCompliance(project)); + } private static String getSourceCompliance(IJavaProject project) { return project != null ? project.getOption(JavaCore.COMPILER_SOURCE, true) : JavaCore.getOption(JavaCore.COMPILER_SOURCE); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/contentassist/TemplateEngine.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/contentassist/TemplateEngine.java index c9a85547b5..93c3885876 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/contentassist/TemplateEngine.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/contentassist/TemplateEngine.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -39,10 +39,12 @@ import org.eclipse.jface.text.templates.Template; import org.eclipse.jface.text.templates.TemplateContextType; import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.internal.corext.template.java.CompilationUnitContext; import org.eclipse.jdt.internal.corext.template.java.CompilationUnitContextType; import org.eclipse.jdt.internal.corext.template.java.SWTContextType; +import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.JavaPluginImages; @@ -53,6 +55,9 @@ public class TemplateEngine { private static final Pattern $_LINE_SELECTION_PATTERN= Pattern.compile("\\$\\{(.*:)?" + GlobalTemplateVariables.LineSelection.NAME + "(\\(.*\\))?\\}"); //$NON-NLS-1$ //$NON-NLS-2$ private static final Pattern $_WORD_SELECTION_PATTERN= Pattern.compile("\\$\\{(.*:)?" + GlobalTemplateVariables.WordSelection.NAME + "(\\(.*\\))?\\}"); //$NON-NLS-1$ //$NON-NLS-2$ + + private static String Switch_Name = "switch"; //$NON-NLS-1$ + private static String Switch_Default = "switch case statement"; //$NON-NLS-1$ /** The context type. */ private TemplateContextType fContextType; @@ -130,11 +135,11 @@ public class TemplateEngine { IRegion region= new Region(start, end - start); Template[] templates= JavaPlugin.getDefault().getTemplateStore().getTemplates(); - + boolean needsCheck= !isJava12OrHigherProject(compilationUnit); if (selection.y == 0) { for (int i= 0; i != templates.length; i++) { Template template= templates[i]; - if (context.canEvaluate(template)) { + if (canEvaluate(context, template, needsCheck)) { fProposals.add(new TemplateProposal(template, context, region, getImage())); } } @@ -147,7 +152,7 @@ public class TemplateEngine { for (int i= 0; i != templates.length; i++) { Template template= templates[i]; - if (context.canEvaluate(template)) + if (canEvaluate(context, template, needsCheck)) { Matcher wordSelectionMatcher= $_WORD_SELECTION_PATTERN.matcher(template.getPattern()); Matcher lineSelectionMatcher= $_LINE_SELECTION_PATTERN.matcher(template.getPattern()); @@ -174,6 +179,34 @@ public class TemplateEngine { return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_TEMPLATE); } + private boolean isJava12OrHigherProject(ICompilationUnit compUnit) { + if (compUnit != null) { + IJavaProject javaProject= compUnit.getJavaProject(); + return JavaModelUtil.is12OrHigher(javaProject); + } + return false; + } + + private boolean isTemplateAllowed(Template template) { + if (Switch_Name.equals(template.getName())) { + if (Switch_Default.equals(template.getDescription())) { + return true; + } + return false; + } + return true; + } + + private boolean canEvaluate(CompilationUnitContext context, Template template, boolean needsCheck) { + if (!needsCheck) { + return context.canEvaluate(template); + } + if (isTemplateAllowed(template)) { + return context.canEvaluate(template); + } + return false; + } + /** * Returns <code>true</code> if one line is completely selected or if multiple lines are selected. * Being completely selected means that all characters except the new line characters are |
