static void addCreateProposals( Tree.CompilationUnit cu, Node node, Collection<ICompletionProposal> proposals, IProject project, IFile file) { Tree.MemberOrTypeExpression smte = (Tree.MemberOrTypeExpression) node; String brokenName = Nodes.getIdentifyingNode(node).getText(); if (!brokenName.isEmpty()) { ValueFunctionDefinitionGenerator vfdg = ValueFunctionDefinitionGenerator.create(brokenName, smte, cu); if (vfdg != null) { if (smte instanceof Tree.BaseMemberExpression) { Tree.BaseMemberExpression bme = (Tree.BaseMemberExpression) smte; Tree.Identifier id = bme.getIdentifier(); if (id.getToken().getType() != CeylonLexer.AIDENTIFIER) { addCreateParameterProposal(proposals, project, vfdg); } } addCreateProposals(cu, proposals, project, file, smte, vfdg); } ObjectClassDefinitionGenerator ocdg = ObjectClassDefinitionGenerator.create(brokenName, smte, cu); if (ocdg != null) { addCreateProposals(cu, proposals, project, file, smte, ocdg); } } }
private static void addCreateProposals( Tree.CompilationUnit rootNode, Collection<ICompletionProposal> proposals, IProject project, IFile file, Tree.MemberOrTypeExpression smte, DefinitionGenerator dg) { if (smte instanceof Tree.QualifiedMemberOrTypeExpression) { addCreateMemberProposals( proposals, project, dg, (Tree.QualifiedMemberOrTypeExpression) smte, Nodes.findStatement(rootNode, smte)); } else { if (!(dg.getNode() instanceof Tree.ExtendedTypeExpression)) { addCreateLocalProposals(proposals, project, dg); ClassOrInterface container = findClassContainer(rootNode, smte); if (container != null && container != smte .getScope()) { // if the statement appears directly in an initializer, propose a // local, not a member do { addCreateMemberProposals( proposals, project, dg, container, // TODO: this is a little lame because // it doesn't handle some cases // of nesting Nodes.findStatement(rootNode, smte)); if (container.getContainer() instanceof Declaration) { Declaration outerContainer = (Declaration) container.getContainer(); container = findClassContainer(outerContainer); } else { break; } } while (container != null); } } addCreateToplevelProposals(proposals, project, dg); addCreateInNewUnitProposal(proposals, dg, file, rootNode); } }
@Override public Object[] getChildren(Object element) { if (element instanceof CeylonOutlineNode) { if (mode) { boolean includeParameters = !CeylonPlugin.getPreferences().getBoolean(PARAMS_IN_OUTLINES); CeylonOutlineNode node = (CeylonOutlineNode) element; CompilationUnit rootNode = getEditor().getParseController().getLastCompilationUnit(); Node treeNode = Nodes.findNode(rootNode, node.getStartOffset(), node.getEndOffset()); TypeDeclaration td; if (treeNode instanceof ClassOrInterface) { ClassOrInterface ci = (ClassOrInterface) treeNode; td = ci.getDeclarationModel(); } else if (treeNode instanceof ObjectDefinition) { ObjectDefinition od = (ObjectDefinition) treeNode; td = od.getDeclarationModel().getTypeDeclaration(); } else { return super.getChildren(element); } List<Declaration> list = new ArrayList<Declaration>(); String filter = getFilterText().getText(); for (int i = 0; i < filter.length(); i++) { char ch = filter.charAt(i); if (ch == '*' || i > 0 && Character.isUpperCase(ch)) { filter = filter.substring(0, i); break; } } Collection<DeclarationWithProximity> members = td.getMatchingMemberDeclarations(rootNode.getUnit(), td, filter, 0, null).values(); for (DeclarationWithProximity dwp : members) { for (Declaration dec : overloads(dwp.getDeclaration())) { if (!(dec instanceof TypeParameter)) { if (includeParameters || !dec.isParameter()) { list.add(dec); } } } } if (!lexicalSortingAction.isChecked()) { Collections.sort( list, new Comparator<Declaration>() { public int compare(Declaration x, Declaration y) { String xn = x.getContainer().getQualifiedNameString(); String yn = y.getContainer().getQualifiedNameString(); return xn.compareTo(yn); } }); } return list.toArray(); } else { return super.getChildren(element); } } else { return null; } }
private CommonToken getTokenStrictlyContainingOffset(int offset) { return Nodes.getTokenStrictlyContainingOffset(offset, getTokens()); }
public static String getInitialValueDescription( final Declaration dec, CeylonParseController cpc) { if (cpc != null) { Node refnode = getReferencedNode(dec); Tree.SpecifierOrInitializerExpression sie = null; String arrow = null; if (refnode instanceof Tree.AttributeDeclaration) { Tree.AttributeDeclaration ad = (Tree.AttributeDeclaration) refnode; sie = ad.getSpecifierOrInitializerExpression(); arrow = " = "; } else if (refnode instanceof Tree.MethodDeclaration) { Tree.MethodDeclaration md = (Tree.MethodDeclaration) refnode; sie = md.getSpecifierExpression(); arrow = " => "; } Tree.CompilationUnit lcu = cpc.getLastCompilationUnit(); if (sie == null) { class FindInitializerVisitor extends Visitor { Tree.SpecifierOrInitializerExpression result; @Override public void visit(Tree.InitializerParameter that) { super.visit(that); Declaration d = that.getParameterModel().getModel(); if (d != null && d.equals(dec)) { result = that.getSpecifierExpression(); } } } FindInitializerVisitor fiv = new FindInitializerVisitor(); fiv.visit(lcu); sie = fiv.result; } if (sie != null) { Tree.Expression e = sie.getExpression(); if (e != null) { Tree.Term term = e.getTerm(); if (term instanceof Tree.Literal) { String text = term.getToken().getText(); if (text.length() < 20) { return arrow + text; } } else if (term instanceof Tree.BaseMemberOrTypeExpression) { Tree.BaseMemberOrTypeExpression bme = (Tree.BaseMemberOrTypeExpression) term; Tree.Identifier id = bme.getIdentifier(); if (id != null && bme.getTypeArguments() == null) { return arrow + id.getText(); } } else if (term != null) { Unit unit = lcu.getUnit(); if (term.getUnit().equals(unit)) { String impl = Nodes.text(term, cpc.getTokens()); if (impl.length() < 10) { return arrow + impl; } } } // don't have the token stream :-/ // TODO: figure out where to get it from! return arrow + "..."; } } } return ""; }