public void run(IStructuredSelection selection) { try { Assert.isTrue(RefactoringAvailabilityTester.isInlineConstantAvailable(selection)); Object first= selection.getFirstElement(); Assert.isTrue(first instanceof IField); IField field= (IField) first; run(field.getNameRange().getOffset(), field.getNameRange().getLength(), field.getCompilationUnit()); } catch (JavaModelException e) { ExceptionHandler.handle(e, getShell(), RefactoringMessages.InlineConstantAction_dialog_title, RefactoringMessages.InlineConstantAction_unexpected_exception); } }
@Override public void run(IStructuredSelection selection) { try { Assert.isTrue(RefactoringAvailabilityTester.isInlineConstantAvailable(selection)); Object first= selection.getFirstElement(); Assert.isTrue(first instanceof IField); IField field= (IField) first; run(field.getNameRange().getOffset(), field.getNameRange().getLength(), field.getCompilationUnit()); } catch (JavaModelException e) { ExceptionHandler.handle(e, getShell(), RefactoringMessages.InlineConstantAction_dialog_title, RefactoringMessages.InlineConstantAction_unexpected_exception); } }
@Override public void run(IStructuredSelection selection) { try { Assert.isTrue(RefactoringAvailabilityTester.isInlineConstantAvailable(selection)); Object first= selection.getFirstElement(); Assert.isTrue(first instanceof IField); IField field= (IField) first; run(field.getNameRange().getOffset(), field.getNameRange().getLength(), field.getCompilationUnit()); } catch (JavaModelException e) { ExceptionHandler.handle(e, getShell(), RefactoringMessages.InlineConstantAction_dialog_title, RefactoringMessages.InlineConstantAction_unexpected_exception); } }
private void addDeclarationUpdate() throws CoreException { ISourceRange nameRange= fField.getNameRange(); TextEdit textEdit= new ReplaceEdit(nameRange.getOffset(), nameRange.getLength(), getNewElementName()); ICompilationUnit cu= fField.getCompilationUnit(); String groupName= RefactoringCoreMessages.RenameFieldRefactoring_Update_field_declaration; addTextEdit(fChangeManager.get(cu), groupName, textEdit); }
private void addDeclarationUpdate() throws CoreException { ISourceRange nameRange= fField.getNameRange(); TextEdit textEdit= new ReplaceEdit(nameRange.getOffset(), nameRange.getLength(), getNewElementName()); ICompilationUnit cu= fField.getCompilationUnit(); String groupName= RefactoringCoreMessages.RenameFieldRefactoring_Update_field_declaration; addTextEdit(fChangeManager.get(cu), groupName, textEdit); }
private void addDeclarationUpdate() throws CoreException { ISourceRange nameRange= fField.getNameRange(); TextEdit textEdit= new ReplaceEdit(nameRange.getOffset(), nameRange.getLength(), getNewElementName()); ICompilationUnit cu= fField.getCompilationUnit(); String groupName= RefactoringCoreMessages.RenameFieldRefactoring_Update_field_declaration; addTextEdit(fChangeManager.get(cu), groupName, textEdit); }
private void addDeclarationUpdate() throws CoreException { ISourceRange nameRange= fField.getNameRange(); TextEdit textEdit= new ReplaceEdit(nameRange.getOffset(), nameRange.getLength(), getNewElementName()); ICompilationUnit cu= fField.getCompilationUnit(); String groupName= RefactoringCoreMessages.RenameFieldRefactoring_Update_field_declaration; addTextEdit(fChangeManager.get(cu), groupName, textEdit); }
private boolean handleConstantValue(IField field, boolean link) throws JavaModelException { String text = null; ISourceRange nameRange = field.getNameRange(); if (SourceRange.isAvailable(nameRange)) { CompilationUnit cuNode = CoreASTProvider.getInstance().getAST(field.getTypeRoot(), CoreASTProvider.WAIT_YES, new NullProgressMonitor());
@Override protected Position getSourceRange(IType type, IDocument doc, IReference reference) throws CoreException, BadLocationException { IApiField field = (IApiField) reference.getMember(); IField javaField = type.getField(field.getName()); Position pos = null; if (javaField.exists()) { ISourceRange range = javaField.getNameRange(); if (range != null) { pos = new Position(range.getOffset(), range.getLength()); } } if (pos == null) { return defaultSourcePosition(type, reference); } return pos; } }
private boolean handleConstantValue(IField field, boolean link) throws JavaModelException { String text= null; ISourceRange nameRange= field.getNameRange(); if (SourceRange.isAvailable(nameRange)) { CompilationUnit cuNode= SharedASTProvider.getAST(field.getTypeRoot(), SharedASTProvider.WAIT_ACTIVE_ONLY, null);
/** * Returns the source range to use for the given field within the given * {@link IType} * * @param type the type to look in for the given {@link IApiField} * @param reference the reference the field is involved in * @param field the field to find the range for * @return the {@link ISourceRange} in the given {@link IType} that encloses * the given {@link IApiField} * @throws JavaModelException * @throws CoreException */ protected Position getSourceRangeForField(IType type, IReference reference, IApiField field) throws JavaModelException, CoreException { IField javaField = type.getField(field.getName()); Position pos = null; if (javaField.exists()) { ISourceRange range = javaField.getNameRange(); if (range != null) { pos = new Position(range.getOffset(), range.getLength()); } } if (pos == null) { return defaultSourcePosition(type, reference); } return pos; }
do { range = ((IField)child).getNameRange(); if (position <= range.getOffset() + range.getLength()) { candidate = child;
do { range = ((IField)child).getNameRange(); if (position <= range.getOffset() + range.getLength()) { candidate = child;
/** * Generates a new setter method for the specified field * * @param field the field * @param astRewrite the AST rewrite to use * @param rewrite the list rewrite to use * @throws CoreException if an error occurs * @throws OperationCanceledException if the operation has been cancelled */ private void generateSetterMethod(final IField field, ASTRewrite astRewrite, final ListRewrite rewrite) throws CoreException, OperationCanceledException { final IType type= field.getDeclaringType(); final String name= GetterSetterUtil.getSetterName(field, null); final IMethod existing= JavaModelUtil.findMethod(name, new String[] { field.getTypeSignature()}, false, type); if (existing == null || !querySkipExistingMethods(existing)) { IJavaElement sibling= null; if (existing != null) { sibling= StubUtility.findNextSibling(existing); removeExistingAccessor(existing, rewrite); } else sibling= fInsert; ASTNode insertion= StubUtility2Core.getNodeToInsertBefore(rewrite, sibling); addNewAccessor(type, field, GetterSetterUtil.getSetterStub(field, name, fSettings.createComments, fVisibility | (field.getFlags() & Flags.AccStatic)), rewrite, insertion); if (Flags.isFinal(field.getFlags())) { FieldDeclaration fieldDecl= ASTNodes.getParent(NodeFinder.perform(fASTRoot, field.getNameRange()), FieldDeclaration.class); if (fieldDecl != null) { ModifierRewrite.create(astRewrite, fieldDecl).setModifiers(0, Modifier.FINAL, null); } } } }
@Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { if (fVisibility < 0) { fVisibility = (fField.getFlags() & (Flags.AccPublic | Flags.AccProtected | Flags.AccPrivate)); } RefactoringStatus result = new RefactoringStatus(); result.merge(Checks.checkAvailability(fField)); if (result.hasFatalError()) { return result; } fRoot = new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL).parse(fField.getCompilationUnit(), true, pm); ISourceRange sourceRange = fField.getNameRange(); ASTNode node = NodeFinder.perform(fRoot, sourceRange.getOffset(), sourceRange.getLength()); if (node == null) { return mappingErrorFound(result, node); } fFieldDeclaration = ASTNodes.getParent(node, VariableDeclarationFragment.class); if (fFieldDeclaration == null) { return mappingErrorFound(result, node); } if (fFieldDeclaration.resolveBinding() == null) { if (!processCompilerError(result, node)) { result.addFatalError(RefactoringCoreMessages.SelfEncapsulateField_type_not_resolveable); } return result; } computeUsedNames(); return result; }
@Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { if (fVisibility < 0) fVisibility= (fField.getFlags() & (Flags.AccPublic | Flags.AccProtected | Flags.AccPrivate)); RefactoringStatus result= new RefactoringStatus(); result.merge(Checks.checkAvailability(fField)); if (result.hasFatalError()) return result; fRoot= new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL).parse(fField.getCompilationUnit(), true, pm); ISourceRange sourceRange= fField.getNameRange(); ASTNode node= NodeFinder.perform(fRoot, sourceRange.getOffset(), sourceRange.getLength()); if (node == null) { return mappingErrorFound(result, node); } fFieldDeclaration= ASTNodes.getParent(node, VariableDeclarationFragment.class); if (fFieldDeclaration == null) { return mappingErrorFound(result, node); } if (fFieldDeclaration.resolveBinding() == null) { if (!processCompilerError(result, node)) result.addFatalError(RefactoringCoreMessages.SelfEncapsulateField_type_not_resolveable); return result; } computeUsedNames(); return result; }
/** * Generates a new setter method for the specified field * * @param field the field * @param astRewrite the AST rewrite to use * @param rewrite the list rewrite to use * @throws CoreException if an error occurs * @throws OperationCanceledException if the operation has been cancelled */ private void generateSetterMethod(final IField field, ASTRewrite astRewrite, final ListRewrite rewrite) throws CoreException, OperationCanceledException { final IType type= field.getDeclaringType(); final String name= GetterSetterUtil.getSetterName(field, null); final IMethod existing= JavaModelUtil.findMethod(name, new String[] { field.getTypeSignature()}, false, type); if (existing == null || !querySkipExistingMethods(existing)) { IJavaElement sibling= null; if (existing != null) { sibling= StubUtility.findNextSibling(existing); removeExistingAccessor(existing, rewrite); } else sibling= fInsert; ASTNode insertion= StubUtility2.getNodeToInsertBefore(rewrite, sibling); addNewAccessor(type, field, GetterSetterUtil.getSetterStub(field, name, fSettings.createComments, fVisibility | (field.getFlags() & Flags.AccStatic)), rewrite, insertion); if (Flags.isFinal(field.getFlags())) { ASTNode fieldDecl= ASTNodes.getParent(NodeFinder.perform(fASTRoot, field.getNameRange()), FieldDeclaration.class); if (fieldDecl != null) { ModifierRewrite.create(astRewrite, fieldDecl).setModifiers(0, Modifier.FINAL, null); } } } }
@Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { if (fVisibility < 0) fVisibility= (fField.getFlags() & (Flags.AccPublic | Flags.AccProtected | Flags.AccPrivate)); RefactoringStatus result= new RefactoringStatus(); result.merge(Checks.checkAvailability(fField)); if (result.hasFatalError()) return result; fRoot= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(fField.getCompilationUnit(), true, pm); ISourceRange sourceRange= fField.getNameRange(); ASTNode node= NodeFinder.perform(fRoot, sourceRange.getOffset(), sourceRange.getLength()); if (node == null) { return mappingErrorFound(result, node); } fFieldDeclaration= (VariableDeclarationFragment)ASTNodes.getParent(node, VariableDeclarationFragment.class); if (fFieldDeclaration == null) { return mappingErrorFound(result, node); } if (fFieldDeclaration.resolveBinding() == null) { if (!processCompilerError(result, node)) result.addFatalError(RefactoringCoreMessages.SelfEncapsulateField_type_not_resolveable); return result; } computeUsedNames(); return result; }
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { if (fVisibility < 0) fVisibility= (fField.getFlags() & (Flags.AccPublic | Flags.AccProtected | Flags.AccPrivate)); RefactoringStatus result= new RefactoringStatus(); result.merge(Checks.checkAvailability(fField)); if (result.hasFatalError()) return result; fRoot= new RefactoringASTParser(AST.JLS3).parse(fField.getCompilationUnit(), true, pm); ISourceRange sourceRange= fField.getNameRange(); ASTNode node= NodeFinder.perform(fRoot, sourceRange.getOffset(), sourceRange.getLength()); if (node == null) { return mappingErrorFound(result, node); } fFieldDeclaration= (VariableDeclarationFragment)ASTNodes.getParent(node, VariableDeclarationFragment.class); if (fFieldDeclaration == null) { return mappingErrorFound(result, node); } if (fFieldDeclaration.resolveBinding() == null) { if (!processCompilerError(result, node)) result.addFatalError(RefactoringCoreMessages.SelfEncapsulateField_type_not_resolveable); return result; } computeUsedNames(); fRewriter= ASTRewrite.create(fRoot.getAST()); return result; }
addNewAccessor(type, field, GetterSetterUtil.getSetterStub(field, name, fSettings.createComments, fVisibility | (field.getFlags() & Flags.AccStatic)), rewrite, insertion); if (Flags.isFinal(field.getFlags())) { ASTNode fieldDecl= ASTNodes.getParent(NodeFinder.perform(fASTRoot, field.getNameRange()), FieldDeclaration.class); if (fieldDecl != null) { ModifierRewrite.create(astRewrite, fieldDecl).setModifiers(0, Modifier.FINAL, null);