use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class TestDiscoveryHelper method collectTestLocations.
/**
* Most clients should use method {@link #collectTests(URI...)} instead!
* <p>
* Low-level method to collect all test modules, i.e. N4JS files containing classes containing at least one method
* annotated with @Test, as {@link IResourceDescription}s.
*/
private Stream<URI> collectTestLocations(final IResourceDescriptions index, final ResourceSet resSet, final URI location) {
if (null == location) {
return Stream.empty();
}
// does location point to an N4JS project?
if (isProject(location)) {
// yes
// --> collect all test modules (files containing test classes) located in source containers of type "test"
final IN4JSProject p = n4jsCore.create(location);
return p.getSourceContainers().stream().filter(IN4JSSourceContainer::isTest).flatMap(// note: IN4JSSourceContainer is an Iterable<URI>
TestDiscoveryHelper::stream).filter(// filter out everything but N4JS files.
uri -> isTestFile(uri)).filter(uri -> isTestModule(resSet, index.getResourceDescription(uri)));
}
// does location point to an n4js file?
final IResourceDescription resDesc = index.getResourceDescription(location.trimFragment());
if (resDesc != null) {
// yes --> is it a test module? (i.e. does it contain test classes and the class is not abstract?)
if (isTestModule(resSet, resDesc)) {
// yes --> is it contained in a source container of type "test"?
final IN4JSSourceContainer srcContainer = n4jsCore.findN4JSSourceContainer(location.trimFragment()).orNull();
if (srcContainer != null && srcContainer.isTest()) {
// return location with fragment! (if any)
return Stream.of(location);
}
}
return Stream.empty();
}
// does location point to a source container (or sub-folder)?
final IN4JSSourceContainer srcContainer = n4jsCore.findN4JSSourceContainer(location).orNull();
if (srcContainer != null) {
// yes --> is this a source container of type "test"?
if (srcContainer.isTest()) {
// yes --> collect all test modules (files containing test classes) in this source container
final String locationStr = location.toString();
return // note: IN4JSSourceContainer is an Iterable<URI>
stream(srcContainer).filter(// TODO improve?
uri -> uri.toString().startsWith(locationStr)).filter(uri -> isTestModule(resSet, index.getResourceDescription(uri)));
}
return Stream.empty();
}
// invalid location URI
return Stream.empty();
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class N4JSASTUtils method isSemiLegalAssignmentToFinalFieldInCtor.
/**
* Returns true iff <code>expr</code> is a semi-legal assignment expression within a constructor to a final field of
* the same class. Here, "semi"-legal means that one requirement for a fully legal such assignment is <b>not</b>
* checked by this method: the requirement that the declaration of the assigned final field must not have an
* initializer expression. For a fully legal assignment to a final field this has to be checked by client code.
*/
public static boolean isSemiLegalAssignmentToFinalFieldInCtor(EObject expr, TMember writtenMember) {
if (!(expr instanceof AssignmentExpression))
return false;
final AssignmentExpression assExpr = (AssignmentExpression) expr;
// left-hand side must be a property access to 'this'
final Expression lhs = assExpr.getLhs();
if (!(lhs instanceof ParameterizedPropertyAccessExpression))
return false;
final ParameterizedPropertyAccessExpression paExpr = (ParameterizedPropertyAccessExpression) lhs;
if (!(paExpr.getTarget() instanceof ThisLiteral))
return false;
// BUT: check this only if we have a resolved property in paExpr (important if this method used from scoping)
if (paExpr.getProperty() != null && !paExpr.getProperty().eIsProxy()) {
if (writtenMember != null) {
// case 1: writtenMember provided as argument -> must be identical
if (paExpr.getProperty() != writtenMember)
return false;
} else {
// case 2: writtenMember not provided -> take from paExpr
if (paExpr.getProperty() instanceof TMember)
writtenMember = (TMember) paExpr.getProperty();
}
}
// written member must be a final field
if (!(writtenMember instanceof TField))
return false;
final TField field = (TField) writtenMember;
if (!field.isFinal())
return false;
// (IMPORTANT: we do not assert !field.isHasExpression() here, which would be required for a fully-legal write
// access)
// assExpr must be located in the constructor of the owner of 'field'
// (a) find type model element for the function containing the assignment expression
final FunctionDefinition containingFunction = getContainingFunction(assExpr);
if (containingFunction == null)
return false;
final Type containingTFunction = containingFunction.getDefinedType();
if (containingTFunction == null)
return false;
// (b) find constructor of the owner of the field
final ContainerType<?> ownerOfField = field.getContainingType();
if (ownerOfField == null)
return false;
final TMember ctorOfOwner = getOwnOrSuperCtor(ownerOfField);
if (ctorOfOwner == null)
return false;
// (c) compare
boolean simpleCompare = containingTFunction == ctorOfOwner;
if (simpleCompare) {
return true;
}
// filled type:
if (containingTFunction.eContainer() instanceof TClass) {
TClass containingTClass = (TClass) containingTFunction.eContainer();
if (containingTClass.isStaticPolyfill() && containingTClass.getSuperClassRef() != null && containingTClass.getSuperClassRef().getDeclaredType() instanceof TClass) {
// get replaced ctor:
TClass filledClass = (TClass) containingTClass.getSuperClassRef().getDeclaredType();
TMember replacedCtorOfFilledClass = getOwnOrSuperCtor(filledClass);
// compare (incl. null)
return replacedCtorOfFilledClass == ctorOfOwner;
}
}
return false;
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class ParameterizedTypeRefStructuralImpl method getTypeRefAsString.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String getTypeRefAsString() {
TypingStrategy _typingStrategy = this.getTypingStrategy();
Type _declaredType = this.getDeclaredType();
String _rawTypeAsString = null;
if (_declaredType != null) {
_rawTypeAsString = _declaredType.getRawTypeAsString();
}
String _plus = (_typingStrategy + _rawTypeAsString);
String _xifexpression = null;
boolean _isEmpty = this.getTypeArgs().isEmpty();
if (_isEmpty) {
_xifexpression = "";
} else {
final Function1<TypeArgument, String> _function = new Function1<TypeArgument, String>() {
public String apply(final TypeArgument it) {
return it.getTypeRefAsString();
}
};
String _join = IterableExtensions.join(XcoreEListExtensions.<TypeArgument, String>map(this.getTypeArgs(), _function), ",");
String _plus_1 = ("<" + _join);
_xifexpression = (_plus_1 + ">");
}
String _plus_2 = (_plus + _xifexpression);
String _xifexpression_1 = null;
boolean _isEmpty_1 = this.getStructuralMembers().isEmpty();
if (_isEmpty_1) {
_xifexpression_1 = "";
} else {
final Function1<TStructMember, String> _function_1 = new Function1<TStructMember, String>() {
public String apply(final TStructMember it) {
return it.getMemberAsString();
}
};
String _join_1 = IterableExtensions.join(XcoreEListExtensions.<TStructMember, String>map(this.getStructuralMembers(), _function_1), "; ");
String _plus_3 = (" with { " + _join_1);
String _plus_4 = (_plus_3 + " }");
String _xifexpression_2 = null;
boolean _isEmpty_2 = this.getPostponedSubstitutions().isEmpty();
if (_isEmpty_2) {
_xifexpression_2 = "";
} else {
final Function1<TypeVariableMapping, String> _function_2 = new Function1<TypeVariableMapping, String>() {
public String apply(final TypeVariableMapping it) {
String _typeAsString = it.getTypeVar().getTypeAsString();
String _plus = (_typeAsString + "->");
String _typeRefAsString = it.getTypeArg().getTypeRefAsString();
return (_plus + _typeRefAsString);
}
};
String _join_2 = IterableExtensions.join(XcoreEListExtensions.<TypeVariableMapping, String>map(this.getPostponedSubstitutions(), _function_2), ", ");
String _plus_5 = (" [[" + _join_2);
_xifexpression_2 = (_plus_5 + "]]");
}
_xifexpression_1 = (_plus_4 + _xifexpression_2);
}
return (_plus_2 + _xifexpression_1);
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class MethodDeclarationImpl method getDefinedTypeElement.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TMember getDefinedTypeElement() {
TMember _xifexpression = null;
Type _definedType = this.getDefinedType();
boolean _tripleEquals = (_definedType == null);
if (_tripleEquals) {
_xifexpression = null;
} else {
TMember _xifexpression_1 = null;
Type _definedType_1 = this.getDefinedType();
if ((_definedType_1 instanceof TMember)) {
Type _definedType_2 = this.getDefinedType();
_xifexpression_1 = ((TMember) _definedType_2);
} else {
throw new IllegalArgumentException("");
}
_xifexpression = _xifexpression_1;
}
return _xifexpression;
}
use of org.eclipse.n4js.ts.types.Type in project n4js by eclipse.
the class FunctionDeclarationImpl method setDefinedType.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setDefinedType(Type newDefinedType) {
Type oldDefinedType = definedType;
definedType = newDefinedType;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.FUNCTION_DECLARATION__DEFINED_TYPE, oldDefinedType, definedType));
}
Aggregations