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

The following examples show how to use org.eclipse.xtext.Keyword#getValue() . These examples are extracted from open source projects. 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
@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
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
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 Project: n4js   File: TokenTypeRewriter.java    License: 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 5
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 6
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 7
@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
@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 9
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 10
public TerminalRuleInterpreter(Keyword keyword) {
	this(keyword.getValue());
}
 
Example 11
@Override
public String caseKeyword(final Keyword object) {
  return '"' + object.getValue() + '"';
}
 
Example 12
protected String getHelpId(Keyword keyword) {
	return getContextId() + "_" + keyword.getValue();
}
 
Example 13
String text(Keyword object) {
	return "'" + object.getValue() + "'";
}
 
Example 14
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 15
protected StyledString getKeywordDisplayString(Keyword keyword) {
	return new StyledString(keyword.getValue());
}
 
Example 16
@Override
protected boolean useKeyword(Keyword keyword, EObject context) {
	String value = keyword.getValue();
	return value.matches("\\w+");
}
 
Example 17
@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 18
@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 19
protected String keywordToString(Keyword keyword) {
	return keyword.getValue();
}
 
Example 20
protected String keywordToString(Keyword keyword) {
	return keyword.getValue();
}