org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher Java Examples

The following examples show how to use org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FQNPrefixMatcherTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected FQNPrefixMatcher createMatcher() {
	IgnoreCase ignoreCase = new PrefixMatcher.IgnoreCase();
	FQNPrefixMatcher result = new FQNPrefixMatcher();
	result.setDelegate(ignoreCase);
	result.setLastSegmentFinder(new FQNPrefixMatcher.LastSegmentFinder() {
		@Override
		public String getLastSegment(String fqn, char delimiter) {
			int i = fqn.lastIndexOf(delimiter);
			if (i >= 0) {
				if (i != fqn.length() - 1)
					return fqn.substring(i + 1);
				return "";
			}
			return fqn;
		}
	});
	return result;
}
 
Example #2
Source File: PrefixMatcherHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/***/
// NOTE: Xtext's FQNPrefixMatcher injects PrefixMatcher.IgnoreCase, not PrefixMatcher, so we have to follow suit:
@Inject
public PrefixMatcherHelper(PrefixMatcher.IgnoreCase prefixMatcher) {
	if (!(prefixMatcher instanceof N4JSPrefixMatcher)) {
		throw new IllegalStateException("wrong injection setup: "
				+ "PrefixMatcher.IgnoreCase is expected to be bound to "
				+ N4JSPrefixMatcher.class.getSimpleName() + " but is bound to "
				+ prefixMatcher.getClass().getName());
	}
	this.prefixMatcher = prefixMatcher;
	this.canDoCamelCaseMatch = ((N4JSPrefixMatcher) prefixMatcher).isJdtAvailable();
}
 
Example #3
Source File: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void completeReferencedMetamodel_EPackage(EObject model, Assignment assignment,
		final ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	super.completeReferencedMetamodel_EPackage(model, assignment, context.copy().setMatcher(new PrefixMatcher() {

		@Override
		public boolean isCandidateMatchingPrefix(String name, String prefix) {
			if (prefix.startsWith("\"")) {
				if (prefix.length() == 1)
					prefix = "";
				else {
					prefix = prefix.substring(1);
					if (prefix.endsWith("\"")) {
						prefix = prefix.substring(0, prefix.length() - 1);
					}
				}
			}
			name = getValueConverter().toValue(name, "STRING", null).toString();
			if (context.getMatcher().isCandidateMatchingPrefix(name, prefix))
				return true;
			try {
				URI uri = URI.createURI(name);
				if (context.getMatcher().isCandidateMatchingPrefix(uri.lastSegment(), prefix))
					return true;
			} catch (Exception e) {
				// ignore
			}
			return false;
		}

	}).toContext(), acceptor);
}
 
Example #4
Source File: Bug349773Test.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected FQNPrefixMatcher createMatcher() {
	IgnoreCase ignoreCase = new PrefixMatcher.IgnoreCase();
	FQNPrefixMatcher result = new FQNPrefixMatcher();
	result.setDelegate(ignoreCase);
	result.setLastSegmentFinder(new FQNPrefixMatcher.DefaultLastSegmentFinder());
	return result;
}
 
Example #5
Source File: PrefixMatcherOutlineAdapterTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected StringMatcher createStringMatcher(String pattern) {
	FQNPrefixMatcher fqnPrefixMatcher = new FQNPrefixMatcher();
	fqnPrefixMatcher.setLastSegmentFinder(new FQNPrefixMatcher.DefaultLastSegmentFinder());
	fqnPrefixMatcher.setDelegate(new PrefixMatcher.CamelCase());
	return new PrefixMatcherOutlineAdapter(pattern, fqnPrefixMatcher);
}
 
Example #6
Source File: PrefixMatcherOutlineAdapter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public PrefixMatcherOutlineAdapter(String prefix, PrefixMatcher strategy) {
	super("", true);
	this.prefix = prefix;
	this.prefixParts = splitIntoParts(prefix);
	this.strategy = strategy;
	this.prefixStringMatcher = new StringMatcher(prefix, true);
	stringMatchers = Lists.newArrayList();
	for(String part: prefixParts) {
		stringMatchers.add(new StringMatcher(part, true));
	}
}
 
Example #7
Source File: TerminalsProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void complete_ID(EObject model, RuleCall ruleCall, final ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	if (doCreateIdProposals()) {
		PrefixMatcher newMatcher = new PrefixMatcher() {
			@Override
			public boolean isCandidateMatchingPrefix(String name, String prefix) {
				String strippedName = name;
				if (name.startsWith("^") && !prefix.startsWith("^")) {
					strippedName = name.substring(1);
				}
				return context.getMatcher().isCandidateMatchingPrefix(strippedName, prefix);
			}
		};
		ContentAssistContext myContext = context.copy().setMatcher(newMatcher).toContext();
		String feature = getAssignedFeature(ruleCall);
		String proposalText = feature != null ? feature : Strings.toFirstUpper(ruleCall.getRule().getName().toLowerCase());
		String displayText = proposalText;
		if (feature != null)
			displayText = proposalText + " - " + ruleCall.getRule().getName();
		proposalText = getValueConverter().toString(proposalText, ruleCall.getRule().getName());
		ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, myContext);
		if (proposal instanceof ConfigurableCompletionProposal) {
			ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
			configurable.setSelectionStart(configurable.getReplacementOffset());
			configurable.setSelectionLength(proposalText.length());
			configurable.setAutoInsertable(false);
			configurable.setSimpleLinkedMode(myContext.getViewer(), '\t', ' ');
		}
		acceptor.accept(proposal);
	}
}
 
Example #8
Source File: AbstractRefactoringTestLanguageUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #9
Source File: AbstractSARLUiModule.java    From sarl with Apache License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher.CamelCase> bindPrefixMatcher$CamelCase() {
	return EscapeSequenceAwarePrefixMatcher.class;
}
 
Example #10
Source File: AbstractContentAssistTestLanguageUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #11
Source File: AbstractRefactoringTestLanguage1UiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #12
Source File: AbstractDomainmodelUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #13
Source File: AbstractStatemachineUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #14
Source File: AbstractRuleEngineUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #15
Source File: AbstractArithmeticsUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #16
Source File: AbstractBuilderTestLanguageUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #17
Source File: AbstractXbaseUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #18
Source File: AbstractXbaseWithAnnotationsUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #19
Source File: AbstractPureXbaseUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #20
Source File: AbstractBug462047LangUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #21
Source File: AbstractXImportSectionTestLangUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #22
Source File: AbstractContentAssistFragmentTestLangUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #23
Source File: DotProposalProvider.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
public AttributeValueMatcher(PrefixMatcher originalMatcher) {
	this.originalMatcher = originalMatcher;
}
 
Example #24
Source File: AbstractXtendUiModule.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #25
Source File: XtendUiModule.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher.CamelCase> bindCamelCasePrefixMatcher() {
	return EscapeSequenceAwarePrefixMatcher.class;
}
 
Example #26
Source File: ImplementMemberFromSuperAssist.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected ICompletionProposal createOverrideMethodProposal(XtendTypeDeclaration model, IResolvedExecutable overrideable,
		final ContentAssistContext context, IProposalConflictHelper conflictHelper) {
	IXtextDocument document = context.getDocument();
	XtextResource resource = (XtextResource) model.eResource();
	int offset = context.getReplaceRegion().getOffset();
	int currentIndentation = appendableFactory.getIndentationLevelAtOffset(offset, document, resource);
	final int indentationLevel = currentIndentation == 0 ? 1 : currentIndentation;
	ReplacingAppendable appendable = appendableFactory.create(document, resource, offset, context.getReplaceRegion().getLength(), new OptionalParameters() {{ 
				ensureEmptyLinesAround = true;
				baseIndentationLevel = indentationLevel;	
			}});
	final String simpleName;
	JvmExecutable declaration = overrideable.getDeclaration();
	if (overrideable instanceof IResolvedOperation) {
		implementor.appendOverrideFunction(model, (IResolvedOperation) overrideable, appendable);
		simpleName = overrideable.getDeclaration().getSimpleName();
	} else if (model instanceof XtendClass) {
		implementor.appendConstructorFromSuper((XtendClass) model, (IResolvedConstructor) overrideable, appendable);
		simpleName = "new";
	} else {
		return null;
	}
	String code = appendable.getCode();
	if (!isValidProposal(code.trim(), context, conflictHelper) && !isValidProposal(simpleName, context, conflictHelper))
		return null;
	ImageDescriptor imageDescriptor = images.forOperation(declaration.getVisibility(), adornments.getOverrideAdornment(declaration));
	ImportOrganizingProposal completionProposal = createCompletionProposal(appendable, context.getReplaceRegion(),
			getLabel(overrideable), imageHelper.getImage(imageDescriptor));
	Matcher matcher = bodyExpressionPattern.matcher(code);
	if (matcher.find()) {
		int bodyExpressionLength = matcher.end(1) - matcher.start(1);
		int bodyExpressionStart = matcher.start(1) + appendable.getTotalOffset() - completionProposal.getReplacementOffset();
		if (bodyExpressionLength == 0) {
			completionProposal.setCursorPosition(bodyExpressionStart);
		} else {
			completionProposal.setSelectionStart(completionProposal.getReplacementOffset() + bodyExpressionStart);
			completionProposal.setSelectionLength(bodyExpressionLength);
			completionProposal.setAutoInsertable(false);
			completionProposal.setCursorPosition(bodyExpressionStart + bodyExpressionLength);
			completionProposal.setSimpleLinkedMode(context.getViewer(), '\t');
		}
	}
	completionProposal.setPriority(getPriority(model, declaration, context));
	completionProposal.setMatcher(new PrefixMatcher() {

		@Override
		public boolean isCandidateMatchingPrefix(String name, String prefix) {
			PrefixMatcher delegate = context.getMatcher();
			boolean result = delegate.isCandidateMatchingPrefix(simpleName, prefix);
			return result;
		}
		
	});
	return completionProposal;
}
 
Example #27
Source File: AbstractHelloWorldUiModule.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #28
Source File: AbstractGamlUiModule.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #29
Source File: AbstractSARLUiModule.java    From sarl with Apache License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}
 
Example #30
Source File: AbstractNoJdtTestLanguageUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends PrefixMatcher> bindPrefixMatcher() {
	return FQNPrefixMatcher.class;
}