if (typeName instanceof PrefixedIdentifier && parent instanceof ConstructorName
&& argumentList == null) {
ConstructorName name = (ConstructorName) parent;
if (name.getName() == null) {
PrefixedIdentifier prefixedIdentifier = (PrefixedIdentifier) typeName;
SimpleIdentifier prefix = prefixedIdentifier.getPrefix();
element = getNameScope().lookup(prefix, getDefiningLibrary());
if (element instanceof PrefixElement) {
if (parent.getParent() instanceof InstanceCreationExpression
&& ((InstanceCreationExpression) parent.getParent()).isConst()) {
// If, if this is a const expression, then generate a
// CompileTimeErrorCode.CONST_WITH_NON_TYPE error.
reportErrorForNode(
CompileTimeErrorCode.CONST_WITH_NON_TYPE,
prefixedIdentifier.getIdentifier(),
prefixedIdentifier.getIdentifier().getName());
} else {
// Else, if this expression is a new expression, report a NEW_WITH_NON_TYPE warning.
reportErrorForNode(
StaticWarningCode.NEW_WITH_NON_TYPE,
prefixedIdentifier.getIdentifier(),
prefixedIdentifier.getIdentifier().getName());
}
setElement(prefix, element);
return null;
} else if (element != null) {
//
// Rewrite the constructor name. The parser, when it sees a constructor named "a.b",
// cannot tell whether "a" is a prefix and "b" is a class name, or whether "a" is a
// class name and "b" is a constructor name. It arbitrarily chooses the former, but
// in this case was wrong.
//
name.setName(prefixedIdentifier.getIdentifier());
name.setPeriod(prefixedIdentifier.getPeriod());
node.setName(prefix);
typeName = prefix;
}
}
}
}
// check element
boolean elementValid = !(element instanceof MultiplyDefinedElement);
if (elementValid && !(element instanceof ClassElement)
&& isTypeNameInInstanceCreationExpression(node)) {
SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName);
InstanceCreationExpression creation = (InstanceCreationExpression) node.getParent().getParent();
if (creation.isConst()) {
if (element == null) {
reportErrorForNode(CompileTimeErrorCode.UNDEFINED_CLASS, typeNameSimple, typeName);
} else {
reportErrorForNode(CompileTimeErrorCode.CONST_WITH_NON_TYPE, typeNameSimple, typeName);
}
elementValid = false;
} else {
if (element != null) {
reportErrorForNode(StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, typeName);
elementValid = false;
}
}
}
if (elementValid && element == null) {
// We couldn't resolve the type name.
// TODO(jwren) Consider moving the check for CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE
// from the ErrorVerifier, so that we don't have two errors on a built in identifier being
// used as a class name. See CompileTimeErrorCodeTest.test_builtInIdentifierAsType().
SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName);
RedirectingConstructorKind redirectingConstructorKind;
if (isBuiltInIdentifier(node) && isTypeAnnotation(node)) {
reportErrorForNode(
CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE,
typeName,
typeName.getName());
} else if (typeNameSimple.getName().equals("boolean")) {
reportErrorForNode(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple);
} else if (isTypeNameInCatchClause(node)) {
reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, typeName.getName());
} else if (isTypeNameInAsExpression(node)) {
reportErrorForNode(StaticWarningCode.CAST_TO_NON_TYPE, typeName, typeName.getName());