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: 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 #2
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 #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: 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 #5
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 #6
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 #7
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 #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: 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 #10
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 #11
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 #12
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 #13
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 #14
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 #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: TwoParametersTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Keyword getNumberSignDigitFourKeyword_1_3_0() { return cNumberSignDigitFourKeyword_1_3_0; } 
Example #18
Source File: XtypeGrammarAccess.java    From xtext-extras with Eclipse Public License 2.0 votes vote down vote up
public Keyword getSuperKeyword_0() { return cSuperKeyword_0; } 
Example #19
Source File: LocationProviderTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Keyword getModesKeyword_1_0() { return cModesKeyword_1_0; } 
Example #20
Source File: SequencerTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Keyword getNumberSignDigitOneDigitFourKeyword_0() { return cNumberSignDigitOneDigitFourKeyword_0; } 
Example #21
Source File: Bug287941TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Keyword getRightCurlyBracketKeyword_4() { return cRightCurlyBracketKeyword_4; } 
Example #22
Source File: KeywordsTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Keyword getFifthAKeyword_4_0() { return cFifthAKeyword_4_0; } 
Example #23
Source File: ParametersTestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Keyword getNumberSignDigitOneDigitTwoKeyword_1_11_0() { return cNumberSignDigitOneDigitTwoKeyword_1_11_0; } 
Example #24
Source File: NoParametersTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Keyword getKeywordKeyword_1_11_1_1_1() { return cKeywordKeyword_1_11_1_1_1; } 
Example #25
Source File: XtextTerminalsTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Keyword getOperatorQuestionMarkEqualsSignKeyword_1_0_2() { return cOperatorQuestionMarkEqualsSignKeyword_1_0_2; } 
Example #26
Source File: FragmentTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Keyword getColonKeyword_1_0_0() { return cColonKeyword_1_0_0; } 
Example #27
Source File: Bug348427TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Keyword getStringBKeyword_3_1_0() { return cStringBKeyword_3_1_0; } 
Example #28
Source File: UnorderedGroupsTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Keyword getDigitTwoKeyword_1_0() { return cDigitTwoKeyword_1_0; } 
Example #29
Source File: SemverGrammarAccess.java    From n4js with Eclipse Public License 1.0 votes vote down vote up
public Keyword getPlusSignKeyword_1_1() { return cPlusSignKeyword_1_1; } 
Example #30
Source File: TypeExpressionsGrammarAccess.java    From n4js with Eclipse Public License 1.0 votes vote down vote up
public Keyword getCommaKeyword_2_0() { return cCommaKeyword_2_0; }