本文整理汇总了Java中org.eclipse.jdt.core.dom.EnumConstantDeclaration.setName方法的典型用法代码示例。如果您正苦于以下问题:Java EnumConstantDeclaration.setName方法的具体用法?Java EnumConstantDeclaration.setName怎么用?Java EnumConstantDeclaration.setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.EnumConstantDeclaration
的用法示例。
在下文中一共展示了EnumConstantDeclaration.setName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doAddEnumConst
import org.eclipse.jdt.core.dom.EnumConstantDeclaration; //导入方法依赖的package包/类
private ASTRewrite doAddEnumConst(CompilationUnit astRoot) {
SimpleName node= fOriginalNode;
ASTNode newTypeDecl= astRoot.findDeclaringNode(fSenderBinding);
if (newTypeDecl == null) {
astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
}
if (newTypeDecl != null) {
AST ast= newTypeDecl.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
EnumConstantDeclaration constDecl= ast.newEnumConstantDeclaration();
constDecl.setName(ast.newSimpleName(node.getIdentifier()));
ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, EnumDeclaration.ENUM_CONSTANTS_PROPERTY);
listRewriter.insertLast(constDecl, null);
return rewrite;
}
return null;
}
示例2: doAddEnumConst
import org.eclipse.jdt.core.dom.EnumConstantDeclaration; //导入方法依赖的package包/类
private ASTRewrite doAddEnumConst(CompilationUnit astRoot) {
SimpleName node= fOriginalNode;
ASTNode newTypeDecl= astRoot.findDeclaringNode(fSenderBinding);
if (newTypeDecl == null) {
astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
}
if (newTypeDecl != null) {
AST ast= newTypeDecl.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
EnumConstantDeclaration constDecl= ast.newEnumConstantDeclaration();
constDecl.setName(ast.newSimpleName(node.getIdentifier()));
ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, EnumDeclaration.ENUM_CONSTANTS_PROPERTY);
listRewriter.insertLast(constDecl, null);
addLinkedPosition(rewrite.track(constDecl.getName()), false, KEY_NAME);
return rewrite;
}
return null;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:27,代码来源:NewVariableCorrectionProposal.java
示例3: writeLabels
import org.eclipse.jdt.core.dom.EnumConstantDeclaration; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void writeLabels(Collection<String> labels) {
if (labels.isEmpty())
return;
EnumDeclaration enumType = getAST().newEnumDeclaration();
enumType.setName(getAST().newSimpleName("TAG"));
enumType.modifiers().add(getAST().newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
enumType.modifiers().add(getAST().newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD));
// elements
int num = 0;
for (String label : labels) {
EnumConstantDeclaration constantDeclaration = getAST().newEnumConstantDeclaration();
constantDeclaration.setName(getAST().newSimpleName(normalizeEnumName(label)));
enumType.enumConstants().add(num, constantDeclaration);
num++;
}
getTarget().bodyDeclarations().add(enumType);
}
示例4: writeMessages
import org.eclipse.jdt.core.dom.EnumConstantDeclaration; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void writeMessages(Collection<String> messages) {
EnumDeclaration enumType = getAST().newEnumDeclaration();
enumType.setName(getAST().newSimpleName("QCPFMSG"));
enumType.modifiers().add(getAST().newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
enumType.modifiers().add(getAST().newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD));
// elements
int num = 0;
for (String message : messages) {
if (message.equalsIgnoreCase("CPF0000"))
continue;
EnumConstantDeclaration constantDeclaration = getAST().newEnumConstantDeclaration();
constantDeclaration.setName(getAST().newSimpleName(normalizeEnumName(message)));
enumType.enumConstants().add(num, constantDeclaration);
num++;
}
getTarget().bodyDeclarations().add(enumType);
}
示例5: createNewEnumConstantDeclarataion
import org.eclipse.jdt.core.dom.EnumConstantDeclaration; //导入方法依赖的package包/类
private static EnumConstantDeclaration createNewEnumConstantDeclarataion(
AST ast, SimpleName constantName, Javadoc docComment,
Collection annotationCollection) {
final EnumConstantDeclaration enumConstDecl = ast
.newEnumConstantDeclaration();
enumConstDecl.setJavadoc(docComment);
enumConstDecl.setName(constantName);
enumConstDecl.modifiers().addAll(annotationCollection);
return enumConstDecl;
}
开发者ID:ponder-lab,项目名称:Constants-to-Enum-Eclipse-Plugin,代码行数:11,代码来源:ConvertConstantsToEnumRefactoring.java
示例6: doAddEnumConst
import org.eclipse.jdt.core.dom.EnumConstantDeclaration; //导入方法依赖的package包/类
private ASTRewrite doAddEnumConst(CompilationUnit astRoot) {
SimpleName node = fOriginalNode;
ASTNode newTypeDecl = astRoot.findDeclaringNode(fSenderBinding);
if (newTypeDecl == null) {
astRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null);
newTypeDecl = astRoot.findDeclaringNode(fSenderBinding.getKey());
}
if (newTypeDecl != null) {
AST ast = newTypeDecl.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
EnumConstantDeclaration constDecl = ast.newEnumConstantDeclaration();
constDecl.setName(ast.newSimpleName(node.getIdentifier()));
ListRewrite listRewriter =
rewrite.getListRewrite(newTypeDecl, EnumDeclaration.ENUM_CONSTANTS_PROPERTY);
listRewriter.insertLast(constDecl, null);
addLinkedPosition(rewrite.track(constDecl.getName()), false, KEY_NAME);
return rewrite;
}
return null;
}
示例7: buildEnumDeclaration
import org.eclipse.jdt.core.dom.EnumConstantDeclaration; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private EnumDeclaration buildEnumDeclaration(AST ast, String name, List<QMessageDescription> messageDescriptions) {
// write AST
EnumDeclaration enumDeclaration = ast.newEnumDeclaration();
enumDeclaration.setName(ast.newSimpleName(name));
enumDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
for (QMessageDescription messageDescription : messageDescriptions) {
EnumConstantDeclaration constantDeclaration = ast.newEnumConstantDeclaration();
constantDeclaration.setName(ast.newSimpleName(messageDescription.getName()));
enumDeclaration.enumConstants().add(constantDeclaration);
/*
* Javadoc javadoc = ast.newJavadoc(); TagElement tag =
* javadoc.getAST().newTagElement(); TextElement textElement =
* javadoc.getAST().newTextElement();
* textElement.setText(messageDescription.getMessageText());
* tag.fragments().add(textElement); javadoc.tags().add(tag);
*
* constantDeclaration.setJavadoc(javadoc);
*/
}
return enumDeclaration;
}
示例8: writeIndex
import org.eclipse.jdt.core.dom.EnumConstantDeclaration; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void writeIndex(List<QFileFormatKey> keys, boolean unique) {
if (keys.isEmpty())
return;
EnumDeclaration enumType = getAST().newEnumDeclaration();
writeAnnotation(enumType, Index.class, "unique", unique);
enumType.setName(getAST().newSimpleName("INDEX_COLUMNS"));
enumType.modifiers().add(getAST().newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
enumType.modifiers().add(getAST().newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD));
// elements
int num = 0;
for (QFileFormatKey key : keys) {
EnumConstantDeclaration constantDeclaration = getAST().newEnumConstantDeclaration();
constantDeclaration.setName(getAST().newSimpleName(getCompilationUnit().normalizeTermName(key.getName())));
if(key.isDescend())
writeAnnotation(constantDeclaration, Descend.class);
enumType.enumConstants().add(num, constantDeclaration);
num++;
}
getTarget().bodyDeclarations().add(enumType);
}
示例9: effectiveAddLiteral
import org.eclipse.jdt.core.dom.EnumConstantDeclaration; //导入方法依赖的package包/类
/**
* Refactors the source code to replace selected source by literal.
*
* @param nodeFinder
* @param literalName
* @param resolver
* @return
*/
@SuppressWarnings("unchecked")
private boolean effectiveAddLiteral(final ASTNodeFinder nodeFinder, final String literalName,
final ASTExpressionResolver resolver) {
final ASTNode parent = nodeFinder.getParentNode();
final AST ast = parent.getAST();
final MethodInvocation replacement = ast.newMethodInvocation();
replacement.setExpression(ast.newName(this.resourceBundleName + "." + literalName));
replacement.setName(ast.newSimpleName("value"));
final EnumDeclaration enumDeclaration = (EnumDeclaration) this.enumDomCompilationUnit.types().get(0);
final EnumConstantDeclaration enumConstantDeclaration = enumDeclaration.getAST().newEnumConstantDeclaration();
enumConstantDeclaration.setName(enumDeclaration.getAST().newSimpleName(literalName));
enumDeclaration.enumConstants().add(enumConstantDeclaration);
boolean hasMessageKeyConstructor = false;
for (final Iterator<Object> iterator = enumDeclaration.bodyDeclarations().iterator(); iterator.hasNext()
&& !hasMessageKeyConstructor;) {
final Object next = iterator.next();
if (next instanceof MethodDeclaration) {
final MethodDeclaration methodDeclaration = (MethodDeclaration) next;
if (methodDeclaration.isConstructor() && methodDeclaration.parameters().size() > 0) {
hasMessageKeyConstructor = true;
}
}
}
if (hasMessageKeyConstructor) {
final StringLiteral literal = enumDeclaration.getAST().newStringLiteral();
literal.setLiteralValue(literalName);
enumConstantDeclaration.arguments().add(literal);
}
StructuralPropertyDescriptor locationInParent = null;
if (nodeFinder.getFoundNode() != null) {
locationInParent = nodeFinder.getFoundNode().getLocationInParent();
} else {
// TODO
return false;
}
ResourceBundleWrapper.addImportToCompilationUnitIfMissing(nodeFinder.getParentNode(), this.packageName + "."
+ this.resourceBundleName);
if (locationInParent.isChildListProperty()) {
final List<Object> list = (List<Object>) parent.getStructuralProperty(locationInParent);
final int index = list.indexOf(nodeFinder.getFoundNode());
list.remove(nodeFinder.getFoundNode());
list.add(index, replacement);
} else {
parent.setStructuralProperty(locationInParent, replacement);
}
for (final Expression parameter : resolver.getMessageParameters()) {
final Expression newParameter = ASTTreeCloner.clone(parameter);
replacement.arguments().add(newParameter);
}
String messagePattern = resolver.getMessagePattern();
if (this.prefixMessageByKey) {
messagePattern = String.format("[%s] %s", literalName, messagePattern);
}
this.properties.put(literalName, messagePattern);
return true;
}