use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class N4JSResourceDescription method getImportedNames.
@Override
public Iterable<QualifiedName> getImportedNames() {
if (null == lazyImportedNames) {
synchronized (this) {
if (null == lazyImportedNames) {
// get imported names collected during global scoping
// the scope provider registers every request in scoping so that by this
// also all names are collected that cannot be resolved
Iterable<QualifiedName> superImportedNames = super.getImportedNames();
// use sorted set to ensure order of items
final SortedSet<QualifiedName> importedNames;
if (superImportedNames != null) {
importedNames = Sets.newTreeSet(superImportedNames);
} else {
importedNames = Sets.<QualifiedName>newTreeSet();
}
// import our own module name to get a proper change notification
Resource resource = getResource();
List<EObject> contents = resource.getContents();
if (contents.size() > 1) {
TModule module = (TModule) contents.get(1);
importedNames.add(qualifiedNameProvider.getFullyQualifiedName(module));
}
final Set<EObject> crossRefTypes = Sets.newHashSet();
IAcceptor<EObject> acceptor = getCrossRefTypeAcceptor(crossRefTypes);
crossReferenceComputer.computeCrossRefs(resource, acceptor);
for (EObject type : crossRefTypes) {
if (type instanceof Type) {
handleType(importedNames, type);
} else if (type instanceof TVariable) {
handleTVariable(importedNames, (TVariable) type);
} else if (type instanceof TEnumLiteral) {
handleTEnumLiteral(importedNames, (TEnumLiteral) type);
}
}
this.lazyImportedNames = importedNames;
}
}
}
return lazyImportedNames;
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class N4JSResourceDescription method getCrossRefTypeAcceptor.
private IAcceptor<EObject> getCrossRefTypeAcceptor(final Set<EObject> crossRefTypesAddHere) {
IAcceptor<EObject> acceptor = new IAcceptor<EObject>() {
@Override
public void accept(EObject to) {
if (to instanceof Type || to instanceof TVariable || to instanceof TEnumLiteral) {
crossRefTypesAddHere.add(to);
}
// Add declared type of a field to cross ref types
if (to instanceof TFunction) {
TypeRef returnTypeRef = ((TFunction) to).getReturnTypeRef();
crossRefTypesAddHere.add(returnTypeRef.getDeclaredType());
}
if (to instanceof TField) {
TypeRef typeRef = ((TField) to).getTypeRef();
crossRefTypesAddHere.add(typeRef.getDeclaredType());
}
// In case of TMember, add the containing type as well
if (to instanceof TMember) {
TMember casted = (TMember) to;
ContainerType<?> declaringType = casted.getContainingType();
crossRefTypesAddHere.add(declaringType);
}
}
};
return acceptor;
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class N4JSResourceDescriptionStrategy method createEObjectDescriptions.
@Override
public boolean createEObjectDescriptions(final EObject eObject, IAcceptor<IEObjectDescription> acceptor) {
if (getQualifiedNameProvider() == null)
return false;
if (eObject instanceof TModule) {
TModule module = (TModule) eObject;
internalCreateEObjectDescriptionForRoot(module, acceptor);
for (Type type : module.getTopLevelTypes()) {
internalCreateEObjectDescription(type, acceptor);
}
for (TVariable variable : module.getVariables()) {
internalCreateEObjectDescription(variable, acceptor);
}
}
// export is only possible for top-level elements
return false;
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class TypeVisibilityChecker method isProjectVisible.
private boolean isProjectVisible(Resource contextResource, URI elementLocation) {
URI moduleURI = getURI(contextResource);
if (moduleURI.isPlatformResource() && elementLocation.isPlatformResource()) {
// Not valid for PUBLIC_INTERNAL
final boolean visible = moduleURI.segment(1).equals(elementLocation.segment(1));
// TODO IDEBUG-640 this needs to be reviewed again, since the refactoring made here are invalid.
if (visible) {
return true;
} else {
if (getTestedProjects(getURI(contextResource)).isEmpty()) {
return false;
}
// $FALL-THROUGH$ if the project for the context resource has a host project.
}
} else {
ResourceSet resourceSet = contextResource.getResourceSet();
EObject loadedType = resourceSet.getEObject(elementLocation, false);
if (loadedType == null) {
loadedType = resourceSet.getEObject(elementLocation, true);
}
if (loadedType instanceof Type) {
// delegate to the *real* impl
return isVisible(contextResource, TypeAccessModifier.PROJECT, (Type) loadedType).visibility;
}
}
return false;
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class N4JSMemberRedefinitionValidator method checkSpecConstructorOverrideCompatibility.
private boolean checkSpecConstructorOverrideCompatibility(TClassifier tClassifier, TMethod inheritedConstructor) {
final Type rightThisContext = MemberRedefinitionUtils.findThisContextForConstructor(tClassifier, inheritedConstructor);
final Result<Boolean> subtypeResult = isSubTypeResult(inheritedConstructor, rightThisContext, inheritedConstructor);
if (subtypeResult.failed()) {
final String msg = getMessageForCLF_PSEUDO_REDEFINED_SPEC_CTOR_INCOMPATIBLE(validatorMessageHelper.description(inheritedConstructor), validatorMessageHelper.description(tClassifier), validatorMessageHelper.description(rightThisContext));
// ok, because tClassifier is coming from AST
final EObject astNode = tClassifier.getAstElement();
addIssue(msg, astNode, N4JSPackage.eINSTANCE.getN4TypeDeclaration_Name(), CLF_PSEUDO_REDEFINED_SPEC_CTOR_INCOMPATIBLE);
return false;
}
return true;
}
Aggregations