Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion com.avaloq.tools.ddk.xtext.ui/.classpath
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
<accessrules>
Expand Down
6 changes: 0 additions & 6 deletions com.avaloq.tools.ddk.xtext.ui/.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
Expand All @@ -44,7 +39,6 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>net.sourceforge.pmd.eclipse.plugin.pmdNature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
<nature>edu.umd.cs.findbugs.plugin.eclipse.findbugsNature</nature>
Expand Down
1 change: 0 additions & 1 deletion com.avaloq.tools.ddk.xtext.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Require-Bundle: com.avaloq.tools.ddk.xtext,
org.eclipse.jdt.core,
org.eclipse.xtext.ui,
org.eclipse.xtext.ui.shared,
org.eclipse.xtext.xbase.lib,
org.eclipse.search,
org.eclipse.ui.ide,
org.apache.commons.lang3,
Expand Down
3 changes: 1 addition & 2 deletions com.avaloq.tools.ddk.xtext.ui/build.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
source.. = src/,\
xtend-gen/
source.. = src/
bin.includes = META-INF/,\
icons/,\
schema/,\
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*******************************************************************************
* Copyright (c) 2016 Avaloq Group AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Avaloq Group AG - initial API and implementation
*******************************************************************************/
package com.avaloq.tools.ddk.xtext.ui.templates;

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

import org.apache.commons.lang3.Validate;
import org.apache.commons.text.StringEscapeUtils;

import com.google.inject.Singleton;

/**
* Helper methods for {@link org.eclipse.xtext.ui.editor.contentassist.ITemplateProposalProvider ITemplateProposalProvider} implementations.
*/
@Singleton
@SuppressWarnings("nls")
public class TemplateProposalProviderHelper {

private static final String SIMPLE_ENUM_TYPE = new SimpleEnumTemplateVariableResolver().getType();

/**
* Create a literal value pattern, including quotes if necessary, for a {@link org.eclipse.jface.text.templates.Template Template}.
*
* @param name the name of the variable, may not be {@code null} nor contain whitespace
* @param defaultValue default value, may be {@code null}
* @return pattern, never {@code null}
* @throws NullPointerException if name is null
* @throws IllegalArgumentException if name contains whitespace
*/
public String createLiteralValuePattern(final String name, final Object defaultValue) throws NullPointerException, IllegalArgumentException {
final String pattern = createTemplateVariablePattern(SIMPLE_ENUM_TYPE, name, defaultValue);

if (defaultValue instanceof String) {
// Surround pattern with quotes
return "\"" + pattern + "\"";
} else {
return pattern;
}
}

/**
* Create a variable pattern for a {@link org.eclipse.jface.text.templates.Template Template}.
*
* @param type the type of the variable, may not be {@code null} nor contain whitespace
* @param name the name of the variable, may not be {@code null} nor contain whitespace
* @param values the values available at this variable, may not be {@code null} nor empty
* @return pattern, never {@code null}
* @throws NullPointerException if type, name or values is null
* @throws IllegalArgumentException if type or name contains whitespace or values is empty
*/
public String createTemplateVariablePattern(final String type, final String name, final Object... values) throws NullPointerException, IllegalArgumentException {
Objects.requireNonNull(type);
Objects.requireNonNull(name);
Objects.requireNonNull(values);
Validate.isTrue(!type.chars().anyMatch(Character::isWhitespace));
Validate.isTrue(!name.chars().anyMatch(Character::isWhitespace));
Validate.notEmpty(values);

final Object[] useValues;
if (values.length == 1 && values[0] instanceof Boolean) {
// Offer both false and true as dropdown options
useValues = new Object[] {values[0], !((Boolean) values[0])};
} else {
useValues = values;
}

final String sanitisedValues = Arrays.stream(useValues)
.map(it ->
// Escape double-quotes to comply with string grammar.
// Double-up single-quotes to comply with template pattern grammar.
// Wrap each value in single quotes.
"'" + StringEscapeUtils.escapeJava(String.valueOf(it)).replace("'", "''") + "'")
.collect(Collectors.joining(", "));

return "${" + name + ":" + type + "(" + sanitisedValues + ")}";
}

}

This file was deleted.

Empty file.