Java Code Examples for org.eclipse.xtext.Keyword#getValue()

The following examples show how to use org.eclipse.xtext.Keyword#getValue() . 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: XbaseIdeContentProposalProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean filterKeyword(final Keyword keyword, final ContentAssistContext context) {
  final String value = keyword.getValue();
  if (((value.length() > 1) && Character.isLetter(value.charAt(0)))) {
    if ((Objects.equal(value, "as") || Objects.equal(value, "instanceof"))) {
      final EObject previousModel = context.getPreviousModel();
      if ((previousModel instanceof XExpression)) {
        if (((context.getPrefix().length() == 0) && (NodeModelUtils.getNode(previousModel).getEndOffset() > context.getOffset()))) {
          return false;
        }
        final LightweightTypeReference type = this.typeResolver.resolveTypes(previousModel).getActualType(((XExpression)previousModel));
        if (((type == null) || type.isPrimitiveVoid())) {
          return false;
        }
      }
    }
    return true;
  }
  return false;
}
 
Example 2
Source File: CodetemplatesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public void completeNestedKeyword(Keyword keyword, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor, TemplateData data) {
	String keywordValue = keyword.getValue();
	String escapedKeywordValue = keywordValue.replace("$", "$$");
	StyledString displayString = new StyledString(keywordValue);
	if (!keywordValue.equals(escapedKeywordValue)) {
		displayString = new StyledString(escapedKeywordValue)
			.append(" - ", StyledString.QUALIFIER_STYLER)
			.append(keywordValue, StyledString.COUNTER_STYLER)
			.append(" - Keyword", StyledString.QUALIFIER_STYLER);
	} else {
		displayString = displayString.append(" - Keyword", StyledString.QUALIFIER_STYLER);
	}
	ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) createCompletionProposal(escapedKeywordValue,
			displayString,
			getImage(keyword),
			contentAssistContext);
	getPriorityHelper().adjustKeywordPriority(proposal, contentAssistContext.getPrefix());
	if (proposal != null)
		proposal.setPriority(proposal.getPriority() * 2);
	acceptor.accept(proposal);
}
 
Example 3
Source File: XtextLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
String text(Assignment object) {
	StringBuffer label = new StringBuffer();
	label.append(object.getFeature()).append(" ").append(object.getOperator()).append(" ");
	AbstractElement terminal = object.getTerminal();
	if (terminal instanceof RuleCall) {
		RuleCall ruleCall = (RuleCall) terminal;
		String string = NodeModelUtils.getNode(ruleCall).getText();
		label.append(string);
	} else if (terminal instanceof Keyword) {
		Keyword keyword = (Keyword) terminal;
		String value = "'" + keyword.getValue() + "'";
		label.append(value);
	} else if (terminal instanceof CrossReference) {
		CrossReference crossReference = (CrossReference) terminal;
		label.append(getLabel(crossReference));
	} else {
		label.append("(..)");
	}

	String cardinality = object.getCardinality();
	label.append(cardinality != null ? cardinality : "");
	return label.toString();
}
 
Example 4
Source File: SARLEcoreDocumentationSyntacticSequencer.java    From sarl with Apache License 2.0 5 votes vote down vote up
protected void accept(ISynState emitter, INode node, RuleCallStack stack) {
	super.accept(emitter, node, stack);
	final InnerBlockDocumentationAdapter documentation = this.lastInnerBlock;
	if (documentation != null && emitter.getType() == SynStateType.UNASSIGEND_KEYWORD) {
		Keyword keyword = (Keyword) emitter.getGrammarElement();
		String token = node != null ? node.getText() : keyword.getValue();
		if (Strings.equal(token, this.keywords.getLeftCurlyBracketKeyword())) {
			this.lastInnerBlock = null;
			emitDocumentation(documentation.getTarget().getClass(), documentation.getDocumentation());
		}
	}
}
 
Example 5
Source File: TokenTypeRewriter.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the token type for the given keyword.
 */
public Integer getTokenType(Keyword kw) {
	String text = kw.getValue();
	Integer type = getTokenType(text, es5Keywords, ES5_KW_TOKEN, null);
	type = getTokenType(text, es6Keywords, ES6_KW_TOKEN, type);
	type = getTokenType(text, futureKeywords, FUTURE_KW_TOKEN, type);
	type = getTokenType(text, nullLiteral, NULL_TOKEN, type);
	type = getTokenType(text, booleanLiteral, BOOLEAN_TOKEN, type);
	type = getTokenType(text, n4jsKeyword, N4JS_KW_TOKEN, type);
	return type;
}
 
Example 6
Source File: EnumLiteralSerializer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String serializeAssignedEnumLiteral(EObject context, RuleCall ruleCall, Object value, INode node) {
	Keyword nodeLit = getLiteral(node);
	Keyword modelLit = getLiteral(context, ruleCall, value);
	if (nodeLit != null && nodeLit.equals(modelLit))
		return ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL;
	return modelLit.getValue();
}
 
Example 7
Source File: EnumLiteralSerializer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String serializeAssignedEnumLiteral(EObject context, RuleCall ruleCall, Object value, INode node,
		Acceptor errorAcceptor) {
	Keyword nodeLit = getLiteral(node);
	Keyword modelLit = getLiteral(context, ruleCall, value);
	if (modelLit == null) {
		if (errorAcceptor != null)
			errorAcceptor.accept(diagnosticProvider.getInvalidEnumValueDiagnostic(context, ruleCall, value));
		return null;
	} else if (nodeLit != null && nodeLit.equals(modelLit))
		return tokenUtil.serializeNode(node);
	else
		return modelLit.getValue();
}
 
Example 8
Source File: XtendAntlrGrammarGeneratorHelper.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void _collectTokens(final Keyword it, final Set<String> tokens) {
  boolean _contains = tokens.contains(it.getValue());
  boolean _not = (!_contains);
  if (_not) {
    String _value = it.getValue();
    tokens.add(_value);
  }
}
 
Example 9
Source File: PredicatedElementTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String _toXtext(final Keyword kw) {
  String _value = kw.getValue();
  String _plus = ("\'" + _value);
  String _plus_1 = (_plus + "\'");
  String _elvis = null;
  String _cardinality = kw.getCardinality();
  if (_cardinality != null) {
    _elvis = _cardinality;
  } else {
    _elvis = "";
  }
  return (_plus_1 + _elvis);
}
 
Example 10
Source File: XtextLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
String text(Keyword object) {
	return "'" + object.getValue() + "'";
}
 
Example 11
Source File: Xtext2RailroadFactory.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public ISegmentFigure createNodeSegment(Keyword keyword) {
	NodeSegment nodeSegment = new NodeSegment(keyword, NodeType.RECTANGLE, keyword.getValue(), primitiveFactory,
			getTextRegion(keyword));
	Assignment containingAssignment = GrammarUtil.containingAssignment(keyword);
	return wrapCardinalitySegments(containingAssignment != null ? containingAssignment :keyword, nodeSegment);
}
 
Example 12
Source File: AbstractContentProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected StyledString getKeywordDisplayString(Keyword keyword) {
	return new StyledString(keyword.getValue());
}
 
Example 13
Source File: SCTUserHelpDocumentationProvider.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected String getHelpId(Keyword keyword) {
	return getContextId() + "_" + keyword.getValue();
}
 
Example 14
Source File: XtextLocationInFileProvider.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected boolean useKeyword(Keyword keyword, EObject context) {
	String value = keyword.getValue();
	return value.matches("\\w+");
}
 
Example 15
Source File: AbstractKeywordSerializer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public String serializeAssignedKeyword(EObject context, Keyword keyword, Object value, INode node) {
	if (node != null && node.getGrammarElement() == keyword)
		return ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL;
	return keyword.getValue();
}
 
Example 16
Source File: AbstractKeywordSerializer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public String serializeUnassignedKeyword(EObject context, Keyword keyword, INode node) {
	if (node != null && node.getGrammarElement() == keyword)
		return ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL;
	return keyword.getValue();
}
 
Example 17
Source File: FormatScopeNameProvider.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public String caseKeyword(final Keyword object) {
  return '"' + object.getValue() + '"';
}
 
Example 18
Source File: KeywordAlternativeConverter.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected String keywordToString(Keyword keyword) {
	return keyword.getValue();
}
 
Example 19
Source File: KeywordBasedValueConverter.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected String keywordToString(Keyword keyword) {
	return keyword.getValue();
}
 
Example 20
Source File: TerminalRuleInterpreter.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRuleInterpreter(Keyword keyword) {
	this(keyword.getValue());
}