Java Code Examples for org.eclipse.xtext.Keyword

The following examples show how to use org.eclipse.xtext.Keyword. 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
/**
 * Syntax: '('*
 */
@Override
protected void emit_XParenthesizedExpression_LeftParenthesisKeyword_0_a(EObject semanticObject,
		ISynNavigable transition, List<INode> nodes) {

	Keyword kw = grammarAccess.getXParenthesizedExpressionAccess().getLeftParenthesisKeyword_0();

	if (nodes == null) {
		if (semanticObject instanceof XIfExpression || semanticObject instanceof XTryCatchFinallyExpression) {
			EObject cnt = semanticObject.eContainer();
			if (cnt instanceof XExpression && !(cnt instanceof XBlockExpression)
					&& !(cnt instanceof XForLoopExpression))
				acceptUnassignedKeyword(kw, kw.getValue(), null);
		}
		if (semanticObject instanceof XConstructorCall) {
			XConstructorCall call = (XConstructorCall) semanticObject;
			if (!call.isExplicitConstructorCall() && call.getArguments().isEmpty()) {
				acceptUnassignedKeyword(kw, kw.getValue(), null);
			}
		}
	}
	acceptNodes(transition, nodes);
}
 
Example 3
public void collectTokens(final EObject it, final List<String> known) {
  if (it instanceof Keyword) {
    _collectTokens((Keyword)it, known);
    return;
  } else if (it instanceof AbstractRule) {
    _collectTokens((AbstractRule)it, known);
    return;
  } else if (it != null) {
    _collectTokens(it, known);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, known).toString());
  }
}
 
Example 4
Source Project: xtext-core   Source File: SequenceFeeder.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public void accept(Keyword keyword, Object value, int indexInFeature, int indexInNonTransient) {
	Assignment ass = getAssignment(keyword);
	EStructuralFeature feature = getFeature(ass.getFeature());
	assertIndex(feature, indexInFeature);
	assertIndex(feature, indexInNonTransient);
	assertValue(feature, value);
	ILeafNode node = getLeafNode(feature, indexInFeature, indexInNonTransient, value);
	String token = getToken(keyword, value, node);
	acceptKeyword(ass, keyword, value, token, indexInFeature, node);
}
 
Example 5
@Override
protected void emit_ModelThing_ThingKeyword_0_q(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
    ILeafNode node = nodes != null && nodes.size() == 1 && nodes.get(0) instanceof ILeafNode ? (ILeafNode) nodes
            .get(0) : null;
    Keyword keyword = grammarAccess.getModelThingAccess().getThingKeyword_0();
    acceptUnassignedKeyword(keyword, keyword.getValue(), node);
}
 
Example 6
Source Project: sarl   Source File: BugSinglelineCommentIndentation.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean detectBugSituation(IHiddenRegion hiddenRegion) {
	if (hiddenRegion != null) {
		final ISemanticRegion semanticRegion = hiddenRegion.getNextSemanticRegion();
		if (semanticRegion != null) {
			final EObject element = semanticRegion.getGrammarElement();
			if (element instanceof Keyword
					&& Strings.equal(((Keyword) element).getValue(), "}")) { //$NON-NLS-1$
				return true;
			}
		}
	}
	return false;
}
 
Example 7
public void completeClassicFacet_Key(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	if (assignment.getTerminal() instanceof RuleCall) {
		completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
	}
	if (assignment.getTerminal() instanceof Keyword) {
		// subclasses may override
	}
}
 
Example 8
Source Project: xtext-core   Source File: XtextValidator.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkKeywordNotEmpty(final Keyword keyword) {
	if (keyword.getValue().length()==0 && !(keyword.eContainer() instanceof EnumLiteralDeclaration)) {
		addIssue("A keyword cannot be empty.", 
				keyword, 
				null,
				EMPTY_KEYWORD);
	}
}
 
Example 9
@Override
public void completeKeyword(Keyword keyword, ContentAssistContext contentAssistContext,
		ICompletionProposalAcceptor acceptor) {
	if (isKeywordWorthyToPropose(keyword, contentAssistContext)) {
		super.completeKeyword(keyword, contentAssistContext, acceptor);
	}
}
 
Example 10
Source Project: xtext-core   Source File: AbstractPackratParser.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Override
public int consumeKeyword(Keyword keyword, String feature, boolean isMany, boolean isBoolean, ICharacterClass notFollowedBy, boolean optional) {
	keywordConsumer.configure(keyword, notFollowedBy);
	return consumeTerminal(keywordConsumer, feature, isMany, isBoolean, keyword, ISequenceMatcher.Factory.nullMatcher(), optional);
}
 
Example 11
Source Project: dsl-devkit   Source File: CheckFormatter.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * General formatting configuration. Delegates formatting configuration to individual grammar elements.
 *
 * @param configuration
 *          formating configuration
 * @param access
 *          grammarAccess
 */
private void configure(final FormattingConfig configuration, final CheckGrammarAccess access) {

  super.configure(configuration, access.getXbaseWithAnnotationsGrammarAccess());

  // Common curly brackets handling (for check grammar only)
  List<Pair<Keyword, Keyword>> curlyPairs = access.findKeywordPairs("{", "}"); //$NON-NLS-1$ //$NON-NLS-2$
  for (Pair<Keyword, Keyword> pair : curlyPairs) {
    if (EcoreUtil2.getContainerOfType(pair.getFirst(), GrammarImpl.class).getName().equals(CheckConstants.GRAMMAR)) {
      configuration.setLinewrap().after(pair.getFirst());
      configuration.setIndentation(pair.getFirst(), pair.getSecond());
      configuration.setLinewrap().before(pair.getSecond());
    }
  }

  // AutoLineWrap
  configuration.setAutoLinewrap(LINE_WRAP_LENGTH);

  // Comments
  configuration.setLinewrap(0, 1, 2).before(access.getSL_COMMENTRule());
  configuration.setLinewrap(1, 1, 2).before(access.getML_COMMENTRule());
  configuration.setLinewrap(1, 1, 1).after(access.getML_COMMENTRule());

  // Rules
  configuration.setLinewrap(1, 1, 2).before(access.getXImportDeclarationRule());
  configuration.setLinewrap(1, 2, 2).before(access.getCategoryRule());
  configuration.setLinewrap(1, 2, 2).before(access.getImplementationRule());
  configuration.setLinewrap(1, 2, 2).before(access.getCheckRule());
  configuration.setLinewrap(1, 1, 2).before(access.getXGuardExpressionRule());
  configuration.setLinewrap(1, 1, 2).before(access.getXIssueExpressionRule());
  configuration.setLinewrap(1, 1, 2).before(access.getXIfExpressionRule());
  configuration.setLinewrap(1, 1, 2).before(access.getXVariableDeclarationRule());

  // Rule elements
  configureFeatureCall(configuration, access.getXMemberFeatureCallAccess());
  configureCheckCatalog(configuration, access.getCheckCatalogAccess());
  configureSeverityRange(configuration, access.getSeverityRangeAccess());
  configureCheck(configuration, access.getCheckAccess());
  configureXIssueExpression(configuration, access.getXIssueExpressionAccess());
  configureCheckContext(configuration, access.getContextAccess());
}
 
Example 12
protected boolean isKeywordWorthyToPropose(Keyword keyword) {
	return keyword.getValue().length() > 1 && Character.isLetter(keyword.getValue().charAt(0));
}
 
Example 13
Source Project: xtext-core   Source File: HiddenTokenSequencer.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void acceptAssignedKeyword(Keyword keyword, String token, Object value, int index, ILeafNode node) {
	emitHiddenTokens(getHiddenNodesBetween(lastNode, node));
	lastNode = node;
	delegate.acceptAssignedKeyword(keyword, token, value, index, node);
}
 
Example 14
@Override
public String caseKeyword(final Keyword object) {
  return '"' + object.getValue() + '"';
}
 
Example 15
Source Project: xtext-core   Source File: XtextSemanticSequencer.java    License: Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Contexts:
 *     PredicatedKeyword returns Keyword
 *
 * Constraint:
 *     ((predicated?='=>' | firstSetPredicated?='->') value=STRING)
 */
protected void sequence_PredicatedKeyword(ISerializationContext context, Keyword semanticObject) {
	genericSequencer.createSequence(context, semanticObject);
}
 
Example 16
public Keyword getDetailDetailKeyword_2_0() { return cDetailDetailKeyword_2_0; } 
Example 17
public Keyword getFragmentKeyword_1_0() { return cFragmentKeyword_1_0; } 
Example 18
public Keyword getRightSquareBracketKeyword_1_5() { return cRightSquareBracketKeyword_1_5; } 
Example 19
public Keyword getKw2Keyword_4() { return cKw2Keyword_4; } 
Example 20
public Keyword getSemicolonKeyword_2_2() { return cSemicolonKeyword_2_2; } 
Example 21
public Keyword getOptionalLoopKeyword_5_6_0() { return cOptionalLoopKeyword_5_6_0; } 
Example 22
public Keyword getLeftCurlyBracketKeyword_2_0() { return cLeftCurlyBracketKeyword_2_0; } 
Example 23
public Keyword getEqualsSignKeyword_1_1_1() { return cEqualsSignKeyword_1_1_1; } 
Example 24
public Keyword getRightSquareBracketKeyword_2_2() { return cRightSquareBracketKeyword_2_2; } 
Example 25
public Keyword getCommaKeyword_5_2_0() { return cCommaKeyword_5_2_0; } 
Example 26
public Keyword getColonKeyword_1() { return cColonKeyword_1; } 
Example 27
public Keyword getSemicolonKeyword_5_0_2() { return cSemicolonKeyword_5_0_2; } 
Example 28
public Keyword getKw1Keyword_1_1_0() { return cKw1Keyword_1_1_0; } 
Example 29
public Keyword getRightCurlyBracketKeyword_3() { return cRightCurlyBracketKeyword_3; } 
Example 30
public Keyword getFunctionNamePlusSignPlusSignKeyword_1_1_0_1() { return cFunctionNamePlusSignPlusSignKeyword_1_1_0_1; }