Java Code Examples for org.eclipse.jdt.core.NamingConventions#VK_STATIC_FINAL_FIELD
The following examples show how to use
org.eclipse.jdt.core.NamingConventions#VK_STATIC_FINAL_FIELD .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaStatementPostfixContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public String[] suggestFieldName(String type, String[] excludes, boolean staticField, boolean finalField) throws IllegalArgumentException { int dim = 0; while (type.endsWith("[]")) { dim++; type = type.substring(0, type.length() - 2); } IJavaProject project = getJavaProject(); int namingConventions = 0; if (staticField && finalField) { namingConventions = NamingConventions.VK_STATIC_FINAL_FIELD; } else if (staticField && !finalField) { namingConventions = NamingConventions.VK_STATIC_FIELD; } else { namingConventions = NamingConventions.VK_INSTANCE_FIELD; } if (project != null) return StubUtility.getVariableNameSuggestions(namingConventions, project, type, dim, Arrays.asList(excludes), true); return new String[] {Signature.getSimpleName(type).toLowerCase()}; }
Example 2
Source File: JdtVariableCompletions.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected int getVariableKind(VariableType varType) { switch (varType) { case INSTANCE_FIELD : return NamingConventions.VK_INSTANCE_FIELD; case LOCAL_VAR : return NamingConventions.VK_LOCAL; case PARAMETER : return NamingConventions.VK_PARAMETER; case STATIC_FIELD: return NamingConventions.VK_STATIC_FINAL_FIELD; default: throw new IllegalStateException("unhandled enum const"+varType); } }
Example 3
Source File: ExtractFieldRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * @return proposed field names (may be empty, but not null). The first proposal * should be used as "best guess" (if it exists). */ public String[] guessFieldNames() { if (fGuessedFieldNames == null) { try { Expression expression = getSelectedExpression().getAssociatedExpression(); if (expression != null) { ITypeBinding binding = guessBindingForReference(expression); int modifiers = getModifiers(); int variableKind; if (Flags.isFinal(modifiers) && Flags.isStatic(modifiers)) { variableKind = NamingConventions.VK_STATIC_FINAL_FIELD; } else if (Flags.isStatic(modifiers)) { variableKind = NamingConventions.VK_STATIC_FIELD; } else { variableKind = NamingConventions.VK_INSTANCE_FIELD; } fGuessedFieldNames = StubUtility.getVariableNameSuggestions(variableKind, fCu.getJavaProject(), binding, expression, Arrays.asList(getExcludedFieldNames())); } } catch (JavaModelException e) { } if (fGuessedFieldNames == null) { fGuessedFieldNames = new String[0]; } } return fGuessedFieldNames; }
Example 4
Source File: StubUtility.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static String[] getDefaultVariableNameSuggestions(int variableKind, Collection<String> excluded) { String prop= variableKind == NamingConventions.VK_STATIC_FINAL_FIELD ? "X" : "x"; //$NON-NLS-1$//$NON-NLS-2$ String name= prop; int i= 1; while (excluded.contains(name)) { name= prop + i++; } return new String[] { name }; }
Example 5
Source File: StubUtility.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static int getFieldKind(int modifiers) { if (!Modifier.isStatic(modifiers)) return NamingConventions.VK_INSTANCE_FIELD; if (!Modifier.isFinal(modifiers)) return NamingConventions.VK_STATIC_FIELD; return NamingConventions.VK_STATIC_FINAL_FIELD; }
Example 6
Source File: StubUtility.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static String getBaseNameFromExpression(IJavaProject project, Expression assignedExpression, int variableKind) { String name= null; if (assignedExpression instanceof CastExpression) { assignedExpression= ((CastExpression)assignedExpression).getExpression(); } if (assignedExpression instanceof Name) { Name simpleNode= (Name)assignedExpression; IBinding binding= simpleNode.resolveBinding(); if (binding instanceof IVariableBinding) return getBaseName((IVariableBinding)binding, project); return ASTNodes.getSimpleNameIdentifier(simpleNode); } else if (assignedExpression instanceof MethodInvocation) { name= ((MethodInvocation)assignedExpression).getName().getIdentifier(); } else if (assignedExpression instanceof SuperMethodInvocation) { name= ((SuperMethodInvocation)assignedExpression).getName().getIdentifier(); } else if (assignedExpression instanceof FieldAccess) { return ((FieldAccess)assignedExpression).getName().getIdentifier(); } else if (variableKind == NamingConventions.VK_STATIC_FINAL_FIELD && (assignedExpression instanceof StringLiteral || assignedExpression instanceof NumberLiteral)) { String string= assignedExpression instanceof StringLiteral ? ((StringLiteral)assignedExpression).getLiteralValue() : ((NumberLiteral)assignedExpression).getToken(); StringBuffer res= new StringBuffer(); boolean needsUnderscore= false; for (int i= 0; i < string.length(); i++) { char ch= string.charAt(i); if (Character.isJavaIdentifierPart(ch)) { if (res.length() == 0 && !Character.isJavaIdentifierStart(ch) || needsUnderscore) { res.append('_'); } res.append(ch); needsUnderscore= false; } else { needsUnderscore= res.length() > 0; } } if (res.length() > 0) { return res.toString(); } } if (name != null) { for (int i= 0; i < KNOWN_METHOD_NAME_PREFIXES.length; i++) { String curr= KNOWN_METHOD_NAME_PREFIXES[i]; if (name.startsWith(curr)) { if (name.equals(curr)) { return null; // don't suggest 'get' as variable name } else if (Character.isUpperCase(name.charAt(curr.length()))) { return name.substring(curr.length()); } } } } return name; }