public void checkConstraints(Collection<ConstraintViolation> violations) { super.checkConstraints(violations); if (!this.linkOperationExpressionIsCreationDerivation()) { violations.add(new ConstraintViolation("linkOperationExpressionIsCreationDerivation", this)); } if (!this.linkOperationExpressionIsClearDerivation()) { violations.add(new ConstraintViolation("linkOperationExpressionIsClearDerivation", this)); } if (!this.linkOperationExpressionReferentDerivation()) { violations.add(new ConstraintViolation("linkOperationExpressionReferentDerivation", this)); } if (!this.linkOperationExpressionFeatureDerivation()) { violations.add(new ConstraintViolation("linkOperationExpressionFeatureDerivation", this)); } if (!this.linkOperationExpressionAssociationReference()) { violations.add(new ConstraintViolation("linkOperationExpressionAssociationReference", this)); } if (!this.linkOperationExpressionArgumentCompatibility()) { violations.add(new ConstraintViolation("linkOperationExpressionArgumentCompatibility", this)); } QualifiedName associationName = this.getAssociationName(); if (associationName != null) { associationName.checkConstraints(violations); } }
private Object substitute(Object arg) { if (arg instanceof Excerpt) { SourceStringBuilder excerptBuilder = new SourceStringBuilder(sourceLevel, shortener); ((Excerpt) arg).addTo(excerptBuilder); return excerptBuilder.toString(); } else if (arg instanceof Package) { return ((Package) arg).getName(); } else if (arg instanceof Element) { ElementKind kind = ((Element) arg).getKind(); if (kind == ElementKind.PACKAGE) { return ((PackageElement) arg).getQualifiedName(); } else if (kind.isClass() || kind.isInterface()) { return shortener.shorten(QualifiedName.of((TypeElement) arg)); } else { return arg; } } else if (arg instanceof Class<?>) { return shortener.shorten(QualifiedName.of((Class<?>) arg)); } else if ((arg instanceof TypeMirror) && (((TypeMirror) arg).getKind() == TypeKind.DECLARED)) { DeclaredType mirror = (DeclaredType) arg; checkArgument(isLegalType(mirror), "Cannot write unknown type %s", mirror); return shortener.shorten(mirror); } else if (arg instanceof QualifiedName) { return shortener.shorten((QualifiedName) arg); } else if (arg instanceof AnnotationMirror) { SourceStringBuilder excerptBuilder = new SourceStringBuilder(sourceLevel, shortener); addSource(excerptBuilder, (AnnotationMirror) arg); return excerptBuilder.toString(); } else { return arg; } }
public void checkConstraints(Collection<ConstraintViolation> violations) { super.checkConstraints(violations); if (!this.castExpressionTypeDerivation()) { violations.add(new ConstraintViolation("castExpressionTypeDerivation", this)); } if (!this.castExpressionLowerDerivation()) { violations.add(new ConstraintViolation("castExpressionLowerDerivation", this)); } if (!this.castExpressionUpperDerivation()) { violations.add(new ConstraintViolation("castExpressionUpperDerivation", this)); } if (!this.castExpressionTypeResolution()) { violations.add(new ConstraintViolation("castExpressionTypeResolution", this)); } if (!this.castExpressionAssignmentsBefore()) { violations.add(new ConstraintViolation("castExpressionAssignmentsBefore", this)); } Expression operand = this.getOperand(); if (operand != null) { operand.checkConstraints(violations); } QualifiedName typeName = this.getTypeName(); if (typeName != null) { typeName.checkConstraints(violations); } }
/* * @see ASTVisitor#visit(QualifiedName) */ @Override public boolean visit(QualifiedName node) { node.getQualifier().accept(this); this.fBuffer.append("."); // $NON-NLS-1$ node.getName().accept(this); return false; }
@Override @NotNull public ClassId getClassId(int index) { LinkedList<String> packageFqName = new LinkedList<String>(); LinkedList<String> relativeClassName = new LinkedList<String>(); boolean local = false; while (index != -1) { QualifiedName proto = qualifiedNames.getQualifiedName(index); String shortName = strings.getString(proto.getShortName()); switch (proto.getKind()) { case CLASS: relativeClassName.addFirst(shortName); break; case PACKAGE: packageFqName.addFirst(shortName); break; case LOCAL: relativeClassName.addFirst(shortName); local = true; break; } index = proto.getParentQualifiedName(); } return new ClassId( FqName.fromSegments(packageFqName), FqName.fromSegments(relativeClassName), local); }
public void print(String prefix, boolean includeDerived) { super.print(prefix, includeDerived); QualifiedName associationName = this.getAssociationName(); if (associationName != null) { System.out.println(prefix + " associationName:"); associationName.print(prefix + " ", includeDerived); } }
public void _deriveAll() { this.getIsCreation(); this.getIsClear(); super._deriveAll(); QualifiedName associationName = this.getAssociationName(); if (associationName != null) { associationName.deriveAll(); } }
@Override public JSType getProp(QualifiedName qname) { Property p = getLeftmostProp(qname); if (qname.isIdentifier()) { return p == null ? JSType.UNDEFINED : p.getType(); } else { Preconditions.checkState(p != null); return p.getType().getProp(qname.getAllButLeftmost()); } }
@Override public JSType getDeclaredProp(QualifiedName qname) { Property p = getLeftmostProp(qname); if (p == null) { return null; } else if (qname.isIdentifier()) { return p.isDeclared() ? p.getDeclaredType() : null; } return p.getType().getDeclaredProp(qname.getAllButLeftmost()); }
public void _deriveAll() { super._deriveAll(); Expression operand = this.getOperand(); if (operand != null) { operand.deriveAll(); } QualifiedName typeName = this.getTypeName(); if (typeName != null) { typeName.deriveAll(); } }
public void print(String prefix, boolean includeDerived) { super.print(prefix, includeDerived); Expression operand = this.getOperand(); if (operand != null) { System.out.println(prefix + " operand:"); operand.print(prefix + " ", includeDerived); } QualifiedName typeName = this.getTypeName(); if (typeName != null) { System.out.println(prefix + " typeName:"); typeName.print(prefix + " ", includeDerived); } }
/** * Replaces (in place) a QualifiedName node with an equivalent FieldAccess node. This is helpful * when a mutation needs to replace the qualifier with a node that has Expression type but not * Name type. CAUTION: It is strongly recommended that this method be used within a "visit", and * not a "endVisit" because it will rewrite all QualifiedNode ancestors. */ public static FieldAccess convertToFieldAccess(QualifiedName node) { TreeNode parent = node.getParent(); if (parent instanceof QualifiedName) { FieldAccess newParent = convertToFieldAccess((QualifiedName) parent); Expression expr = newParent.getExpression(); assert expr instanceof QualifiedName; node = (QualifiedName) expr; } IVariableBinding variableBinding = getVariableBinding(node); assert variableBinding != null : "node must be a variable"; FieldAccess newNode = new FieldAccess(variableBinding, remove(node.getQualifier())); node.replaceWith(newNode); return newNode; }
private JSType lookupTypeByName( String name, Node n, DeclaredTypeRegistry registry, ImmutableList<String> outerTypeParameters) throws UnknownTypeException { String tvar = UniqueNameGenerator.findGeneratedName(name, outerTypeParameters); if (tvar != null) { return JSType.fromTypeVar(tvar); } Declaration decl = registry.getDeclaration(QualifiedName.fromQualifiedString(name), true); if (decl == null) { unknownTypeNames.put(n, name); throw new UnknownTypeException("Unhandled type: " + name); } // It's either a typedef, an enum, a type variable or a nominal type if (decl.getTypedef() != null) { return getTypedefType(decl.getTypedef(), registry); } if (decl.getEnum() != null) { return getEnumPropType(decl.getEnum(), registry); } if (decl.isTypeVar()) { howmanyTypeVars++; return decl.getTypeOfSimpleDecl(); } if (decl.getNominal() != null) { return getNominalTypeHelper(decl.getNominal(), n, registry, outerTypeParameters); } return JSType.UNKNOWN; }
private Property getLeftmostProp(QualifiedName qname) { String objName = qname.getLeftmostName(); Property p = props.get(objName); if (p != null) { return p; } if (nominalType != null) { return nominalType.getProp(objName); } return builtinObject == null ? null : builtinObject.getProp(objName); }
public boolean hasConstantProp(QualifiedName pname) { Preconditions.checkArgument(pname.isIdentifier()); if (objs == null) { return false; } for (ObjectType obj : objs) { if (obj.hasConstantProp(pname)) { return true; } } return false; }
@Nullable private Modifier getWrappersFromStub() { final StubElement parentStub = getStub().getParentStub(); final List childrenStubs = parentStub.getChildrenStubs(); int index = childrenStubs.indexOf(getStub()); if (index >= 0 && index < childrenStubs.size() - 1) { StubElement nextStub = (StubElement) childrenStubs.get(index + 1); if (nextStub instanceof PyTargetExpressionStub) { final PyTargetExpressionStub targetExpressionStub = (PyTargetExpressionStub) nextStub; if (targetExpressionStub.getInitializerType() == PyTargetExpressionStub.InitializerType.CallExpression) { final QualifiedName qualifiedName = targetExpressionStub.getInitializer(); if (QualifiedName.fromComponents(PyNames.CLASSMETHOD).equals(qualifiedName)) { return CLASSMETHOD; } if (QualifiedName.fromComponents(PyNames.STATICMETHOD).equals(qualifiedName)) { return STATICMETHOD; } } } } return null; }
@Override public Void visitAnnotation(AnnotationMirror annotation, AnnotationValue unused) { // By explicitly adding annotations rather than relying on AnnotationMirror.toString(), // we can import the types and make the code (hopefully) more readable. code.add("@%s", QualifiedName.of(asElement(annotation.getAnnotationType()))); if (annotation.getElementValues().isEmpty()) { return null; } code.add("("); if (hasSingleValueWithDefaultKey(annotation)) { AnnotationValue value = getOnlyElement(annotation.getElementValues().values()); visit(value, value); } else { String separator = ""; for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotation.getElementValues().entrySet()) { code.add("%s%s = ", separator, entry.getKey().getSimpleName()); visit(entry.getValue(), entry.getValue()); separator = ", "; } } code.add(")"); return null; }
// When type is null, this method removes the property. // If the property is already declared, but isDeclared is false, be careful // to not un-declare it. // If the property is already constant, but isConstant is false, be careful // to not un-const it. private ObjectType withPropertyHelper( QualifiedName qname, JSType type, boolean isDeclared, boolean isConstant) { // TODO(blickly): If the prop exists with right type, short circuit here. PersistentMap<String, Property> newProps = this.props; if (qname.isIdentifier()) { String pname = qname.getLeftmostName(); JSType declType = getDeclaredProp(qname); if (type == null) { type = declType; } if (declType != null) { isDeclared = true; if (hasConstantProp(qname)) { isConstant = true; } if (type != null && !type.isSubtypeOf(declType)) { // Can happen in inheritance-related type errors. // Not sure what the best approach is. // For now, just forget the inferred type. type = declType; } } else if (isDeclared) { declType = type; } if (type == null && declType == null) { newProps = newProps.without(pname); } else { newProps = newProps.with( pname, isConstant ? Property.makeConstant(null, type, declType) : Property.make(type, isDeclared ? declType : null)); } } else { // This has a nested object String objName = qname.getLeftmostName(); QualifiedName objQname = new QualifiedName(objName); if (!mayHaveProp(objQname)) { Preconditions.checkState( type == null, "Trying to update property %s on type %s, but sub-property %s does" + " not exist", qname, this, objName); return this; } QualifiedName innerProps = qname.getAllButLeftmost(); Property objProp = getLeftmostProp(objQname); JSType inferred = type == null ? objProp.getType().withoutProperty(innerProps) : objProp.getType().withProperty(innerProps, type); JSType declared = objProp.getDeclaredType(); newProps = newProps.with( objName, objProp.isOptional() ? Property.makeOptional(null, inferred, declared) : Property.make(inferred, declared)); } return ObjectType.makeObjectType(nominalType, newProps, fn, isLoose, objectKind); }
@Override public boolean hasConstantProp(QualifiedName qname) { Preconditions.checkArgument(qname.isIdentifier()); Property p = getLeftmostProp(qname); return p != null && p.isConstant(); }
@Override public boolean mayHaveProp(QualifiedName qname) { Property p = getLeftmostProp(qname); return p != null && (qname.isIdentifier() || p.getType().mayHaveProp(qname.getAllButLeftmost())); }
boolean isPropDefinedOnSubtype(QualifiedName pname) { Preconditions.checkArgument(pname.isIdentifier()); return this.rawType.isPropDefinedOnSubtype(pname.getLeftmostName()); }