本文整理汇总了Java中org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor类的典型用法代码示例。如果您正苦于以下问题:Java ModifierCorrectionSubProcessor类的具体用法?Java ModifierCorrectionSubProcessor怎么用?Java ModifierCorrectionSubProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ModifierCorrectionSubProcessor类属于org.eclipse.jdt.internal.ui.text.correction包,在下文中一共展示了ModifierCorrectionSubProcessor类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doAddField
import org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor; //导入依赖的package包/类
private ASTRewrite doAddField(CompilationUnit astRoot) {
SimpleName node = fOriginalNode;
boolean isInDifferentCU = false;
ASTNode newTypeDecl = astRoot.findDeclaringNode(fSenderBinding);
if (newTypeDecl == null) {
astRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null);
newTypeDecl = astRoot.findDeclaringNode(fSenderBinding.getKey());
isInDifferentCU = true;
}
ImportRewrite imports = createImportRewrite(astRoot);
ImportRewriteContext importRewriteContext =
new ContextSensitiveImportRewriteContext(
ASTResolving.findParentBodyDeclaration(node), imports);
if (newTypeDecl != null) {
AST ast = newTypeDecl.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
fragment.setName(ast.newSimpleName(node.getIdentifier()));
Type type = evaluateVariableType(ast, imports, importRewriteContext, fSenderBinding);
FieldDeclaration newDecl = ast.newFieldDeclaration(fragment);
newDecl.setType(type);
newDecl
.modifiers()
.addAll(ASTNodeFactory.newModifiers(ast, evaluateFieldModifiers(newTypeDecl)));
if (fSenderBinding.isInterface() || fVariableKind == CONST_FIELD) {
fragment.setInitializer(ASTNodeFactory.newDefaultExpression(ast, type, 0));
}
ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
List<BodyDeclaration> decls =
ASTNodes.<BodyDeclaration>getChildListProperty(newTypeDecl, property);
int maxOffset = isInDifferentCU ? -1 : node.getStartPosition();
int insertIndex = findFieldInsertIndex(decls, newDecl, maxOffset);
ListRewrite listRewriter = rewrite.getListRewrite(newTypeDecl, property);
listRewriter.insertAt(newDecl, insertIndex, null);
ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(
getLinkedProposalModel(), rewrite, newDecl.modifiers(), fSenderBinding.isInterface());
addLinkedPosition(rewrite.track(newDecl.getType()), false, KEY_TYPE);
if (!isInDifferentCU) {
addLinkedPosition(rewrite.track(node), true, KEY_NAME);
}
addLinkedPosition(rewrite.track(fragment.getName()), false, KEY_NAME);
if (fragment.getInitializer() != null) {
addLinkedPosition(rewrite.track(fragment.getInitializer()), false, KEY_INITIALIZER);
}
return rewrite;
}
return null;
}
示例2: addFieldDeclaration
import org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor; //导入依赖的package包/类
private VariableDeclarationFragment addFieldDeclaration(
ASTRewrite rewrite, ASTNode newTypeDecl, int modifiers, Expression expression) {
if (fExistingFragment != null) {
return fExistingFragment;
}
ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
List<BodyDeclaration> decls = ASTNodes.getBodyDeclarations(newTypeDecl);
AST ast = newTypeDecl.getAST();
String[] varNames = suggestFieldNames(fTypeBinding, expression, modifiers);
for (int i = 0; i < varNames.length; i++) {
addLinkedPositionProposal(KEY_NAME, varNames[i], null);
}
String varName = varNames[0];
VariableDeclarationFragment newDeclFrag = ast.newVariableDeclarationFragment();
newDeclFrag.setName(ast.newSimpleName(varName));
FieldDeclaration newDecl = ast.newFieldDeclaration(newDeclFrag);
Type type = evaluateType(ast);
newDecl.setType(type);
newDecl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, modifiers));
ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(
getLinkedProposalModel(), rewrite, newDecl.modifiers(), false);
int insertIndex = findFieldInsertIndex(decls, fNodeToAssign.getStartPosition());
rewrite.getListRewrite(newTypeDecl, property).insertAt(newDecl, insertIndex, null);
return newDeclFrag;
}
示例3: createConstantDeclaration
import org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor; //导入依赖的package包/类
private void createConstantDeclaration() throws CoreException {
Type type = getConstantType();
IExpressionFragment fragment = getSelectedExpression();
Expression initializer =
getSelectedExpression().createCopyTarget(fCuRewrite.getASTRewrite(), true);
AST ast = fCuRewrite.getAST();
VariableDeclarationFragment variableDeclarationFragment = ast.newVariableDeclarationFragment();
variableDeclarationFragment.setName(ast.newSimpleName(fConstantName));
variableDeclarationFragment.setInitializer(initializer);
FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(variableDeclarationFragment);
fieldDeclaration.setType(type);
Modifier.ModifierKeyword accessModifier = Modifier.ModifierKeyword.toKeyword(fVisibility);
if (accessModifier != null) fieldDeclaration.modifiers().add(ast.newModifier(accessModifier));
fieldDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD));
fieldDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));
boolean createComments =
JavaPreferencesSettings.getCodeGenerationSettings(fCu.getJavaProject()).createComments;
if (createComments) {
String comment =
CodeGeneration.getFieldComment(
fCu, getConstantTypeName(), fConstantName, StubUtility.getLineDelimiterUsed(fCu));
if (comment != null && comment.length() > 0) {
Javadoc doc =
(Javadoc) fCuRewrite.getASTRewrite().createStringPlaceholder(comment, ASTNode.JAVADOC);
fieldDeclaration.setJavadoc(doc);
}
}
AbstractTypeDeclaration parent = getContainingTypeDeclarationNode();
ListRewrite listRewrite =
fCuRewrite.getASTRewrite().getListRewrite(parent, parent.getBodyDeclarationsProperty());
TextEditGroup msg =
fCuRewrite.createGroupDescription(
RefactoringCoreMessages.ExtractConstantRefactoring_declare_constant);
if (insertFirst()) {
listRewrite.insertFirst(fieldDeclaration, msg);
} else {
listRewrite.insertAfter(fieldDeclaration, getNodeToInsertConstantDeclarationAfter(), msg);
}
if (fLinkedProposalModel != null) {
ASTRewrite rewrite = fCuRewrite.getASTRewrite();
LinkedProposalPositionGroup nameGroup = fLinkedProposalModel.getPositionGroup(KEY_NAME, true);
nameGroup.addPosition(rewrite.track(variableDeclarationFragment.getName()), true);
String[] nameSuggestions = guessConstantNames();
if (nameSuggestions.length > 0 && !nameSuggestions[0].equals(fConstantName)) {
nameGroup.addProposal(fConstantName, null, nameSuggestions.length + 1);
}
for (int i = 0; i < nameSuggestions.length; i++) {
nameGroup.addProposal(nameSuggestions[i], null, nameSuggestions.length - i);
}
LinkedProposalPositionGroup typeGroup = fLinkedProposalModel.getPositionGroup(KEY_TYPE, true);
typeGroup.addPosition(rewrite.track(type), true);
ITypeBinding typeBinding = guessBindingForReference(fragment.getAssociatedExpression());
if (typeBinding != null) {
ITypeBinding[] relaxingTypes = ASTResolving.getNarrowingTypes(ast, typeBinding);
for (int i = 0; i < relaxingTypes.length; i++) {
typeGroup.addProposal(relaxingTypes[i], fCuRewrite.getCu(), relaxingTypes.length - i);
}
}
boolean isInterface =
parent.resolveBinding() != null && parent.resolveBinding().isInterface();
ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(
fLinkedProposalModel, rewrite, fieldDeclaration.modifiers(), isInterface);
}
}
示例4: addNewModifiers
import org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor; //导入依赖的package包/类
@Override
protected void addNewModifiers(
ASTRewrite rewrite, ASTNode targetTypeDecl, List<IExtendedModifier> modifiers) {
modifiers.addAll(rewrite.getAST().newModifiers(evaluateModifiers(targetTypeDecl)));
ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(
getLinkedProposalModel(), rewrite, modifiers, getSenderBinding().isInterface());
}
示例5: addFieldDeclaration
import org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor; //导入依赖的package包/类
private VariableDeclarationFragment addFieldDeclaration(ASTRewrite rewrite, ASTNode newTypeDecl, int modifiers, Expression expression) {
if (fExistingFragment != null) {
return fExistingFragment;
}
ChildListPropertyDescriptor property= ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
List<BodyDeclaration> decls= ASTNodes.getBodyDeclarations(newTypeDecl);
AST ast= newTypeDecl.getAST();
String[] varNames= suggestFieldNames(fTypeBinding, expression, modifiers);
for (int i= 0; i < varNames.length; i++) {
addLinkedPositionProposal(KEY_NAME, varNames[i], null);
}
String varName= varNames[0];
VariableDeclarationFragment newDeclFrag= ast.newVariableDeclarationFragment();
newDeclFrag.setName(ast.newSimpleName(varName));
FieldDeclaration newDecl= ast.newFieldDeclaration(newDeclFrag);
Type type= evaluateType(ast);
newDecl.setType(type);
newDecl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, modifiers));
ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(getLinkedProposalModel(), rewrite, newDecl.modifiers(), false);
int insertIndex= findFieldInsertIndex(decls, fNodeToAssign.getStartPosition());
rewrite.getListRewrite(newTypeDecl, property).insertAt(newDecl, insertIndex, null);
return newDeclFrag;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:31,代码来源:AssignToVariableAssistProposal.java
示例6: addFieldDeclaration
import org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor; //导入依赖的package包/类
private VariableDeclarationFragment addFieldDeclaration(ASTRewrite rewrite, ASTNode newTypeDecl, int modifiers, Expression expression) {
if (fExistingFragment != null) {
return fExistingFragment;
}
ChildListPropertyDescriptor property= ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
List<BodyDeclaration> decls= (List<BodyDeclaration>) newTypeDecl.getStructuralProperty(property);
AST ast= newTypeDecl.getAST();
String[] varNames= suggestFieldNames(fTypeBinding, expression, modifiers);
for (int i= 0; i < varNames.length; i++) {
addLinkedPositionProposal(KEY_NAME, varNames[i], null);
}
String varName= varNames[0];
VariableDeclarationFragment newDeclFrag= ast.newVariableDeclarationFragment();
newDeclFrag.setName(ast.newSimpleName(varName));
FieldDeclaration newDecl= ast.newFieldDeclaration(newDeclFrag);
Type type= evaluateType(ast);
newDecl.setType(type);
newDecl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, modifiers));
ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(getLinkedProposalModel(), rewrite, newDecl.modifiers(), false);
int insertIndex= findFieldInsertIndex(decls, fNodeToAssign.getStartPosition());
rewrite.getListRewrite(newTypeDecl, property).insertAt(newDecl, insertIndex, null);
return newDeclFrag;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:31,代码来源:AssignToVariableAssistProposal.java
示例7: createNewNestedClass
import org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor; //导入依赖的package包/类
private AbstractTypeDeclaration createNewNestedClass(
CompilationUnitRewrite rewrite, ITypeBinding[] typeParameters) throws CoreException {
final AST ast = fAnonymousInnerClassNode.getAST();
final TypeDeclaration newDeclaration = ast.newTypeDeclaration();
newDeclaration.setInterface(false);
newDeclaration.setJavadoc(null);
newDeclaration
.modifiers()
.addAll(ASTNodeFactory.newModifiers(ast, createModifiersForNestedClass()));
newDeclaration.setName(ast.newSimpleName(fClassName));
TypeParameter parameter = null;
for (int index = 0; index < typeParameters.length; index++) {
parameter = ast.newTypeParameter();
parameter.setName(ast.newSimpleName(typeParameters[index].getName()));
newDeclaration.typeParameters().add(parameter);
}
setSuperType(newDeclaration);
IJavaProject project = fCu.getJavaProject();
IVariableBinding[] bindings = getUsedLocalVariables();
ArrayList<String> fieldNames = new ArrayList<String>();
for (int i = 0; i < bindings.length; i++) {
String name = StubUtility.getBaseName(bindings[i], project);
String[] fieldNameProposals =
StubUtility.getVariableNameSuggestions(
NamingConventions.VK_INSTANCE_FIELD, project, name, 0, fieldNames, true);
fieldNames.add(fieldNameProposals[0]);
if (fLinkedProposalModel != null) {
LinkedProposalPositionGroup positionGroup =
fLinkedProposalModel.getPositionGroup(KEY_FIELD_NAME_EXT + i, true);
for (int k = 0; k < fieldNameProposals.length; k++) {
positionGroup.addProposal(fieldNameProposals[k], null, fieldNameProposals.length - k);
}
}
}
String[] allFieldNames = fieldNames.toArray(new String[fieldNames.size()]);
List<BodyDeclaration> newBodyDeclarations = newDeclaration.bodyDeclarations();
createFieldsForAccessedLocals(rewrite, bindings, allFieldNames, newBodyDeclarations);
MethodDeclaration newConstructorDecl = createNewConstructor(rewrite, bindings, allFieldNames);
if (newConstructorDecl != null) {
newBodyDeclarations.add(newConstructorDecl);
}
updateAndMoveBodyDeclarations(
rewrite, bindings, allFieldNames, newBodyDeclarations, newConstructorDecl);
if (doAddComments()) {
String[] parameterNames = new String[typeParameters.length];
for (int index = 0; index < parameterNames.length; index++) {
parameterNames[index] = typeParameters[index].getName();
}
String string =
CodeGeneration.getTypeComment(
rewrite.getCu(), fClassName, parameterNames, StubUtility.getLineDelimiterUsed(fCu));
if (string != null) {
Javadoc javadoc =
(Javadoc) rewrite.getASTRewrite().createStringPlaceholder(string, ASTNode.JAVADOC);
newDeclaration.setJavadoc(javadoc);
}
}
if (fLinkedProposalModel != null) {
addLinkedPosition(KEY_TYPE_NAME, newDeclaration.getName(), rewrite.getASTRewrite(), false);
ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(
fLinkedProposalModel, rewrite.getASTRewrite(), newDeclaration.modifiers(), false);
}
return newDeclaration;
}
示例8: getStub
import org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor; //导入依赖的package包/类
private AnnotationTypeMemberDeclaration getStub(
ASTRewrite rewrite, AnnotationTypeDeclaration targetTypeDecl) {
AST ast = targetTypeDecl.getAST();
AnnotationTypeMemberDeclaration decl = ast.newAnnotationTypeMemberDeclaration();
SimpleName newNameNode = getNewName(rewrite);
decl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, evaluateModifiers(targetTypeDecl)));
ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(
getLinkedProposalModel(), rewrite, decl.modifiers(), true);
decl.setName(newNameNode);
Type returnType = getNewType(rewrite);
decl.setType(returnType);
return decl;
}
示例9: createNewNestedClass
import org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor; //导入依赖的package包/类
private AbstractTypeDeclaration createNewNestedClass(CompilationUnitRewrite rewrite, ITypeBinding[] typeParameters) throws CoreException {
final AST ast= fAnonymousInnerClassNode.getAST();
final TypeDeclaration newDeclaration= ast.newTypeDeclaration();
newDeclaration.setInterface(false);
newDeclaration.setJavadoc(null);
newDeclaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiersForNestedClass()));
newDeclaration.setName(ast.newSimpleName(fClassName));
TypeParameter parameter= null;
for (int index= 0; index < typeParameters.length; index++) {
parameter= ast.newTypeParameter();
parameter.setName(ast.newSimpleName(typeParameters[index].getName()));
newDeclaration.typeParameters().add(parameter);
}
setSuperType(newDeclaration);
IJavaProject project= fCu.getJavaProject();
IVariableBinding[] bindings= getUsedLocalVariables();
ArrayList<String> fieldNames= new ArrayList<String>();
for (int i= 0; i < bindings.length; i++) {
String name= StubUtility.getBaseName(bindings[i], project);
String[] fieldNameProposals= StubUtility.getVariableNameSuggestions(NamingConventions.VK_INSTANCE_FIELD, project, name, 0, fieldNames, true);
fieldNames.add(fieldNameProposals[0]);
if (fLinkedProposalModel != null) {
LinkedProposalPositionGroup positionGroup= fLinkedProposalModel.getPositionGroup(KEY_FIELD_NAME_EXT + i, true);
for (int k= 0; k < fieldNameProposals.length; k++) {
positionGroup.addProposal(fieldNameProposals[k], null, fieldNameProposals.length - k);
}
}
}
String[] allFieldNames= fieldNames.toArray(new String[fieldNames.size()]);
List<BodyDeclaration> newBodyDeclarations= newDeclaration.bodyDeclarations();
createFieldsForAccessedLocals(rewrite, bindings, allFieldNames, newBodyDeclarations);
MethodDeclaration newConstructorDecl= createNewConstructor(rewrite, bindings, allFieldNames);
if (newConstructorDecl != null) {
newBodyDeclarations.add(newConstructorDecl);
}
updateAndMoveBodyDeclarations(rewrite, bindings, allFieldNames, newBodyDeclarations, newConstructorDecl);
if (doAddComments()) {
String[] parameterNames= new String[typeParameters.length];
for (int index= 0; index < parameterNames.length; index++) {
parameterNames[index]= typeParameters[index].getName();
}
String string= CodeGeneration.getTypeComment(rewrite.getCu(), fClassName, parameterNames, StubUtility.getLineDelimiterUsed(fCu));
if (string != null) {
Javadoc javadoc= (Javadoc) rewrite.getASTRewrite().createStringPlaceholder(string, ASTNode.JAVADOC);
newDeclaration.setJavadoc(javadoc);
}
}
if (fLinkedProposalModel != null) {
addLinkedPosition(KEY_TYPE_NAME, newDeclaration.getName(), rewrite.getASTRewrite(), false);
ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(fLinkedProposalModel, rewrite.getASTRewrite(), newDeclaration.modifiers(), false);
}
return newDeclaration;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:66,代码来源:ConvertAnonymousToNestedRefactoring.java
示例10: createConstantDeclaration
import org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor; //导入依赖的package包/类
private void createConstantDeclaration() throws CoreException {
Type type= getConstantType();
IExpressionFragment fragment= getSelectedExpression();
Expression initializer= getSelectedExpression().createCopyTarget(fCuRewrite.getASTRewrite(), true);
AST ast= fCuRewrite.getAST();
VariableDeclarationFragment variableDeclarationFragment= ast.newVariableDeclarationFragment();
variableDeclarationFragment.setName(ast.newSimpleName(fConstantName));
variableDeclarationFragment.setInitializer(initializer);
FieldDeclaration fieldDeclaration= ast.newFieldDeclaration(variableDeclarationFragment);
fieldDeclaration.setType(type);
Modifier.ModifierKeyword accessModifier= Modifier.ModifierKeyword.toKeyword(fVisibility);
if (accessModifier != null)
fieldDeclaration.modifiers().add(ast.newModifier(accessModifier));
fieldDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD));
fieldDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));
boolean createComments= JavaPreferencesSettings.getCodeGenerationSettings(fCu.getJavaProject()).createComments;
if (createComments) {
String comment= CodeGeneration.getFieldComment(fCu, getConstantTypeName(), fConstantName, StubUtility.getLineDelimiterUsed(fCu));
if (comment != null && comment.length() > 0) {
Javadoc doc= (Javadoc) fCuRewrite.getASTRewrite().createStringPlaceholder(comment, ASTNode.JAVADOC);
fieldDeclaration.setJavadoc(doc);
}
}
AbstractTypeDeclaration parent= getContainingTypeDeclarationNode();
ListRewrite listRewrite= fCuRewrite.getASTRewrite().getListRewrite(parent, parent.getBodyDeclarationsProperty());
TextEditGroup msg= fCuRewrite.createGroupDescription(RefactoringCoreMessages.ExtractConstantRefactoring_declare_constant);
if (insertFirst()) {
listRewrite.insertFirst(fieldDeclaration, msg);
} else {
listRewrite.insertAfter(fieldDeclaration, getNodeToInsertConstantDeclarationAfter(), msg);
}
if (fLinkedProposalModel != null) {
ASTRewrite rewrite= fCuRewrite.getASTRewrite();
LinkedProposalPositionGroup nameGroup= fLinkedProposalModel.getPositionGroup(KEY_NAME, true);
nameGroup.addPosition(rewrite.track(variableDeclarationFragment.getName()), true);
String[] nameSuggestions= guessConstantNames();
if (nameSuggestions.length > 0 && !nameSuggestions[0].equals(fConstantName)) {
nameGroup.addProposal(fConstantName, null, nameSuggestions.length + 1);
}
for (int i= 0; i < nameSuggestions.length; i++) {
nameGroup.addProposal(nameSuggestions[i], null, nameSuggestions.length - i);
}
LinkedProposalPositionGroup typeGroup= fLinkedProposalModel.getPositionGroup(KEY_TYPE, true);
typeGroup.addPosition(rewrite.track(type), true);
ITypeBinding typeBinding= guessBindingForReference(fragment.getAssociatedExpression());
if (typeBinding != null) {
ITypeBinding[] relaxingTypes= ASTResolving.getNarrowingTypes(ast, typeBinding);
for (int i= 0; i < relaxingTypes.length; i++) {
typeGroup.addProposal(relaxingTypes[i], fCuRewrite.getCu(), relaxingTypes.length - i);
}
}
boolean isInterface= parent.resolveBinding() != null && parent.resolveBinding().isInterface();
ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(fLinkedProposalModel, rewrite, fieldDeclaration.modifiers(), isInterface);
}
}
示例11: doAddField
import org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor; //导入依赖的package包/类
private ASTRewrite doAddField(CompilationUnit astRoot) {
SimpleName node= fOriginalNode;
boolean isInDifferentCU= false;
ASTNode newTypeDecl= astRoot.findDeclaringNode(fSenderBinding);
if (newTypeDecl == null) {
astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
isInDifferentCU= true;
}
ImportRewrite imports= createImportRewrite(astRoot);
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(ASTResolving.findParentBodyDeclaration(node), imports);
if (newTypeDecl != null) {
AST ast= newTypeDecl.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
fragment.setName(ast.newSimpleName(node.getIdentifier()));
Type type= evaluateVariableType(ast, imports, importRewriteContext, fSenderBinding);
FieldDeclaration newDecl= ast.newFieldDeclaration(fragment);
newDecl.setType(type);
newDecl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, evaluateFieldModifiers(newTypeDecl)));
if (fSenderBinding.isInterface() || fVariableKind == CONST_FIELD) {
fragment.setInitializer(ASTNodeFactory.newDefaultExpression(ast, type, 0));
}
ChildListPropertyDescriptor property= ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
List<BodyDeclaration> decls= ASTNodes.<BodyDeclaration>getChildListProperty(newTypeDecl, property);
int maxOffset= isInDifferentCU ? -1 : node.getStartPosition();
int insertIndex= findFieldInsertIndex(decls, newDecl, maxOffset);
ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, property);
listRewriter.insertAt(newDecl, insertIndex, null);
ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(getLinkedProposalModel(), rewrite, newDecl.modifiers(), fSenderBinding.isInterface());
addLinkedPosition(rewrite.track(newDecl.getType()), false, KEY_TYPE);
if (!isInDifferentCU) {
addLinkedPosition(rewrite.track(node), true, KEY_NAME);
}
addLinkedPosition(rewrite.track(fragment.getName()), false, KEY_NAME);
if (fragment.getInitializer() != null) {
addLinkedPosition(rewrite.track(fragment.getInitializer()), false, KEY_INITIALIZER);
}
return rewrite;
}
return null;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:57,代码来源:NewVariableCorrectionProposal.java
示例12: getStub
import org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor; //导入依赖的package包/类
private AnnotationTypeMemberDeclaration getStub(ASTRewrite rewrite, AnnotationTypeDeclaration targetTypeDecl) {
AST ast= targetTypeDecl.getAST();
AnnotationTypeMemberDeclaration decl= ast.newAnnotationTypeMemberDeclaration();
SimpleName newNameNode= getNewName(rewrite);
decl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, evaluateModifiers(targetTypeDecl)));
ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(getLinkedProposalModel(), rewrite, decl.modifiers(), true);
decl.setName(newNameNode);
Type returnType= getNewType(rewrite);
decl.setType(returnType);
return decl;
}
示例13: addNewModifiers
import org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor; //导入依赖的package包/类
@Override
protected void addNewModifiers(ASTRewrite rewrite, ASTNode targetTypeDecl, List<IExtendedModifier> modifiers) {
modifiers.addAll(rewrite.getAST().newModifiers(evaluateModifiers(targetTypeDecl)));
ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(getLinkedProposalModel(), rewrite, modifiers, getSenderBinding().isInterface());
}
示例14: doAddField
import org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor; //导入依赖的package包/类
private ASTRewrite doAddField(CompilationUnit astRoot) {
SimpleName node= fOriginalNode;
boolean isInDifferentCU= false;
ASTNode newTypeDecl= astRoot.findDeclaringNode(fSenderBinding);
if (newTypeDecl == null) {
astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
isInDifferentCU= true;
}
ImportRewrite imports= createImportRewrite(astRoot);
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(ASTResolving.findParentBodyDeclaration(node), imports);
if (newTypeDecl != null) {
AST ast= newTypeDecl.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
VariableDeclarationFragment fragment= ast.newVariableDeclarationFragment();
fragment.setName(ast.newSimpleName(node.getIdentifier()));
Type type= evaluateVariableType(ast, imports, importRewriteContext, fSenderBinding);
FieldDeclaration newDecl= ast.newFieldDeclaration(fragment);
newDecl.setType(type);
newDecl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, evaluateFieldModifiers(newTypeDecl)));
if (fSenderBinding.isInterface() || fVariableKind == CONST_FIELD) {
fragment.setInitializer(ASTNodeFactory.newDefaultExpression(ast, type, 0));
}
ChildListPropertyDescriptor property= ASTNodes.getBodyDeclarationsProperty(newTypeDecl);
List<BodyDeclaration> decls= (List<BodyDeclaration>) newTypeDecl.getStructuralProperty(property);
int maxOffset= isInDifferentCU ? -1 : node.getStartPosition();
int insertIndex= findFieldInsertIndex(decls, newDecl, maxOffset);
ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, property);
listRewriter.insertAt(newDecl, insertIndex, null);
ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(getLinkedProposalModel(), rewrite, newDecl.modifiers(), fSenderBinding.isInterface());
addLinkedPosition(rewrite.track(newDecl.getType()), false, KEY_TYPE);
if (!isInDifferentCU) {
addLinkedPosition(rewrite.track(node), true, KEY_NAME);
}
addLinkedPosition(rewrite.track(fragment.getName()), false, KEY_NAME);
if (fragment.getInitializer() != null) {
addLinkedPosition(rewrite.track(fragment.getInitializer()), false, KEY_INITIALIZER);
}
return rewrite;
}
return null;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:57,代码来源:NewVariableCorrectionProposal.java