Java Code Examples for org.eclipse.xtext.EcoreUtil2#getAllContentsOfType()

The following examples show how to use org.eclipse.xtext.EcoreUtil2#getAllContentsOfType() . 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: ASTUtils.java    From balzac with Apache License 2.0 6 votes vote down vote up
public NetworkType networkParams(EObject obj) {
    List<Network> list = EcoreUtil2.getAllContentsOfType(EcoreUtil2.getRootContainer(obj), Network.class);

    if (list.size() == 0) // network undeclared, assume testnet
        return NetworkType.TESTNET;

    if (list.size() == 1) {
        Network net = list.get(0);

        if (net.isTestnet())
            return NetworkType.TESTNET;

        if (net.isMainnet())
            return NetworkType.MAINNET;
    }

    throw new IllegalStateException();
}
 
Example 2
Source File: SoliditySemanticHighlighter.java    From solidity-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void provideHighLightForNamedElement(NamedElement namedElement, INode nextNode, String textStyle,
		IHighlightedPositionAcceptor acceptor) {
	acceptor.addPosition(nextNode.getOffset(), nextNode.getLength(), textStyle);
	List<ElementReferenceExpression> references = EcoreUtil2.getAllContentsOfType(namedElement.eContainer(),
			ElementReferenceExpression.class);
	for (ElementReferenceExpression elementReferenceExpression : references) {
		EObject reference = elementReferenceExpression.getReference();
		if (reference.equals(namedElement)) {
			ICompositeNode referencingNode = NodeModelUtils.findActualNodeFor(elementReferenceExpression);
			BidiIterator<INode> bidiIterator = referencingNode.getChildren().iterator();
			while (bidiIterator.hasNext()) {
				INode currentNode = bidiIterator.next();
				if (currentNode.getText().trim().equals(namedElement.getName())) {
					acceptor.addPosition(currentNode.getOffset(), currentNode.getLength(), textStyle);
				}
			}
		}
	}
}
 
Example 3
Source File: QuickfixCrossrefTestLanguageValidator.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Check(CheckType.FAST)
public void checkBadNames(Main main) {
	Resource res = main.eResource();
	for (Element root : main.getElements()) {
		List<String> fragments = Lists.newArrayList();
		for (Element ele : EcoreUtil2.getAllContentsOfType(root, Element.class)) {
			if ("badname".equals(ele.getName())) {
				fragments.add(res.getURIFragment(ele));
			}
		}
		if (!fragments.isEmpty()) {
			warning(BAD_NAME_IN_SUBELEMENTS, root, QuickfixCrossrefPackage.Literals.ELEMENT__NAME,
					ValidationMessageAcceptor.INSIGNIFICANT_INDEX, BAD_NAME_IN_SUBELEMENTS, Joiner.on(";").join(fragments));
		}
	}
}
 
Example 4
Source File: Utils.java    From sarl with Apache License 2.0 6 votes vote down vote up
private static boolean hasLocalParameters(EObject current, XExpression container, List<JvmFormalParameter> containerParameters) {
	if (current instanceof XAbstractFeatureCall) {
		final XAbstractFeatureCall featureCall = (XAbstractFeatureCall) current;
		if (isLocalEntity(featureCall, container, containerParameters)) {
			return true;
		}
		for (final XExpression argument : featureCall.getActualArguments()) {
			final Iterable<XAbstractFeatureCall> iterable;
			if (argument instanceof XAbstractFeatureCall) {
				iterable = Iterables.concat(
						Collections.singletonList((XAbstractFeatureCall) argument),
						EcoreUtil2.getAllContentsOfType(argument, XAbstractFeatureCall.class));
			} else {
				iterable = EcoreUtil2.getAllContentsOfType(argument, XAbstractFeatureCall.class);
			}
			for (final XAbstractFeatureCall c : iterable) {
				if (isLocalEntity(c, container, containerParameters)) {
					return true;
				}
			}
		}
	}
	return false;
}
 
Example 5
Source File: DocumentationMenuAction.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
	IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
			.getActiveEditor();
	if (activeEditor instanceof StatechartDiagramEditor) {
		Diagram diagram = ((StatechartDiagramEditor) activeEditor).getDiagram();
		List<View> result = EcoreUtil2.getAllContentsOfType(diagram, View.class);
		ToggleShowDocumentationCommand.toggleDocumentation(result);
	}
}
 
Example 6
Source File: StextImportAwareScopeProvider.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(final EObject context, boolean ignoreCase) {
	List<ImportNormalizer> importedNamespaceResolvers = Lists.newArrayList();
	List<ImportScope> importScopes = null;
	if (context instanceof StateSpecification || context instanceof TransitionSpecification) {
		importScopes = EcoreUtil2.getAllContentsOfType(utils.getStatechart(context), ImportScope.class);
	} else {
		importScopes = EcoreUtil2.getAllContentsOfType(context, ImportScope.class);
	}
	for (ImportScope scope : importScopes) {
		importedNamespaceResolvers.addAll(createNamespaceResolver(scope, ignoreCase));
	}
	return importedNamespaceResolvers;
}
 
Example 7
Source File: DocumentationDropDownAction.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public void run() {
	IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
			.getActiveEditor();
	if (activeEditor instanceof StatechartDiagramEditor) {
		Diagram diagram = ((StatechartDiagramEditor) activeEditor).getDiagram();
		List<View> result = EcoreUtil2.getAllContentsOfType(diagram, View.class);
		show(result);
	}
}
 
Example 8
Source File: RefactoringTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected State getStateByName(Statechart statechart, String name) {
	List<State> allStates = EcoreUtil2.getAllContentsOfType(statechart, State.class);
	for (State state : allStates) {
		if (state.getName().equals(name)) {
			return state;
		}
	}
	return null;
}
 
Example 9
Source File: PyExpressionGenerator.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
protected void before(XExpression expression, IAppendable output, IExtraLanguageGeneratorContext context) {
	if (!(expression instanceof XClosure) && !(expression instanceof AnonymousClass)) {
		// Generate the closure definitions before their usage in the expressions
		for (final XClosure closure : EcoreUtil2.getAllContentsOfType(expression, XClosure.class)) {
			generateClosureDefinition(closure, output, context);
		}
		// Generate the closure definitions before their usage in the expressions
		for (final AnonymousClass anonClass : EcoreUtil2.getAllContentsOfType(expression, AnonymousClass.class)) {
			generateAnonymousClassDefinition(anonClass, output, context);
		}
	}
}
 
Example 10
Source File: SARLValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean isInitialized(JvmField input) {
	if (super.isInitialized(input)) {
		return true;
	}
	// Check initialization into a static constructor.
	final XtendField sarlField = (XtendField) this.associations.getPrimarySourceElement(input);
	if (sarlField == null) {
		return false;
	}
	final XtendTypeDeclaration declaringType = sarlField.getDeclaringType();
	if (declaringType == null) {
		return false;
	}
	for (final XtendConstructor staticConstructor : Iterables.filter(Iterables.filter(
			declaringType.getMembers(), XtendConstructor.class), it -> it.isStatic())) {
		if (staticConstructor.getExpression() != null) {
			for (final XAssignment assign : EcoreUtil2.getAllContentsOfType(staticConstructor.getExpression(), XAssignment.class)) {
				if (assign.isStatic() && Strings.equal(input.getIdentifier(), assign.getFeature().getIdentifier())) {
					// Mark the field as initialized in order to be faster during the next initialization test.
					this.readAndWriteTracking.markInitialized(input, null);
					return true;
				}
			}
		}
	}
	return false;
}
 
Example 11
Source File: TypeHierarchyHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void reportError(EClassifierInfo info, TransformationErrorCode errorCode, String message) {
	if (grammar == null) {
		reportError(errorCode, message, null);
		return;
	}
	List<TypeRef> typeRefs = EcoreUtil2.getAllContentsOfType(grammar, TypeRef.class);
	for(TypeRef typeRef: typeRefs) {
		EClassifierInfo otherInfo = infos.getInfo(typeRef);
		if (otherInfo == info)
			reportError(errorCode, message, typeRef);
	}
}
 
Example 12
Source File: GuardStructure.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private List<Guard> getGuardList() {
	LinkedList<Guard> gList = new LinkedList<>();
	List<Expression> allExpressions = EcoreUtil2.getAllContentsOfType(condition, Expression.class);
	allExpressions.add(condition);
	EObject conditionContainer = condition.eContainer();

	for (Expression expr : allExpressions) {
		Guard guard = GuardFactory.create(conditionContainer, expr, negate);
		if (guard != null) {
			gList.add(guard);
		}
	}
	return gList;
}
 
Example 13
Source File: RenameElementHandler.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public NameUniquenessValidator(NamedElement element) {
	existingNames = Lists.newArrayList();
	Scope scope = EcoreUtil2.getContainerOfType(element, Scope.class);
	List<? extends NamedElement> allOfSameType = EcoreUtil2.getAllContentsOfType(scope, NamedElement.class);
	allOfSameType.remove(element);
	for (NamedElement namedElement : allOfSameType) {
		existingNames.add(namedElement.getName());
	}
}
 
Example 14
Source File: ParseTreeConstructorUtil.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private static List<CrossReference> getCrossReferencesWithSameEReference(CrossReference cr) {
	Grammar g = GrammarUtil.getGrammar(cr);
	EReference ref = GrammarUtil.getReference(cr);
	List<CrossReference> result = Lists.newArrayList();
	for (CrossReference c : EcoreUtil2.getAllContentsOfType(g, CrossReference.class))
		if (GrammarUtil.getReference(c) == ref)
			result.add(c);
	return result;
}
 
Example 15
Source File: SolidityIssueCreator.java    From solidity-ide with Eclipse Public License 1.0 5 votes vote down vote up
protected EObject getEObject(File errorFile, int offset, EObject currentObject) {
	Resource resource = currentObject.eResource();
	if (offset == 0) {
		EList<EObject> resourceContent = resource.getContents();
		if (!resourceContent.isEmpty()) {
			EObject object = resourceContent.get(0);
			List<Package> packages = EcoreUtil2.getAllContentsOfType(object, Package.class);
			if (!packages.isEmpty()) {
				return packages.get(0);
			}
		}
	}
	return offsetHelper.resolveContainedElementAt((XtextResource) resource, offset);
}
 
Example 16
Source File: SARLOperationHelper.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static boolean isLocalExpression(XExpression expression, ISideEffectContext context, boolean dereference) {
	if (expression == null) {
		return true;
	}
	if (expression instanceof XAbstractFeatureCall) {
		return isLocalExpression((XAbstractFeatureCall) expression, context, dereference);
	}
	for (final XAbstractFeatureCall featureCall : EcoreUtil2.getAllContentsOfType(expression, XAbstractFeatureCall.class)) {
		if (!isLocalExpression(featureCall, context, dereference)) {
			return false;
		}
	}
	return true;
}
 
Example 17
Source File: SoliditySemanticHighlighter.java    From solidity-ide with Eclipse Public License 1.0 5 votes vote down vote up
private void provideHighligtingFor(Block block, IHighlightedPositionAcceptor acceptor) {
	List<VariableDefinition> variableDefinitions = EcoreUtil2.getAllContentsOfType(block, VariableDefinition.class);
	for (VariableDefinition variableDefinition : variableDefinitions) {
		provideHighLightForNamedElement(variableDefinition, SolidityHighlightingConfiguration.FUNCTION_PARAMETER,
				acceptor);
	}
}
 
Example 18
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Check
public void checkNegatedTokenNotEOF(NegatedToken token) {
	for (EOF eof : EcoreUtil2.getAllContentsOfType(token, EOF.class)) {
		error("It is not possible to negate EOF", eof, null);
	}
}
 
Example 19
Source File: GrammarParserTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
private void checkEnums(Grammar grammar) {
	List<EnumLiteralDeclaration> decls = EcoreUtil2.getAllContentsOfType(grammar, EnumLiteralDeclaration.class);
	for(EnumLiteralDeclaration decl: decls) {
		assertNotNull(decl.getLiteral());
	}
}
 
Example 20
Source File: LambdaTypeVariableFinder.java    From xsemantics with Eclipse Public License 1.0 4 votes vote down vote up
public List<TypeVariable> findTypeVariables(EObject term) {
	return EcoreUtil2.getAllContentsOfType(term, TypeVariable.class);
}