org.eclipse.xtext.Keyword Java Examples

The following examples show how to use org.eclipse.xtext.Keyword. 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: XbaseSyntacticSequencer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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
Source File: JFlexGeneratorFragmentTemplate.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
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 File: SequenceFeeder.java    From xtext-core with 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
Source File: ThingSyntacticSequencerExtension.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@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 File: BugSinglelineCommentIndentation.java    From sarl with 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
Source File: AbstractGamlProposalProvider.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
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 File: XtextValidator.java    From xtext-core with 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
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void completeKeyword(Keyword keyword, ContentAssistContext contentAssistContext,
		ICompletionProposalAcceptor acceptor) {
	if (isKeywordWorthyToPropose(keyword, contentAssistContext)) {
		super.completeKeyword(keyword, contentAssistContext, acceptor);
	}
}
 
Example #10
Source File: AbstractPackratParser.java    From xtext-core with 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 File: CheckFormatter.java    From dsl-devkit with 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
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean isKeywordWorthyToPropose(Keyword keyword) {
	return keyword.getValue().length() > 1 && Character.isLetter(keyword.getValue().charAt(0));
}
 
Example #13
Source File: HiddenTokenSequencer.java    From xtext-core with 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
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 #15
Source File: XtextSemanticSequencer.java    From xtext-core with 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
Source File: Bug332217TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Keyword getDetailDetailKeyword_2_0() { return cDetailDetailKeyword_2_0; } 
Example #17
Source File: ParametersTestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Keyword getFragmentKeyword_1_0() { return cFragmentKeyword_1_0; } 
Example #18
Source File: Bug303200TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Keyword getRightSquareBracketKeyword_1_5() { return cRightSquareBracketKeyword_1_5; } 
Example #19
Source File: ConcreteSyntaxValidationTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Keyword getKw2Keyword_4() { return cKw2Keyword_4; } 
Example #20
Source File: GH341TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Keyword getSemicolonKeyword_2_2() { return cSemicolonKeyword_2_2; } 
Example #21
Source File: Bug304681TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Keyword getOptionalLoopKeyword_5_6_0() { return cOptionalLoopKeyword_5_6_0; } 
Example #22
Source File: BacktrackingContentAssistTestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Keyword getLeftCurlyBracketKeyword_2_0() { return cLeftCurlyBracketKeyword_2_0; } 
Example #23
Source File: XtextGrammarTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Keyword getEqualsSignKeyword_1_1_1() { return cEqualsSignKeyword_1_1_1; } 
Example #24
Source File: Bug299395TestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Keyword getRightSquareBracketKeyword_2_2() { return cRightSquareBracketKeyword_2_2; } 
Example #25
Source File: Bug289187TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Keyword getCommaKeyword_5_2_0() { return cCommaKeyword_5_2_0; } 
Example #26
Source File: BacktrackingContentAssistTestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Keyword getColonKeyword_1() { return cColonKeyword_1; } 
Example #27
Source File: Bug304681TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Keyword getSemicolonKeyword_5_0_2() { return cSemicolonKeyword_5_0_2; } 
Example #28
Source File: SequencerTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Keyword getKw1Keyword_1_1_0() { return cKw1Keyword_1_1_0; } 
Example #29
Source File: CrossReferenceProposalTestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Keyword getRightCurlyBracketKeyword_3() { return cRightCurlyBracketKeyword_3; } 
Example #30
Source File: BeeLangTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Keyword getFunctionNamePlusSignPlusSignKeyword_1_1_0_1() { return cFunctionNamePlusSignPlusSignKeyword_1_1_0_1; }