Java Code Examples for org.eclipse.xtext.Assignment#getFeature()
The following examples show how to use
org.eclipse.xtext.Assignment#getFeature() .
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: AbstractEObjectRegion.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public EStructuralFeature getContainingFeature() { if(semanticElement.eContainer() == null) { return null; } String feature = null; if (grammarElement instanceof Action) { feature = ((Action) grammarElement).getFeature(); } else { Assignment assignment = GrammarUtil.containingAssignment(getGrammarElement()); if (assignment != null) { feature = assignment.getFeature(); } } if (feature == null) { return null; } return semanticElement.eContainer().eClass().getEStructuralFeature(feature); }
Example 2
Source File: Xtext2EcoreInterpretationContext.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public void addFeature(Assignment assignment) throws TransformationException { final String featureName = assignment.getFeature(); boolean isMultivalue = GrammarUtil.isMultipleAssignment(assignment); boolean isContainment = true; EClassifierInfo featureTypeInfo; if (GrammarUtil.isBooleanAssignment(assignment)) { checkNoFragmentRuleCall(assignment.getTerminal()); EDataType eBoolean = GrammarUtil.findEBoolean(GrammarUtil.getGrammar(assignment)); featureTypeInfo = getEClassifierInfoOrThrowException(eBoolean, assignment); isMultivalue = false; } else { AbstractElement terminal = assignment.getTerminal(); if (terminal == null) { throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable, "Cannot derive type from incomplete assignment.", assignment); } checkNoFragmentRuleCall(terminal); EClassifier type = getTerminalType(terminal); isContainment = isContainmentAssignment(assignment); featureTypeInfo = getEClassifierInfoOrThrowException(type, assignment); } addFeature(featureName, featureTypeInfo, isMultivalue, isContainment, assignment); }
Example 3
Source File: FeatureFinderUtil.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.0 */ public static EStructuralFeature getFeature(AbstractElement grammarElement, EClass owner) { Preconditions.checkNotNull(owner); if (grammarElement == null) return null; String featureName = null; if (grammarElement instanceof Action) featureName = ((Action) grammarElement).getFeature(); else { Assignment ass = GrammarUtil.containingAssignment(grammarElement); if (ass != null) featureName = ass.getFeature(); } if (featureName != null) return owner.getEStructuralFeature(featureName); return null; }
Example 4
Source File: CodetemplatesProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private String getAssignedFeature(RuleCall call) { Assignment ass = GrammarUtil.containingAssignment(call); if (ass != null) { String result = ass.getFeature(); if (result.equals(result.toLowerCase())) result = Strings.toFirstUpper(result); return result; } return null; }
Example 5
Source File: CheckProposalProvider.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Get the name assigned feature in an Assignment rule call. * * @param call * a rule call * @return the assigned feature */ private String getAssignedFeature(final RuleCall call) { Assignment ass = GrammarUtil.containingAssignment(call); if (ass != null) { String result = ass.getFeature(); if (result.equals(result.toLowerCase())) { // NOPMD result = Strings.toFirstUpper(result); } return result; } return null; }
Example 6
Source File: IdeContentProposalProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void _createProposals(Assignment assignment, ContentAssistContext context, IIdeContentProposalAcceptor acceptor) { AbstractElement terminal = assignment.getTerminal(); if (terminal instanceof CrossReference) { createProposals(terminal, context, acceptor); } else { if (terminal instanceof RuleCall) { AbstractRule rule = ((RuleCall) terminal).getRule(); if (rule instanceof TerminalRule && context.getPrefix().isEmpty()) { final String proposal; if ("STRING".equals(rule.getName())) { proposal = "\"" + assignment.getFeature() + "\""; } else { proposal = assignment.getFeature(); } ContentAssistEntry entry = proposalCreator.createProposal(proposal, context, (ContentAssistEntry it) -> { if ("STRING".equals(rule.getName())) { it.getEditPositions() .add(new TextRegion(context.getOffset() + 1, proposal.length() - 2)); it.setKind(ContentAssistEntry.KIND_TEXT); } else { it.getEditPositions().add(new TextRegion(context.getOffset(), proposal.length())); it.setKind(ContentAssistEntry.KIND_VALUE); } it.setDescription(rule.getName()); }); acceptor.accept(entry, proposalPriorities.getDefaultPriority(entry)); } } } }
Example 7
Source File: GrammarAccessExtensions.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public String localVar(final Assignment it, final AbstractElement terminal) { String _feature = it.getFeature(); String _plus = ("lv_" + _feature); String _plus_1 = (_plus + "_"); int _indexOf = this.contentsAsList(GrammarUtil.containingParserRule(it)).indexOf(it); String _plus_2 = (_plus_1 + Integer.valueOf(_indexOf)); String _plus_3 = (_plus_2 + "_"); int _indexOf_1 = EcoreUtil2.eAllContentsAsList(it).indexOf(terminal); return (_plus_3 + Integer.valueOf(_indexOf_1)); }
Example 8
Source File: GrammarConstraintProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public String getFeatureName() { if (element instanceof Action) return ((Action) element).getFeature(); Assignment assignment = GrammarUtil.containingAssignment(element); if (assignment != null) return assignment.getFeature(); return null; }
Example 9
Source File: GrammarElementTitleSwitch.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected String addAssignemnt(String result, AbstractElement ele) { if (!showAssignment) return result; Assignment ass = GrammarUtil.containingAssignment(ele); result = ass != null ? ass.getFeature() + ass.getOperator() + result : result; return addQualified(result, ele); }
Example 10
Source File: AbstractParseTreeConstructor.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override protected String serializeInternal(INode node) { if (type == null) return null; switch (type) { case CROSS_REFERENCE: String ref = crossRefSerializer.serializeCrossRef(eObjectConsumer.getEObject(), (CrossReference) element, (EObject) value, node); if (ref == null) { Assignment ass = GrammarUtil.containingAssignment(element); throw new XtextSerializationException("Could not serialize cross reference from " + EmfFormatter.objPath(eObjectConsumer.getEObject()) + "." + ass.getFeature() + " to " + EmfFormatter.objPath((EObject) value)); } return ref; case KEYWORD: return keywordSerializer.serializeAssignedKeyword(eObjectConsumer.getEObject(), ((Keyword) element), value, node); case TERMINAL_RULE_CALL: return valueSerializer.serializeAssignedValue(eObjectConsumer.getEObject(), (RuleCall) element, value, node); case ENUM_RULE_CALL: return enumLitSerializer.serializeAssignedEnumLiteral(eObjectConsumer.getEObject(), (RuleCall) element, value, node); case PARSER_RULE_CALL: return null; case DATATYPE_RULE_CALL: return valueSerializer.serializeAssignedValue(eObjectConsumer.getEObject(), (RuleCall) element, value, node); default: return null; } }
Example 11
Source File: TreeConstructionReportImpl.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected String getDiagnosticMessage(AssignmentToken token) { Assignment ass = (Assignment) token.getGrammarElement(); Object value = token.getEObjectConsumer().getConsumable(ass.getFeature(), false); if (value == null) { EStructuralFeature f = token.getEObjectConsumer().getEObject().eClass() .getEStructuralFeature(ass.getFeature()); if (f == null) return "The current object of type '" + token.getEObjectConsumer().getEObject().eClass().getName() + "' does not have a feature named '" + ass.getFeature() + "'"; String cls = f.getEContainingClass() == token.getEObjectConsumer().getEObject().eClass() ? f .getEContainingClass().getName() : f.getEContainingClass().getName() + "(" + token.getEObjectConsumer().getEObject().eClass().getName() + ")"; String feat = cls + "." + f.getName(); if (f.isMany()) { int size = ((List<?>) token.getEObjectConsumer().getEObject().eGet(f)).size(); return "All " + size + " values of " + feat + " have been consumed. " + "More are needed to continue here."; } else return feat + " is not set."; } else { ErrorAcceptor err = new ErrorAcceptor(); for (RuleCall ruleCall : GrammarUtil.containedRuleCalls(token.getGrammarElement())) { if (ruleCall.getRule() instanceof EnumRule) { if (enumSerializer.isValid(token.getEObject(), ruleCall, value, err)) return null; } else if (ruleCall.getRule().getType().getClassifier() instanceof EDataType) { if (valueSerializer.isValid(token.getEObject(), ruleCall, value, err)) return null; } } return err.getMessage(); } }
Example 12
Source File: TerminalsProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private String getAssignedFeature(RuleCall call) { Assignment ass = GrammarUtil.containingAssignment(call); if (ass != null) { String result = ass.getFeature(); if (result.equals(result.toLowerCase())) result = Strings.toFirstUpper(result); return result; } return null; }
Example 13
Source File: CodetemplatesProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public void completeNestedCrossReference(CrossReference crossReference, ContentAssistContext context, ICompletionProposalAcceptor acceptor, TemplateData data) { if (data.doCreateProposals()) { ContextTypeIdHelper helper = languageRegistry.getContextTypeIdHelper(data.language); if (helper != null) { String contextTypeId = helper.getId(data.rule); ContextTypeRegistry contextTypeRegistry = languageRegistry.getContextTypeRegistry(data.language); TemplateContextType contextType = contextTypeRegistry.getContextType(contextTypeId); TemplateVariableResolver crossRefResolver = getResolver(contextType, "CrossReference"); if (crossRefResolver != null) { Assignment assignment = (Assignment) crossReference.eContainer(); EReference reference = GrammarUtil.getReference(crossReference); if (reference != null) { String proposalText = "${" + assignment.getFeature() + ":CrossReference(" + reference.getEContainingClass().getName() + "." + reference.getName() + ")}"; StyledString displayText = new StyledString("${", StyledString.DECORATIONS_STYLER) .append(assignment.getFeature()) .append(":CrossReference(", StyledString.DECORATIONS_STYLER) .append(reference.getEContainingClass().getName() + "." + reference.getName(), StyledString.COUNTER_STYLER) .append(")}", StyledString.DECORATIONS_STYLER) .append(" - Create a new template variable", StyledString.QUALIFIER_STYLER); ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context); if (proposal instanceof ConfigurableCompletionProposal) { ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal; configurable.setSelectionStart(configurable.getReplacementOffset() + 2); configurable.setSelectionLength(assignment.getFeature().length()); configurable.setAutoInsertable(false); configurable.setSimpleLinkedMode(context.getViewer(), '\t'); configurable.setPriority(configurable.getPriority() * 2); } acceptor.accept(proposal); } } } } }
Example 14
Source File: CodetemplatesProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public void completeNestedAssignment(Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor, TemplateData data) { String proposalText = "${" + assignment.getFeature() + "}"; StyledString displayText; if (assignment.getTerminal() instanceof RuleCall) { RuleCall ruleCall = (RuleCall) assignment.getTerminal(); AbstractRule calledRule = ruleCall.getRule(); displayText = new StyledString("${", StyledString.DECORATIONS_STYLER) .append(assignment.getFeature(), null) .append("}", StyledString.DECORATIONS_STYLER) .append(" - ", StyledString.QUALIFIER_STYLER) .append(calledRule.getName(), StyledString.COUNTER_STYLER) .append(" - Create a new template variable", StyledString.QUALIFIER_STYLER); } else { displayText = new StyledString("${", StyledString.DECORATIONS_STYLER) .append(assignment.getFeature(), null) .append("}", StyledString.DECORATIONS_STYLER) .append(" - Create a new template variable", StyledString.QUALIFIER_STYLER); } ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context); if (proposal instanceof ConfigurableCompletionProposal) { ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal; configurable.setSelectionStart(configurable.getReplacementOffset() + 2); configurable.setSelectionLength(proposalText.length() - 3); configurable.setAutoInsertable(false); configurable.setSimpleLinkedMode(context.getViewer(), '\t'); configurable.setPriority(configurable.getPriority() * 2); } acceptor.accept(proposal); }
Example 15
Source File: Bug303200TestLanguageProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private String getAssignedFeature(RuleCall call) { Assignment ass = GrammarUtil.containingAssignment(call); if (ass != null) { String result = ass.getFeature(); if (result.equals(result.toLowerCase())) result = Strings.toFirstUpper(result); return result; } return null; }
Example 16
Source File: GrammarElementTitleSwitch.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public String caseAssignment(Assignment object) { String result = object.getFeature() + object.getOperator() + " " + card(object); return addQualified(result, object); }
Example 17
Source File: AntlrGrammarGenerator.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override protected String _assignmentEbnf(final AbstractElement it, final Assignment assignment, final AntlrOptions options, final boolean supportActions) { String _xifexpression = null; if (supportActions) { StringConcatenation _builder = new StringConcatenation(); String _localVar = this._grammarAccessExtensions.localVar(assignment, it); _builder.append(_localVar); _builder.append("="); String __assignmentEbnf = super._assignmentEbnf(it, assignment, options, supportActions); _builder.append(__assignmentEbnf); _builder.newLineIfNotEmpty(); _builder.append("{"); _builder.newLine(); _builder.append("\t"); _builder.append("if ($current==null) {"); _builder.newLine(); _builder.append("\t\t"); _builder.append("$current = "); CharSequence _createModelElement = this.createModelElement(assignment); _builder.append(_createModelElement, "\t\t"); _builder.append(";"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("\t"); String _setOrAdd = this._grammarAccessExtensions.setOrAdd(assignment); _builder.append(_setOrAdd, "\t"); _builder.append("WithLastConsumed($current, \""); String _feature = assignment.getFeature(); _builder.append(_feature, "\t"); _builder.append("\", "); String _localVar_1 = this._grammarAccessExtensions.localVar(assignment, it); _builder.append(_localVar_1, "\t"); { boolean _isBooleanAssignment = GrammarUtil.isBooleanAssignment(assignment); if (_isBooleanAssignment) { _builder.append(" != null"); } } _builder.append(", "); CharSequence _stringLiteral = this._grammarAccessExtensions.toStringLiteral(assignment.getTerminal()); _builder.append(_stringLiteral, "\t"); _builder.append(");"); _builder.newLineIfNotEmpty(); _builder.append("}"); _builder.newLine(); _xifexpression = _builder.toString(); } else { _xifexpression = super._assignmentEbnf(it, assignment, options, supportActions); } return _xifexpression; }
Example 18
Source File: FormatScopeNameProvider.java From dsl-devkit with Eclipse Public License 1.0 | 4 votes |
@Override public String caseAssignment(final Assignment object) { return object.getFeature(); }