private void addRemoval(Tree.Identifier id, Declaration d) { if (id != null && d != null && dec.equals(getAbstraction(d)) && id.getText().equals(aid.getText())) { change.addEdit(new ReplaceEdit(id.getStartIndex(), id.getDistance(), dec.getName())); } }
private static String name(Tree.Identifier id) { if (id == null) { return "<unknown>"; } else { return id.getText(); } }
public static void addChangeIdentifierCaseProposal( Node node, Collection<ICompletionProposal> proposals, IFile file) { Tree.Identifier identifier = null; if (node instanceof Tree.TypeDeclaration) { identifier = ((Tree.TypeDeclaration) node).getIdentifier(); } else if (node instanceof Tree.TypeParameterDeclaration) { identifier = ((Tree.TypeParameterDeclaration) node).getIdentifier(); } else if (node instanceof Tree.TypedDeclaration) { identifier = ((Tree.TypedDeclaration) node).getIdentifier(); } else if (node instanceof Tree.ImportPath) { List<Identifier> importIdentifiers = ((Tree.ImportPath) node).getIdentifiers(); for (Identifier importIdentifier : importIdentifiers) { if (importIdentifier.getText() != null && !importIdentifier.getText().isEmpty() && Character.isUpperCase(importIdentifier.getText().charAt(0))) { identifier = importIdentifier; break; } } } if (identifier != null && !identifier.getText().isEmpty()) { addProposal(identifier, proposals, file); } }
private static String toPath(Tree.Import ai) { String path = ""; for (Tree.Identifier id : ai.getImportPath().getIdentifiers()) { path += "." + id.getText(); } path = path.substring(1); return path; }
protected void renameIdentifier(TextChange tfc, Tree.Identifier id, Tree.CompilationUnit root) { String name = declaration.getName(); int loc = id.getText().indexOf(name); int start = id.getStartIndex(); int len = id.getDistance(); if (loc > 0) { tfc.addEdit(new ReplaceEdit(start + loc, name.length(), newName)); } else { tfc.addEdit(new ReplaceEdit(start, len, escaping_.get_().toInitialLowercase(newName))); } }
@Override public void visit(Tree.TypedDeclaration that) { super.visit(that); Tree.Identifier id = that.getIdentifier(); if (id != null) { Type type = that.getType().getTypeModel(); if (type != null) { TypeDeclaration td = type.getDeclaration(); if ((td instanceof ClassOrInterface || td instanceof TypeParameter) && td.equals(declaration)) { String text = id.getText(); String name = declaration.getName(); if (text.equalsIgnoreCase(name) || text.endsWith(name)) { identifiers.add(id); } } } } }
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 ""; }