Skip to main content
summaryrefslogtreecommitdiffstats
blob: c0402432809c3318f8cbc5b45bf40cb47d8b7bbd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*******************************************************************************
 * Copyright (c) 2005, 2007 committers of openArchitectureWare 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:
 *     committers of openArchitectureWare - initial API and implementation
 *******************************************************************************/

package org.eclipse.internal.xpand2.codeassist;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.internal.xpand2.model.XpandDefinition;
import org.eclipse.internal.xtend.expression.codeassist.ProposalComputer;
import org.eclipse.internal.xtend.expression.codeassist.ProposalFactory;
import org.eclipse.xpand2.XpandExecutionContext;
import org.eclipse.xtend.expression.ExecutionContext;

public class ExpandProposalComputer implements ProposalComputer {
	private final static Pattern p = FastAnalyzer.EXPAND_PATTERN;

	public List<Object> computeProposals(final String txt, final ExecutionContext ctx, final ProposalFactory factory) {
		final List<Object> result = new ArrayList<Object>();

		Matcher m = p.matcher(txt);
		if (m.find()) {
			String prefix = m.group(1);
			if (ctx instanceof XpandExecutionContext) {
				XpandExecutionContext xpandCtx = (XpandExecutionContext) ctx;
				List<XpandDefinition> allDefinitions = xpandCtx.getAllDefinitions();
				if (allDefinitions != null) {
					for (XpandDefinition xpandDefinition : allDefinitions) {
						String defineName = xpandDefinition.getName();
						result.add(factory.createDefinitionProposal(defineName, defineName, prefix));
					}
				}
			}
		}

		return result;
	}
}

Back to the top