diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/CdtTemplate.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/CdtTemplate.java new file mode 100644 index 00000000000..6728b1c96c8 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/CdtTemplate.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2021 Wind River Systems, Inc. and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Lidia Popescu (Wind River Systems) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.corext.codemanipulation; + +import java.util.Objects; + +import org.eclipse.jface.text.templates.Template; + +public class CdtTemplate implements Comparable { + + private String id; + private Template template; + private String key; + private String name; + + /** + * @param id - should be the id from TemplatePersistenceData + * @param template + */ + public CdtTemplate(String id, Template template) { + this.id = id; + this.template = template; + if (id == null) { + this.key = ""; //$NON-NLS-1$ + } else { + this.key = id; + } + if (template == null || template.getName() == null) { + this.name = ""; //$NON-NLS-1$ + } else { + this.name = template.getName(); + } + } + + public String getID() { + return id; + } + + public Template getTemplate() { + return template; + } + + public String getKey() { + return key; + } + + public String getName() { + return name; + } + + @Override + public int compareTo(CdtTemplate cdtTmp) { + int value = Objects.compare(key, cdtTmp.key, String::compareTo); + if (value == 0) { + return Objects.compare(name, cdtTmp.name, String.CASE_INSENSITIVE_ORDER); + } + return value; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java index d1aa1849f35..10593493114 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java @@ -18,6 +18,7 @@ package org.eclipse.cdt.internal.corext.codemanipulation; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -759,13 +760,27 @@ public class StubUtility { } templateDatas = projectStore.getTemplateData(); } + List