private Declaration getDirectMemberFromSource(String name) { for (Declaration d : super.getMembers()) { if (com.redhat.ceylon.compiler.typechecker.model.Util.isResolvable(d) /* && d.isShared() */ && com.redhat.ceylon.compiler.typechecker.model.Util.isNamed(name, d)) { return d; } } return null; }
public String getProducedTypeName(boolean abbreviate) { if (getDeclaration() == null) { // unknown type return null; } if (abbreviate && getDeclaration() instanceof UnionType) { UnionType ut = (UnionType) getDeclaration(); if (ut.getCaseTypes().size() == 2) { Unit unit = getDeclaration().getUnit(); if (Util.isElementOfUnion(ut, unit.getNothingDeclaration())) { return unit.getDefiniteType(this).getProducedTypeName() + "?"; } if (Util.isElementOfUnion(ut, unit.getEmptyDeclaration()) && Util.isElementOfUnion(ut, unit.getSequenceDeclaration())) { return unit.getElementType(this).getProducedTypeName() + "[]"; } } } String producedTypeName = ""; if (getDeclaration().isMember()) { producedTypeName += getQualifyingType().getProducedTypeName(abbreviate); producedTypeName += "."; } producedTypeName += getDeclaration().getName(); if (!getTypeArgumentList().isEmpty()) { producedTypeName += "<"; for (ProducedType t : getTypeArgumentList()) { if (t == null) { producedTypeName += "unknown,"; } else { producedTypeName += t.getProducedTypeName(abbreviate) + ","; } } producedTypeName += ">"; producedTypeName = producedTypeName.replace(",>", ">"); } return producedTypeName; }
private List<ProducedType> getSupertypes(List<ProducedType> list) { if (isWellDefined() && Util.addToSupertypes(list, this)) { ProducedType extendedType = getExtendedType(); if (extendedType != null) { extendedType.getSupertypes(list); } for (ProducedType dst : getSatisfiedTypes()) { dst.getSupertypes(list); } ProducedType selfType = getSelfType(); if (selfType != null) { if (!(selfType.getDeclaration() instanceof TypeParameter)) { // TODO: is this really correct??? selfType.getSupertypes(list); } } List<ProducedType> caseTypes = getCaseTypes(); if (caseTypes != null /*&& !getDeclaration().getCaseTypes().isEmpty()*/) { for (ProducedType t : caseTypes) { List<ProducedType> candidates = t.getSupertypes(); for (ProducedType st : candidates) { boolean include = true; for (ProducedType ct : getDeclaration().getCaseTypes()) { if (!ct.isSubtypeOf(st)) { include = false; break; } } if (include) { Util.addToSupertypes(list, st); } } } } } return list; }
public Map<String, DeclarationWithProximity> getMatchingMemberDeclarations( Scope scope, String startingWith, int proximity) { Map<String, DeclarationWithProximity> result = new TreeMap<String, DeclarationWithProximity>(); for (TypeDeclaration st : getSatisfiedTypeDeclarations()) { mergeMembers(result, st.getMatchingMemberDeclarations(scope, startingWith, proximity + 1)); } TypeDeclaration et = getExtendedTypeDeclaration(); if (et != null) { mergeMembers(result, et.getMatchingMemberDeclarations(scope, startingWith, proximity + 1)); } for (Declaration d : getMembers()) { if (isResolvable(d) && !isOverloadedVersion(d) && isNameMatching(startingWith, d)) { if (d.isShared() || Util.contains(d.getScope(), scope)) { result.put(d.getName(), new DeclarationWithProximity(d, proximity)); } } } // TODO: self type? return result; }
/** Search for the most-specialized supertype satisfying the given predicate. */ private ProducedType getSupertype( final Criteria c, List<ProducedType> list, final TypeDeclaration ignoringSelfType) { if (c.satisfies(getDeclaration())) { return qualifiedByDeclaringType(); } if (isWellDefined() && Util.addToSupertypes(list, this)) { // search for the most-specific supertype // for the given declaration ProducedType result = null; ProducedType extendedType = getInternalExtendedType(); if (extendedType != null) { ProducedType possibleResult = extendedType.getSupertype(c, list, ignoringSelfType); if (possibleResult != null) { result = possibleResult; } } for (ProducedType dst : getInternalSatisfiedTypes()) { ProducedType possibleResult = dst.getSupertype(c, list, ignoringSelfType); if (possibleResult != null && (result == null || possibleResult.isSubtypeOf(result, ignoringSelfType))) { result = possibleResult; } } if (!getDeclaration().equals(ignoringSelfType)) { ProducedType selfType = getInternalSelfType(); if (selfType != null) { ProducedType possibleResult = selfType.getSupertype(c, list, ignoringSelfType); if (possibleResult != null && (result == null || possibleResult.isSubtypeOf(result, ignoringSelfType))) { result = possibleResult; } } } final List<ProducedType> caseTypes = getInternalCaseTypes(); if (caseTypes != null && !caseTypes.isEmpty()) { // first find a common superclass or superinterface // declaration that satisfies the criteria, ignoring // type arguments for now Criteria c2 = new Criteria() { @Override public boolean satisfies(TypeDeclaration type) { if (c.satisfies(type)) { for (ProducedType ct : caseTypes) { if (ct.getSupertype(type, ignoringSelfType) == null) { return false; } } return true; } else { return false; } } }; ProducedType stc = caseTypes.get(0).getSupertype(c2, list, ignoringSelfType); if (stc != null) { // we found the declaration, now try to construct a // produced type that is a true common supertype ProducedType candidateResult = getCommonSupertype(caseTypes, stc.getDeclaration(), ignoringSelfType); if (candidateResult != null && (result == null || candidateResult.isSubtypeOf(result, ignoringSelfType))) { result = candidateResult; } } } return result; } else { return null; } }
private String getQualifiedName(final String pkgName, String name) { // FIXME: some refactoring needed String className = pkgName.isEmpty() ? name : Util.quoteJavaKeywords(pkgName) + "." + name; return className; }
@Override public void apply(IDocument document) { super.apply(document); if (withBody && EditorsUI.getPreferenceStore().getBoolean(LINKED_MODE)) { final LinkedModeModel linkedModeModel = new LinkedModeModel(); final Point selection = getSelection(document); List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(); for (final Declaration d : p.getMembers()) { if (Util.isResolvable(d) && d.isShared()) { proposals.add( new ICompletionProposal() { @Override public Point getSelection(IDocument document) { return null; } @Override public Image getImage() { return getImageForDeclaration(d); } @Override public String getDisplayString() { return d.getName(); } @Override public IContextInformation getContextInformation() { return null; } @Override public String getAdditionalProposalInfo() { return null; } @Override public void apply(IDocument document) { try { document.replace(selection.x, selection.y, d.getName()); } catch (BadLocationException e) { e.printStackTrace(); } linkedModeModel.exit(ILinkedModeListener.UPDATE_CARET); } }); } } ProposalPosition linkedPosition = new ProposalPosition( document, selection.x, selection.y, 0, proposals.toArray(NO_COMPLETIONS)); try { LinkedMode.addLinkedPosition(linkedModeModel, linkedPosition); LinkedMode.installLinkedMode( (CeylonEditor) EditorUtil.getCurrentEditor(), document, linkedModeModel, this, new LinkedMode.NullExitPolicy(), -1, 0); } catch (BadLocationException ble) { ble.printStackTrace(); } } }
/** * Returns a ProducedType corresponding to {@code Range<T>} * * @param rt The ProducedType corresponding to {@code T} * @return The ProducedType corresponding to {@code Range<T>} */ public ProducedType getRangeType(ProducedType rt) { return Util.producedType(getRangeDeclaration(), rt); }
/** * Returns a ProducedType corresponding to {@code Iterator<T>} * * @param et The ProducedType corresponding to {@code T} * @return The ProducedType corresponding to {@code Iterator<T>} */ public ProducedType getIteratorType(ProducedType et) { return Util.producedType(getIteratorDeclaration(), et); }