/** * Method addPrimitiveTypes. */ private void processKeywords() { if (isKind(PRIMITIVETYPES)) { for (int i= 0; i < PRIM_TYPES.length; i++) { if (NameMatcher.isSimilarName(fName, PRIM_TYPES[i])) { addResult(new SimilarElement(PRIMITIVETYPES, PRIM_TYPES[i], 50)); } } } if (isKind(VOIDTYPE)) { String voidType= "void"; //$NON-NLS-1$ if (NameMatcher.isSimilarName(fName, voidType)) { addResult(new SimilarElement(PRIMITIVETYPES, voidType, 50)); } } }
/** * Returns a similarity value of the two names. * The range of is from 0 to 256. no similarity is negative * @param name1 the first name * @param name2 the second name * @return <code>true</code> is returned if the names are similar */ public static boolean isSimilarName(String name1, String name2) { return getSimilarity(name1, name2) >= 0; }
while (i < name1len && isSimilarChar(name1.charAt(i), name2.charAt(i))) { i++; nMatched++; while (k > i && isSimilarChar(name1.charAt(k - 1), name2.charAt(k + diff - 1))) { k--; nMatched++;
/** * Method addPrimitiveTypes. */ private void processKeywords() { if (isKind(TypeKinds.PRIMITIVETYPES)) { for (int i= 0; i < PRIM_TYPES.length; i++) { if (NameMatcher.isSimilarName(fName, PRIM_TYPES[i])) { addResult(new SimilarElement(TypeKinds.PRIMITIVETYPES, PRIM_TYPES[i], 50)); } } } if (isKind(TypeKinds.VOIDTYPE)) { String voidType= "void"; //$NON-NLS-1$ if (NameMatcher.isSimilarName(fName, voidType)) { addResult(new SimilarElement(TypeKinds.PRIMITIVETYPES, voidType, 50)); } } }
/** * Returns a similarity value of the two names. * The range of is from 0 to 256. no similarity is negative */ public static boolean isSimilarName(String name1, String name2) { return getSimilarity(name1, name2) >= 0; }
while (i < name1len && isSimilarChar(name1.charAt(i), name2.charAt(i))) { i++; nMatched++; while (k > i && isSimilarChar(name1.charAt(k - 1), name2.charAt(k + diff - 1))) { k--; nMatched++;
/** * Method addPrimitiveTypes. */ private void processKeywords() { if (isKind(PRIMITIVETYPES)) { for (int i= 0; i < PRIM_TYPES.length; i++) { if (NameMatcher.isSimilarName(fName, PRIM_TYPES[i])) { addResult(new SimilarElement(PRIMITIVETYPES, PRIM_TYPES[i], 50)); } } } if (isKind(VOIDTYPE)) { String voidType= "void"; //$NON-NLS-1$ if (NameMatcher.isSimilarName(fName, voidType)) { addResult(new SimilarElement(PRIMITIVETYPES, voidType, 50)); } } }
/** * Returns a similarity value of the two names. * The range of is from 0 to 256. no similarity is negative * @param name1 the first name * @param name2 the second name * @return <code>true</code> is returned if the names are similar */ public static boolean isSimilarName(String name1, String name2) { return getSimilarity(name1, name2) >= 0; }
while (i < name1len && isSimilarChar(name1.charAt(i), name2.charAt(i))) { i++; nMatched++; while (k > i && isSimilarChar(name1.charAt(k - 1), name2.charAt(k + diff - 1))) { k--; nMatched++;
private void addType(char[] typeNameSig, int flags, int relevance) { int kind= getKind(flags, typeNameSig); if (!isKind(kind)) { return; } String fullName= new String(Signature.toCharArray(Signature.getTypeErasure(typeNameSig))); if (TypeFilter.isFiltered(fullName)) { return; } if (NameMatcher.isSimilarName(fName, Signature.getSimpleName(fullName))) { addResult(new SimilarElement(kind, fullName, relevance)); } }
private void addType(char[] typeNameSig, int flags, int relevance) { int kind= getKind(flags, typeNameSig); if (!isKind(kind)) { return; } String fullName= new String(Signature.toCharArray(Signature.getTypeErasure(typeNameSig))); if (TypeFilter.isFiltered(fullName)) { return; } if (NameMatcher.isSimilarName(fName, Signature.getSimpleName(fullName))) { addResult(new SimilarElement(kind, fullName, relevance)); } }
private void addType(char[] typeNameSig, int flags, int relevance) { int kind= getKind(flags, typeNameSig); if (!isKind(kind)) { return; } String fullName= new String(Signature.toCharArray(Signature.getTypeErasure(typeNameSig))); if (TypeFilter.isFiltered(fullName)) { return; } if (NameMatcher.isSimilarName(fName, Signature.getSimpleName(fullName))) { addResult(new SimilarElement(kind, fullName, relevance)); } }
IMethodBinding binding= (IMethodBinding) bindings[i]; String curr= binding.getName(); if (!curr.equals(methodName) && binding.getParameterTypes().length == nArguments && NameMatcher.isSimilarName(methodName, curr) && suggestedRenames.add(curr)) { String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changemethod_description, curr); proposals.add(new RenameNodeCompletionProposal(label, context.getCompilationUnit(), problem.getOffset(), problem.getLength(), curr, 6));
IMethodBinding binding= (IMethodBinding) bindings[i]; String curr= binding.getName(); if (!curr.equals(methodName) && binding.getParameterTypes().length == nArguments && NameMatcher.isSimilarName(methodName, curr) && suggestedRenames.add(curr)) { String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changemethod_description, curr); proposals.add(new RenameNodeCompletionProposal(label, context.getCompilationUnit(), problem.getOffset(), problem.getLength(), curr, 6));
IMethodBinding binding= (IMethodBinding) bindings[i]; String curr= binding.getName(); if (!curr.equals(methodName) && binding.getParameterTypes().length == nArguments && NameMatcher.isSimilarName(methodName, curr) && suggestedRenames.add(curr)) { String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changemethod_description, BasicElementLabels.getJavaElementName(curr)); proposals.add(new RenameNodeCorrectionProposal(label, context.getCompilationUnit(), problem.getOffset(), problem.getLength(), curr, IProposalRelevance.CHANGE_METHOD));
IMethodBinding binding= (IMethodBinding) bindings[i]; String curr= binding.getName(); if (!curr.equals(methodName) && binding.getParameterTypes().length == nArguments && NameMatcher.isSimilarName(methodName, curr) && suggestedRenames.add(curr)) { String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changemethod_description, BasicElementLabels.getJavaElementName(curr)); proposals.add(new RenameNodeCorrectionProposal(label, context.getCompilationUnit(), problem.getOffset(), problem.getLength(), curr, IProposalRelevance.CHANGE_METHOD));
public static void addUnknownSuppressWarningProposals(IInvocationContext context, IProblemLocation problem, Collection proposals) { ASTNode coveringNode= context.getCoveringNode(); if (!(coveringNode instanceof StringLiteral)) return; AST ast= coveringNode.getAST(); StringLiteral literal= (StringLiteral) coveringNode; String literalValue= literal.getLiteralValue(); String[] allWarningTokens= CorrectionEngine.getAllWarningTokens(); for (int i= 0; i < allWarningTokens.length; i++) { String curr= allWarningTokens[i]; if (NameMatcher.isSimilarName(literalValue, curr)) { StringLiteral newLiteral= ast.newStringLiteral(); newLiteral.setLiteralValue(curr); ASTRewrite rewrite= ASTRewrite.create(ast); rewrite.replace(literal, newLiteral, null); String label= Messages.format(CorrectionMessages.SuppressWarningsSubProcessor_fix_suppress_token_label, new String[] { curr }); Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 5, image); proposals.add(proposal); } } }
public static void getArrayAccessProposals(IInvocationContext context, IProblemLocation problem, Collection proposals) { CompilationUnit root= context.getASTRoot(); ASTNode selectedNode= problem.getCoveringNode(root); if (!(selectedNode instanceof MethodInvocation)) { return; } MethodInvocation decl= (MethodInvocation) selectedNode; SimpleName nameNode= decl.getName(); String methodName= nameNode.getIdentifier(); IBinding[] bindings= (new ScopeAnalyzer(root)).getDeclarationsInScope(nameNode, ScopeAnalyzer.METHODS); for (int i= 0; i < bindings.length; i++) { String currName= bindings[i].getName(); if (NameMatcher.isSimilarName(methodName, currName)) { String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_arraychangetomethod_description, currName); proposals.add(new RenameNodeCompletionProposal(label, context.getCompilationUnit(), nameNode.getStartPosition(), nameNode.getLength(), currName, 6)); } } // always suggest 'length' String lengthId= "length"; //$NON-NLS-1$ String label= CorrectionMessages.UnresolvedElementsSubProcessor_arraychangetolength_description; int offset= nameNode.getStartPosition(); int length= decl.getStartPosition() + decl.getLength() - offset; proposals.add(new RenameNodeCompletionProposal(label, context.getCompilationUnit(), offset, length, lengthId, 7)); }
public static void getArrayAccessProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { CompilationUnit root= context.getASTRoot(); ASTNode selectedNode= problem.getCoveringNode(root); if (!(selectedNode instanceof MethodInvocation)) { return; } MethodInvocation decl= (MethodInvocation) selectedNode; SimpleName nameNode= decl.getName(); String methodName= nameNode.getIdentifier(); IBinding[] bindings= (new ScopeAnalyzer(root)).getDeclarationsInScope(nameNode, ScopeAnalyzer.METHODS); for (int i= 0; i < bindings.length; i++) { String currName= bindings[i].getName(); if (NameMatcher.isSimilarName(methodName, currName)) { String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_arraychangetomethod_description, BasicElementLabels.getJavaElementName(currName)); proposals.add(new RenameNodeCorrectionProposal(label, context.getCompilationUnit(), nameNode.getStartPosition(), nameNode.getLength(), currName, IProposalRelevance.ARRAY_CHANGE_TO_METHOD)); } } // always suggest 'length' String lengthId= "length"; //$NON-NLS-1$ String label= CorrectionMessages.UnresolvedElementsSubProcessor_arraychangetolength_description; int offset= nameNode.getStartPosition(); int length= decl.getStartPosition() + decl.getLength() - offset; proposals.add(new RenameNodeCorrectionProposal(label, context.getCompilationUnit(), offset, length, lengthId, IProposalRelevance.ARRAY_CHANGE_TO_LENGTH)); }
/** * Adds a proposal to correct the name of the SuppressWarning annotation * @param context the context * @param problem the problem * @param proposals the resulting proposals */ public static void addUnknownSuppressWarningProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { ASTNode coveringNode= context.getCoveringNode(); if (!(coveringNode instanceof StringLiteral)) return; AST ast= coveringNode.getAST(); StringLiteral literal= (StringLiteral) coveringNode; String literalValue= literal.getLiteralValue(); String[] allWarningTokens= CorrectionEngine.getAllWarningTokens(); for (int i= 0; i < allWarningTokens.length; i++) { String curr= allWarningTokens[i]; if (NameMatcher.isSimilarName(literalValue, curr)) { StringLiteral newLiteral= ast.newStringLiteral(); newLiteral.setLiteralValue(curr); ASTRewrite rewrite= ASTRewrite.create(ast); rewrite.replace(literal, newLiteral, null); String label= Messages.format(CorrectionMessages.SuppressWarningsSubProcessor_fix_suppress_token_label, new String[] { curr }); Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.FIX_SUPPRESS_TOKEN, image); proposals.add(proposal); } } addRemoveUnusedSuppressWarningProposals(context, problem, proposals); }