mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
[xbase][validation] check for forward references to type parameters
Change-Id: I7caebcb4683e627ebf615fa47dd647742eb8ebfc
This commit is contained in:
parent
525dc13b67
commit
5ecf7c2f74
2 changed files with 54 additions and 2 deletions
|
@ -1,4 +1,3 @@
|
|||
#Wed Oct 14 22:36:24 CEST 2009
|
||||
cleanup.add_default_serial_version_id=true
|
||||
cleanup.add_generated_serial_version_id=false
|
||||
cleanup.add_missing_annotations=true
|
||||
|
@ -72,6 +71,7 @@ sp_cleanup.add_missing_deprecated_annotations=true
|
|||
sp_cleanup.add_missing_methods=false
|
||||
sp_cleanup.add_missing_nls_tags=false
|
||||
sp_cleanup.add_missing_override_annotations=true
|
||||
sp_cleanup.add_missing_override_annotations_interface_methods=false
|
||||
sp_cleanup.add_serial_version_id=false
|
||||
sp_cleanup.always_use_blocks=true
|
||||
sp_cleanup.always_use_parentheses_in_expressions=false
|
||||
|
@ -99,7 +99,7 @@ sp_cleanup.remove_private_constructors=true
|
|||
sp_cleanup.remove_trailing_whitespaces=false
|
||||
sp_cleanup.remove_trailing_whitespaces_all=true
|
||||
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
|
||||
sp_cleanup.remove_unnecessary_casts=true
|
||||
sp_cleanup.remove_unnecessary_casts=false
|
||||
sp_cleanup.remove_unnecessary_nls_tags=false
|
||||
sp_cleanup.remove_unused_imports=false
|
||||
sp_cleanup.remove_unused_local_variables=false
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
|
|||
import org.eclipse.emf.ecore.resource.URIConverter;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.emf.ecore.util.EcoreUtil;
|
||||
import org.eclipse.emf.ecore.util.InternalEList;
|
||||
import org.eclipse.xtext.linking.lazy.LazyLinkingResource;
|
||||
import org.eclipse.xtext.resource.ClassloaderClasspathUriResolver;
|
||||
import org.eclipse.xtext.util.CancelIndicator;
|
||||
|
@ -608,4 +609,55 @@ public class EcoreUtil2 extends EcoreUtil {
|
|||
return URIConverter.INSTANCE.normalize(resource.getURI());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A better performing alternative to the {@link org.eclipse.emf.ecore.util.EcoreUtil.CrossReferencer}.
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void findCrossReferences(EObject rootElement, Set<? extends EObject> targets, ElementReferenceAcceptor acceptor) {
|
||||
for(EReference ref: rootElement.eClass().getEAllReferences()) {
|
||||
if(rootElement.eIsSet(ref)) {
|
||||
if(ref.isContainment()) {
|
||||
Object content = rootElement.eGet(ref, false);
|
||||
if(ref.isMany()) {
|
||||
InternalEList<EObject> contentList = (InternalEList<EObject>) content;
|
||||
for(int i=0; i<contentList.size(); ++i) {
|
||||
EObject childElement = contentList.basicGet(i);
|
||||
if(!childElement.eIsProxy())
|
||||
findCrossReferences(childElement, targets, acceptor);
|
||||
}
|
||||
} else {
|
||||
EObject childElement = (EObject) content;
|
||||
if(!childElement.eIsProxy())
|
||||
findCrossReferences(childElement, targets, acceptor);
|
||||
}
|
||||
} else if (!ref.isContainer()) {
|
||||
Object value = rootElement.eGet(ref, false);
|
||||
if(ref.isMany()) {
|
||||
InternalEList<EObject> values = (InternalEList<EObject>) value;
|
||||
for(int i=0; i< values.size(); ++i) {
|
||||
EObject refElement = values.get(i);
|
||||
if(targets.contains(refElement)) {
|
||||
acceptor.accept(rootElement, refElement, ref, i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
EObject refElement = (EObject) value;
|
||||
if(targets.contains(refElement)) {
|
||||
acceptor.accept(rootElement, refElement, ref, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.4
|
||||
*/
|
||||
public static interface ElementReferenceAcceptor {
|
||||
void accept(EObject referrer, EObject referenced, EReference reference, int index);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue