| Previous CloneSet | Next CloneSet | Back to Main Report |
| Clone Mass | Clones in CloneSet | Parameter Count | Clone Similarity | Syntax Category [Sequence Length] |
|---|---|---|---|---|
| 120 | 2 | 4 | 0.998 | class_body_declarations[2] |
| Clone Abstraction | Parameter Bindings |
| Clone Instance (Click to see clone) | Line Count | Source Line | Source File |
|---|---|---|---|
| 1 | 140 | 286 | plugins/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java |
| 2 | 120 | 241 | plugins/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/CodeFormatterUtil.java |
| ||||
/**
* Creates edits that describe how to format the given string. Returns <code>null</code> if the code could not be formatted for the given kind.
* @param node Node describing the type of the string
* @param str The unformatted string
* @param indentationLevel
* @param lineSeparator
* @param options
* @return Returns the edit representing the result of the formatter
* @throws IllegalArgumentException If the offset and length are not inside the string, a
* IllegalArgumentException is thrown.
*/
private static TextEdit formatNode(ASTNode node, String str, int indentationLevel, String lineSeparator, Map options) {
int code;
String prefix = ""; //$NON-NLS-1$
String suffix = ""; //$NON-NLS-1$
if (node instanceof Statement) {
code = CodeFormatter.K_STATEMENTS;
if (node.getNodeType() == ASTNode.SWITCH_CASE) {
prefix = "switch(1) {"; //$NON-NLS-1$
suffix = "}"; //$NON-NLS-1$
code = CodeFormatter.K_STATEMENTS;
}
}
else if (node instanceof Expression && node.getNodeType() != ASTNode.VARIABLE_DECLARATION_EXPRESSION) {
code = CodeFormatter.K_EXPRESSION;
}
else
if (node instanceof BodyDeclaration) {
code = CodeFormatter.K_CLASS_BODY_DECLARATIONS;
}
else {
switch (node.getNodeType()) {
case ASTNode.ARRAY_TYPE:
case ASTNode.PARAMETERIZED_TYPE:
case ASTNode.PRIMITIVE_TYPE:
case ASTNode.QUALIFIED_TYPE:
case ASTNode.SIMPLE_TYPE:
suffix = " x;"; //$NON-NLS-1$
code = CodeFormatter.K_CLASS_BODY_DECLARATIONS;
break;
case ASTNode.WILDCARD_TYPE:
prefix = "A<"; //$NON-NLS-1$
suffix = "> x;"; //$NON-NLS-1$
code = CodeFormatter.K_CLASS_BODY_DECLARATIONS;
break;
case ASTNode.COMPILATION_UNIT:
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
case ASTNode.SINGLE_VARIABLE_DECLARATION:
suffix = ";"; //$NON-NLS-1$
code = CodeFormatter.K_STATEMENTS;
break;
case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
prefix = "A "; //$NON-NLS-1$
suffix = ";"; //$NON-NLS-1$
code = CodeFormatter.K_STATEMENTS;
break;
case ASTNode.PACKAGE_DECLARATION:
case ASTNode.IMPORT_DECLARATION:
suffix = "\nclass A {}"; //$NON-NLS-1$
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.JAVADOC:
suffix = "\nclass A {}"; //$NON-NLS-1$
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.CATCH_CLAUSE:
prefix = "try {}"; //$NON-NLS-1$
code = CodeFormatter.K_STATEMENTS;
break;
case ASTNode.ANONYMOUS_CLASS_DECLARATION:
prefix = "new A()"; //$NON-NLS-1$
suffix = ";"; //$NON-NLS-1$
code = CodeFormatter.K_STATEMENTS;
break;
case ASTNode.MEMBER_VALUE_PAIR:
prefix = "@Author("; //$NON-NLS-1$
suffix = ") class x {}"; //$NON-NLS-1$
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.MODIFIER:
suffix = " class x {}"; //$NON-NLS-1$
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.TYPE_PARAMETER:
prefix = "class X<"; //$NON-NLS-1$
suffix = "> {}"; //$NON-NLS-1$
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.MEMBER_REF:
case ASTNode.METHOD_REF:
case ASTNode.METHOD_REF_PARAMETER:
case ASTNode.TAG_ELEMENT:
case ASTNode.TEXT_ELEMENT:
// javadoc formatting disabled due to bug 93644
return null;
// wiat for bug 93644
// case ASTNode.MEMBER_REF:
// case ASTNode.METHOD_REF:
// prefix= "/**\n * @see ";
// suffix= "\n*/";
// code= CodeFormatter.K_JAVA_DOC;
// break;
// case ASTNode.METHOD_REF_PARAMETER:
// prefix= "/**\n * @see A#foo(";
// suffix= ")\n*/";
// code= CodeFormatter.K_JAVA_DOC;
// break;
// case ASTNode.TAG_ELEMENT:
// case ASTNode.TEXT_ELEMENT:
// prefix= "/**\n * ";
// suffix= "\n*/";
// code= CodeFormatter.K_JAVA_DOC;
// break;
default:
//Assert.isTrue(false, "Node type not covered: " + node.getClass().getName());
return null;
}
}
String concatStr = prefix + str + suffix;
TextEdit edit = ToolFactory.createCodeFormatter(options).format(code, concatStr, prefix.length(), str.length(), indentationLevel, lineSeparator);
if (prefix.length() > 0) {
edit = shifEdit(edit, prefix.length());
}
return edit;
}
private static TextEdit shifEdit(TextEdit oldEdit, int diff) {
TextEdit newEdit;
if (oldEdit instanceof ReplaceEdit) {
ReplaceEdit edit = (ReplaceEdit) oldEdit;
newEdit = new ReplaceEdit(edit.getOffset() - diff, edit.getLength(), edit.getText());
}
else if (oldEdit instanceof InsertEdit) {
InsertEdit edit = (InsertEdit) oldEdit;
newEdit = new InsertEdit(edit.getOffset() - diff, edit.getText());
}
else
if (oldEdit instanceof DeleteEdit) {
DeleteEdit edit = (DeleteEdit) oldEdit;
newEdit = new DeleteEdit(edit.getOffset() - diff, edit.getLength());
}
else
if (oldEdit instanceof MultiTextEdit) {
newEdit = new MultiTextEdit();
}
else {
return null; // not supported
}
TextEdit[] children = oldEdit.getChildren();
for (int i = 0; i < children.length; i++) {
TextEdit shifted = shifEdit(children[i], diff);
if (shifted != null) {
newEdit.addChild(shifted);
}
}
return newEdit;
}
|
| ||||
/**
* Creates edits that describe how to format the given string. Returns <code>null</code> if the code could not be formatted for the given kind.
* @throws IllegalArgumentException If the offset and length are not inside the string, a
* IllegalArgumentException is thrown.
*/
public static TextEdit format2(ASTNode node, String str, int indentationLevel, String lineSeparator, Map options) {
int code;
String prefix = ""; //$NON-NLS-1$
String suffix = ""; //$NON-NLS-1$
if (node instanceof Statement) {
code = CodeFormatter.K_STATEMENTS;
if (node.getNodeType() == ASTNode.SWITCH_CASE) {
prefix = "switch(1) {"; //$NON-NLS-1$
suffix = "}"; //$NON-NLS-1$
code = CodeFormatter.K_STATEMENTS;
}
}
else if (node instanceof Expression && node.getNodeType() != ASTNode.VARIABLE_DECLARATION_EXPRESSION) {
code = CodeFormatter.K_EXPRESSION;
}
else
if (node instanceof BodyDeclaration) {
code = CodeFormatter.K_CLASS_BODY_DECLARATIONS;
}
else {
switch (node.getNodeType()) {
case ASTNode.ARRAY_TYPE:
case ASTNode.PARAMETERIZED_TYPE:
case ASTNode.PRIMITIVE_TYPE:
case ASTNode.QUALIFIED_TYPE:
case ASTNode.SIMPLE_TYPE:
suffix = " x;"; //$NON-NLS-1$
code = CodeFormatter.K_CLASS_BODY_DECLARATIONS;
break;
case ASTNode.WILDCARD_TYPE:
prefix = "A<"; //$NON-NLS-1$
suffix = "> x;"; //$NON-NLS-1$
code = CodeFormatter.K_CLASS_BODY_DECLARATIONS;
break;
case ASTNode.COMPILATION_UNIT:
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
case ASTNode.SINGLE_VARIABLE_DECLARATION:
suffix = ";"; //$NON-NLS-1$
code = CodeFormatter.K_STATEMENTS;
break;
case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
prefix = "A "; //$NON-NLS-1$
suffix = ";"; //$NON-NLS-1$
code = CodeFormatter.K_STATEMENTS;
break;
case ASTNode.PACKAGE_DECLARATION:
case ASTNode.IMPORT_DECLARATION:
suffix = "\nclass A {}"; //$NON-NLS-1$
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.JAVADOC:
suffix = "void foo();"; //$NON-NLS-1$
code = CodeFormatter.K_CLASS_BODY_DECLARATIONS;
break;
case ASTNode.CATCH_CLAUSE:
prefix = "try {}"; //$NON-NLS-1$
code = CodeFormatter.K_STATEMENTS;
break;
case ASTNode.ANONYMOUS_CLASS_DECLARATION:
prefix = "new A()"; //$NON-NLS-1$
suffix = ";"; //$NON-NLS-1$
code = CodeFormatter.K_STATEMENTS;
break;
case ASTNode.MEMBER_VALUE_PAIR:
prefix = "@Author("; //$NON-NLS-1$
suffix = ") class x {}"; //$NON-NLS-1$
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.MODIFIER:
suffix = " class x {}"; //$NON-NLS-1$
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.TYPE_PARAMETER:
prefix = "class X<"; //$NON-NLS-1$
suffix = "> {}"; //$NON-NLS-1$
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.MEMBER_REF:
case ASTNode.METHOD_REF:
case ASTNode.METHOD_REF_PARAMETER:
case ASTNode.TAG_ELEMENT:
case ASTNode.TEXT_ELEMENT:
// Javadoc formatting not yet supported:
return null;
default:
//Assert.isTrue(false, "Node type not covered: " + node.getClass().getName()); //$NON-NLS-1$
return null;
}
}
String concatStr = prefix + str + suffix;
TextEdit edit = ToolFactory.createCodeFormatter(options).format(code, concatStr, prefix.length(), str.length(), indentationLevel, lineSeparator);
if (prefix.length() > 0) {
edit = shifEdit(edit, prefix.length());
}
return edit;
}
private static TextEdit shifEdit(TextEdit oldEdit, int diff) {
TextEdit newEdit;
if (oldEdit instanceof ReplaceEdit) {
ReplaceEdit edit = (ReplaceEdit) oldEdit;
newEdit = new ReplaceEdit(edit.getOffset() - diff, edit.getLength(), edit.getText());
}
else if (oldEdit instanceof InsertEdit) {
InsertEdit edit = (InsertEdit) oldEdit;
newEdit = new InsertEdit(edit.getOffset() - diff, edit.getText());
}
else
if (oldEdit instanceof DeleteEdit) {
DeleteEdit edit = (DeleteEdit) oldEdit;
newEdit = new DeleteEdit(edit.getOffset() - diff, edit.getLength());
}
else
if (oldEdit instanceof MultiTextEdit) {
newEdit = new MultiTextEdit();
}
else {
return null; // not supported
}
TextEdit[] children = oldEdit.getChildren();
for (int i = 0; i < children.length; i++) {
TextEdit shifted = shifEdit(children[i], diff);
if (shifted != null) {
newEdit.addChild(shifted);
}
}
return newEdit;
}
|
| |||
[[#variable5447e220]]static TextEdit [[#variable5447e1c0]](ASTNode node, String str, int indentationLevel, String lineSeparator, Map options) {
int code;
String prefix = ""; //$NON-NLS-1$
String suffix = ""; //$NON-NLS-1$
if (node instanceof Statement) {
code = CodeFormatter.K_STATEMENTS;
if (node.getNodeType() == ASTNode.SWITCH_CASE) {
prefix = "switch(1) {"; //$NON-NLS-1$
suffix = "}"; //$NON-NLS-1$
code = CodeFormatter.K_STATEMENTS;
}
}
else
if (node instanceof Expression && node.getNodeType() != ASTNode.VARIABLE_DECLARATION_EXPRESSION) {
code = CodeFormatter.K_EXPRESSION;
}
else
if (node instanceof BodyDeclaration) {
code = CodeFormatter.K_CLASS_BODY_DECLARATIONS;
}
else {
switch (node.getNodeType()) {
case ASTNode.ARRAY_TYPE:
case ASTNode.PARAMETERIZED_TYPE:
case ASTNode.PRIMITIVE_TYPE:
case ASTNode.QUALIFIED_TYPE:
case ASTNode.SIMPLE_TYPE:
suffix = " x;"; //$NON-NLS-1$
code = CodeFormatter.K_CLASS_BODY_DECLARATIONS;
break;
case ASTNode.WILDCARD_TYPE:
prefix = "A<"; //$NON-NLS-1$
suffix = "> x;"; //$NON-NLS-1$
code = CodeFormatter.K_CLASS_BODY_DECLARATIONS;
break;
case ASTNode.COMPILATION_UNIT:
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
case ASTNode.SINGLE_VARIABLE_DECLARATION:
suffix = ";"; //$NON-NLS-1$
code = CodeFormatter.K_STATEMENTS;
break;
case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
prefix = "A "; //$NON-NLS-1$
suffix = ";"; //$NON-NLS-1$
code = CodeFormatter.K_STATEMENTS;
break;
case ASTNode.PACKAGE_DECLARATION:
case ASTNode.IMPORT_DECLARATION:
suffix = "\nclass A {}"; //$NON-NLS-1$
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.JAVADOC:
suffix = [[#variable5447ed20]]; //$NON-NLS-1$
code = CodeFormatter. [[#variable5447e180]];
break;
case ASTNode.CATCH_CLAUSE:
prefix = "try {}"; //$NON-NLS-1$
code = CodeFormatter.K_STATEMENTS;
break;
case ASTNode.ANONYMOUS_CLASS_DECLARATION:
prefix = "new A()"; //$NON-NLS-1$
suffix = ";"; //$NON-NLS-1$
code = CodeFormatter.K_STATEMENTS;
break;
case ASTNode.MEMBER_VALUE_PAIR:
prefix = "@Author("; //$NON-NLS-1$
suffix = ") class x {}"; //$NON-NLS-1$
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.MODIFIER:
suffix = " class x {}"; //$NON-NLS-1$
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.TYPE_PARAMETER:
prefix = "class X<"; //$NON-NLS-1$
suffix = "> {}"; //$NON-NLS-1$
code = CodeFormatter.K_COMPILATION_UNIT;
break;
case ASTNode.MEMBER_REF:
case ASTNode.METHOD_REF:
case ASTNode.METHOD_REF_PARAMETER:
case ASTNode.TAG_ELEMENT:
case ASTNode.TEXT_ELEMENT:
// Javadoc formatting not yet supported:
// javadoc formatting disabled due to bug 93644
return null;
// wiat for bug 93644
// case ASTNode.MEMBER_REF:
// case ASTNode.METHOD_REF:
// prefix= "/**\n * @see ";
// suffix= "\n*/";
// code= CodeFormatter.K_JAVA_DOC;
// break;
// case ASTNode.METHOD_REF_PARAMETER:
// prefix= "/**\n * @see A#foo(";
// suffix= ")\n*/";
// code= CodeFormatter.K_JAVA_DOC;
// break;
// case ASTNode.TAG_ELEMENT:
// case ASTNode.TEXT_ELEMENT:
// prefix= "/**\n * ";
// suffix= "\n*/";
// code= CodeFormatter.K_JAVA_DOC;
// break;
default:
//Assert.isTrue(false, "Node type not covered: " + node.getClass().getName()); //$NON-NLS-1$
//Assert.isTrue(false, "Node type not covered: " + node.getClass().getName());
return null;
}
}
String concatStr = prefix + str + suffix;
TextEdit edit = ToolFactory.createCodeFormatter(options).format(code, concatStr, prefix.length(), str.length(), indentationLevel, lineSeparator);
if (prefix.length() > 0) {
edit = shifEdit(edit, prefix.length());
}
return edit;
}
private static TextEdit shifEdit(TextEdit oldEdit, int diff) {
TextEdit newEdit;
if (oldEdit instanceof ReplaceEdit) {
ReplaceEdit edit = (ReplaceEdit) oldEdit;
newEdit = new ReplaceEdit(edit.getOffset() - diff, edit.getLength(), edit.getText());
}
else
if (oldEdit instanceof InsertEdit) {
InsertEdit edit = (InsertEdit) oldEdit;
newEdit = new InsertEdit(edit.getOffset() - diff, edit.getText());
}
else
if (oldEdit instanceof DeleteEdit) {
DeleteEdit edit = (DeleteEdit) oldEdit;
newEdit = new DeleteEdit(edit.getOffset() - diff, edit.getLength());
}
else
if (oldEdit instanceof MultiTextEdit) {
newEdit = new MultiTextEdit();
}
else {
return null; // not supported
}
TextEdit[] children = oldEdit.getChildren();
for (int i = 0; i < children.length; i++) {
TextEdit shifted = shifEdit(children[i], diff);
if (shifted != null) {
newEdit.addChild(shifted);
}
}
return newEdit;
}
|
| CloneAbstraction |
| Parameter Index | Clone Instance | Parameter Name | Value |
|---|---|---|---|
| 1 | 1 | [[#5447e220]] | /** * Creates edits that describe how to format the given string. Returns <code>null</code> if the code could not be formatted for the given kind. * @throws IllegalArgumentException If the offset and length are not inside the string, a * IllegalArgumentException is thrown. */ public |
| 1 | 2 | [[#5447e220]] | /** * Creates edits that describe how to format the given string. Returns <code>null</code> if the code could not be formatted for the given kind. * @param node Node describing the type of the string * @param str The unformatted string * @param indentationLevel * @param lineSeparator * @param options * @return Returns the edit representing the result of the formatter * @throws IllegalArgumentException If the offset and length are not inside the string, a * IllegalArgumentException is thrown. */ private |
| 2 | 1 | [[#5447e1c0]] | format2 |
| 2 | 2 | [[#5447e1c0]] | formatNode |
| 3 | 1 | [[#5447ed20]] | "void foo();" |
| 3 | 2 | [[#5447ed20]] | "\nclass A {}" |
| 4 | 1 | [[#5447e180]] | K_CLASS_BODY_DECLARATIONS |
| 4 | 2 | [[#5447e180]] | K_COMPILATION_UNIT |