static void addCreateParameterProposal( Collection<ICompletionProposal> proposals, String def, String desc, Image image, Declaration dec, PhasedUnit unit, Tree.Declaration decNode, Tree.ParameterList paramList, ProducedType t) { IFile file = CeylonBuilder.getFile(unit); TextFileChange change = new TextFileChange("Add Parameter", file); change.setEdit(new MultiTextEdit()); int offset = paramList.getStopIndex(); int il = importType(change, t, unit.getCompilationUnit()); change.addEdit(new InsertEdit(offset, def)); proposals.add( new CreateProposal( def, "Add " + desc + " to '" + dec.getName() + "'", image, 0, offset + il, file, change)); }
private static void appendImportElements( String packageName, List<Tree.ImportMemberOrType> elements, List<Declaration> unused, List<Declaration> proposed, boolean hasWildcard, StringBuilder builder) { for (Tree.ImportMemberOrType i : elements) { if (i.getDeclarationModel() != null && i.getIdentifier().getErrors().isEmpty() && i.getErrors().isEmpty()) { if (!i.getImportModel().getAlias().equals(i.getDeclarationModel().getName())) { builder.append(i.getImportModel().getAlias()).append("="); } builder.append(i.getDeclarationModel().getName()); appendNestedImportElements(i, unused, builder); builder.append(", "); } } for (Declaration d : proposed) { if (d.getUnit().getPackage().getNameAsString().equals(packageName)) { builder.append(d.getName()).append(", "); } } if (hasWildcard) { builder.append("..."); } else { builder.setLength(builder.length() - 2); } }
static void addCreateParameterAndAttributeProposal( Collection<ICompletionProposal> proposals, String pdef, String adef, String desc, Image image, Declaration dec, PhasedUnit unit, Tree.Declaration decNode, Tree.ParameterList paramList, Tree.Body body, ProducedType t) { IFile file = CeylonBuilder.getFile(unit); TextFileChange change = new TextFileChange("Add Attribute", file); change.setEdit(new MultiTextEdit()); int offset = paramList.getStopIndex(); IDocument doc = CreateProposal.getDocument(change); String indent; String indentAfter; int offset2; List<Tree.Statement> statements = body.getStatements(); if (statements.isEmpty()) { indentAfter = "\n" + CeylonQuickFixAssistant.getIndent(decNode, doc); indent = indentAfter + getDefaultIndent(); offset2 = body.getStartIndex() + 1; } else { Tree.Statement statement = statements.get(statements.size() - 1); indent = "\n" + CeylonQuickFixAssistant.getIndent(statement, doc); offset2 = statement.getStopIndex() + 1; indentAfter = ""; } int il = importType(change, t, unit.getCompilationUnit()); change.addEdit(new InsertEdit(offset, pdef)); change.addEdit(new InsertEdit(offset2, indent + adef + indentAfter)); proposals.add( new CreateProposal( pdef, "Add " + desc + " to '" + dec.getName() + "'", image, 0, offset + il, file, change)); }