Example usage for org.eclipse.jdt.core NamingConventions BK_NAME

List of usage examples for org.eclipse.jdt.core NamingConventions BK_NAME

Introduction

In this page you can find the example usage for org.eclipse.jdt.core NamingConventions BK_NAME.

Prototype

int BK_NAME

To view the source code for org.eclipse.jdt.core NamingConventions BK_NAME.

Click Source Link

Document

The base name associated to this base name kind is a simple name.

Usage

From source file:org.codehaus.groovy.eclipse.refactoring.core.convert.AssignStatementToNewLocalRefactoring.java

License:Apache License

private TextEdit createEdit(IDocument doc, Expression expression) {
    TextEdit edit = new MultiTextEdit();

    String candidate;//from w ww .  j a v a 2s  .  c om
    if (expression instanceof ConstantExpression) {
        candidate = ((ConstantExpression) expression).getText();
    } else if (expression instanceof VariableExpression) {
        candidate = ((VariableExpression) expression).getName();
    } else if (expression instanceof ClassExpression) {
        candidate = ((ClassExpression) expression).getType().getNameWithoutPackage();
    } else if (expression instanceof MethodCallExpression) {
        candidate = ((MethodCallExpression) expression).getMethodAsString();
    } else if (expression instanceof StaticMethodCallExpression) {
        candidate = ((StaticMethodCallExpression) expression).getMethod();
    } else if (expression instanceof MapExpression) {
        candidate = "map";
    } else if (expression instanceof ListExpression) {
        candidate = "list";
    } else {
        candidate = "temp";
    }

    Set<Variable> vars = ASTTools.getVariablesInScope(unit.getModuleNode(), expression);
    String[] variableNames = new String[vars.size()];
    int i = 0;
    for (Variable v : vars) {
        variableNames[i] = v.getName();
        i++;
    }

    String[] names = NamingConventions.suggestVariableNames(NamingConventions.VK_LOCAL,
            NamingConventions.BK_NAME, candidate, null, 0, variableNames, true);

    edit.addChild(new InsertEdit(expression.getStart(), "def " + names[0] + " = "));
    // add 4 for "def ".
    newOffset = expression.getStart() + 4;
    newLength = names[0].length();

    return edit;
}

From source file:org.codehaus.groovy.eclipse.refactoring.core.extract.ExtractGroovyConstantRefactoring.java

License:Apache License

@Override
public String[] guessConstantNames() {
    String text = getBaseNameFromExpression(getCu().getJavaProject(), getSelectedFragment(),
            NamingConventions.VK_STATIC_FINAL_FIELD);
    try {//www .j av  a  2s.c o m
        Integer.parseInt(text);
        text = "_" + text;
    } catch (NumberFormatException e) {
        // ignore
    }
    return NamingConventions.suggestVariableNames(NamingConventions.VK_STATIC_FINAL_FIELD,
            NamingConventions.BK_NAME, text, getCu().getJavaProject(),
            getContainingClassNode().isArray() ? 1 : 0, null, true);
}

From source file:org.codehaus.groovy.eclipse.refactoring.core.extract.ExtractGroovyLocalRefactoring.java

License:Apache License

public String[] guessLocalNames() {
    String text = getBaseNameFromExpression(getSelectedFragment());
    return NamingConventions.suggestVariableNames(NamingConventions.VK_LOCAL, NamingConventions.BK_NAME, text,
            unit.getJavaProject(), 0, null, true);
}