Java Code Examples for org.eclipse.xtext.EcoreUtil2#eAllContents()
The following examples show how to use
org.eclipse.xtext.EcoreUtil2#eAllContents() .
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: TokenTypeRewriter.java From n4js with Eclipse Public License 1.0 | 6 votes |
private static void rewriteKeywords(AbstractRule rule, N4JSKeywords keywords, ImmutableMap.Builder<AbstractElement, Integer> builder) { for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) { if (obj instanceof Keyword) { Keyword keyword = (Keyword) obj; Integer type = keywords.getTokenType(keyword); if (type != null) { if (keyword.eContainer() instanceof EnumLiteralDeclaration) { builder.put((AbstractElement) keyword.eContainer(), type); } else { builder.put(keyword, type); } } } } }
Example 2
Source File: TokenTypeRewriter.java From n4js with Eclipse Public License 1.0 | 6 votes |
private static void rewriteTypeReferences(N4JSGrammarAccess ga, ImmutableMap.Builder<AbstractElement, Integer> builder) { for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) { for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) { if (obj instanceof Assignment) { Assignment assignment = (Assignment) obj; AbstractElement terminal = assignment.getTerminal(); if (terminal instanceof RuleCall) { AbstractRule calledRule = ((RuleCall) terminal).getRule(); EClassifier classifier = calledRule.getType().getClassifier(); if (classifier instanceof EClass && TypeRefsPackage.Literals.TYPE_REF.isSuperTypeOf((EClass) classifier)) { builder.put(assignment, TYPE_REF_TOKEN); } } } } } }
Example 3
Source File: TokenTypeRewriter.java From n4js with Eclipse Public License 1.0 | 6 votes |
private static void rewriteIdentifiers(N4JSGrammarAccess ga, ImmutableMap.Builder<AbstractElement, Integer> builder) { ImmutableSet<AbstractRule> identifierRules = ImmutableSet.of( ga.getBindingIdentifierRule(), ga.getIdentifierNameRule(), ga.getIDENTIFIERRule()); for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) { for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) { if (obj instanceof Assignment) { Assignment assignment = (Assignment) obj; AbstractElement terminal = assignment.getTerminal(); int type = InternalN4JSParser.RULE_IDENTIFIER; if (terminal instanceof CrossReference) { terminal = ((CrossReference) terminal).getTerminal(); type = IDENTIFIER_REF_TOKEN; } if (terminal instanceof RuleCall) { AbstractRule calledRule = ((RuleCall) terminal).getRule(); if (identifierRules.contains(calledRule)) { builder.put(assignment, type); } } } } } }
Example 4
Source File: TokenTypeRewriter.java From n4js with Eclipse Public License 1.0 | 6 votes |
private static void rewriteNumberLiterals(N4JSGrammarAccess ga, ImmutableMap.Builder<AbstractElement, Integer> builder) { for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) { for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) { if (obj instanceof Assignment) { Assignment assignment = (Assignment) obj; AbstractElement terminal = assignment.getTerminal(); if (terminal instanceof RuleCall) { AbstractRule calledRule = ((RuleCall) terminal).getRule(); EClassifier classifier = calledRule.getType().getClassifier(); if (classifier == EcorePackage.Literals.EBIG_DECIMAL) { builder.put(assignment, NUMBER_LITERAL_TOKEN); } } } } } }
Example 5
Source File: ExtractMethodRefactoring.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public RefactoringStatus checkInitialConditions(final IProgressMonitor pm) throws CoreException, OperationCanceledException { StatusWrapper status = statusProvider.get(); IResolvedTypes resolvedTypes = typeResolver.resolveTypes(firstExpression, new CancelIndicator() { @Override public boolean isCanceled() { return pm.isCanceled(); } }); try { Set<String> calledExternalFeatureNames = newHashSet(); returnType = calculateReturnType(resolvedTypes); if (returnType != null && !equal("void", returnType.getIdentifier())) returnExpression = lastExpression; boolean isReturnAllowed = isEndOfOriginalMethod(); for (EObject element : EcoreUtil2.eAllContents(originalMethod.getExpression())) { if (pm.isCanceled()) { throw new OperationCanceledException(); } boolean isLocalExpression = EcoreUtil.isAncestor(expressions, element); if (element instanceof XFeatureCall) { XFeatureCall featureCall = (XFeatureCall) element; JvmIdentifiableElement feature = featureCall.getFeature(); LightweightTypeReference featureType = resolvedTypes.getActualType(featureCall); boolean isLocalFeature = EcoreUtil.isAncestor(expressions, feature); if (!isLocalFeature && isLocalExpression) { // call-out if (feature instanceof JvmFormalParameter || feature instanceof XVariableDeclaration) { if (!calledExternalFeatureNames.contains(feature.getSimpleName())) { calledExternalFeatureNames.add(feature.getSimpleName()); ParameterInfo parameterInfo = new ParameterInfo(featureType.getIdentifier(), feature.getSimpleName(), parameterInfos.size()); parameterInfos.add(parameterInfo); parameter2type.put(parameterInfo, featureType); } externalFeatureCalls.put(feature.getSimpleName(), featureCall); } } else if (isLocalFeature && !isLocalExpression) { // call-in if (returnExpression != null) { status.add(RefactoringStatus.FATAL, "Ambiguous return value: Multiple local variables are accessed in subsequent code."); break; } returnExpression = featureCall; returnType = featureType; } } else if(isLocalExpression) { if(element instanceof XReturnExpression && !isReturnAllowed) { status.add(RefactoringStatus.FATAL, "Extracting method would break control flow due to return statements."); break; } else if (element instanceof JvmTypeReference) { JvmType type = ((JvmTypeReference) element).getType(); if (type instanceof JvmTypeParameter) { JvmOperation operation = associations.getDirectlyInferredOperation(originalMethod); if (operation != null) { List<JvmTypeParameter> typeParameters = operation.getTypeParameters(); if (typeParameters.contains(type)) neededTypeParameters.add((JvmTypeParameter) type); } } } else if (element instanceof JvmFormalParameter) localFeatureNames.add(((JvmFormalParameter) element).getName()); else if (element instanceof XVariableDeclaration) localFeatureNames.add(((XVariableDeclaration) element).getIdentifier()); } } } catch (OperationCanceledException e) { throw e; } catch (Exception exc) { handleException(exc, status); } return status.getRefactoringStatus(); }
Example 6
Source File: VertexValidator.java From statecharts with Eclipse Public License 1.0 | 4 votes |
@Check(CheckType.FAST) public void checkVertexMustBeReachable(final Vertex vertex) { if (!(vertex instanceof Entry)) { final Set<Object> stateScopeSet = new HashSet<>(); for (EObject obj : EcoreUtil2.eAllContents(vertex)) { stateScopeSet.add(obj); } stateScopeSet.add(vertex); final List<Object> externalPredecessors = new ArrayList<>(); DFS dfs = new DFS() { @Override public Iterator<Object> getElementLinks(Object element) { List<Object> elements = new ArrayList<>(); if (element instanceof org.yakindu.sct.model.sgraph.State) { if (!stateScopeSet.contains(element)) { externalPredecessors.add(element); } else { elements.addAll(((org.yakindu.sct.model.sgraph.State) element).getRegions()); elements.addAll(((org.yakindu.sct.model.sgraph.State) element).getIncomingTransitions()); } } else if (element instanceof Region) { elements.addAll(((Region) element).getVertices()); } else if (element instanceof Entry) { if (!stateScopeSet.contains(element)) { externalPredecessors.add(element); } else { elements.addAll(((Entry) element).getIncomingTransitions()); } } else if (element instanceof Vertex) { elements.addAll(((Vertex) element).getIncomingTransitions()); } else if (element instanceof Transition) { elements.add(((Transition) element).getSource()); } return elements.iterator(); } }; dfs.perform(vertex); if (externalPredecessors.size() == 0) { error(VERTEX_MUST_BE_REACHABLE_MSG, vertex, null, -1, VERTEX_MUST_BE_REACHABLE_CODE); } } }