use of org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser in project che by eclipse.
the class SelfEncapsulateFieldRefactoring method checkInitialConditions.
//----activation checking ----------------------------------------------------------
@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;
}
use of org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser in project che by eclipse.
the class TypeContextChecker method resolveSuperClass.
public static ITypeBinding resolveSuperClass(String superclass, IType typeHandle, StubTypeContext superClassContext) {
StringBuffer cuString = new StringBuffer();
cuString.append(superClassContext.getBeforeString());
cuString.append(superclass);
cuString.append(superClassContext.getAfterString());
try {
ICompilationUnit wc = typeHandle.getCompilationUnit().getWorkingCopy(new WorkingCopyOwner() {
}, new NullProgressMonitor());
try {
wc.getBuffer().setContents(cuString.toString());
CompilationUnit compilationUnit = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(wc, true);
ASTNode type = NodeFinder.perform(compilationUnit, superClassContext.getBeforeString().length(), superclass.length());
if (type instanceof Type) {
return handleBug84585(((Type) type).resolveBinding());
} else if (type instanceof Name) {
ASTNode parent = type.getParent();
if (parent instanceof Type)
return handleBug84585(((Type) parent).resolveBinding());
}
throw new IllegalStateException();
} finally {
wc.discardWorkingCopy();
}
} catch (JavaModelException e) {
return null;
}
}
use of org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser in project che by eclipse.
the class InlineMethodRefactoring method resolveSourceProvider.
private static SourceProvider resolveSourceProvider(RefactoringStatus status, ITypeRoot typeRoot, ASTNode invocation) {
CompilationUnit root = (CompilationUnit) invocation.getRoot();
IMethodBinding methodBinding = Invocations.resolveBinding(invocation);
if (methodBinding == null) {
status.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);
return null;
}
MethodDeclaration declaration = (MethodDeclaration) root.findDeclaringNode(methodBinding);
if (declaration != null) {
return new SourceProvider(typeRoot, declaration);
}
IMethod method = (IMethod) methodBinding.getJavaElement();
if (method != null) {
CompilationUnit methodDeclarationAstRoot;
ICompilationUnit methodCu = method.getCompilationUnit();
if (methodCu != null) {
methodDeclarationAstRoot = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(methodCu, true);
} else {
IClassFile classFile = method.getClassFile();
if (!JavaElementUtil.isSourceAvailable(classFile)) {
String methodLabel = JavaElementLabels.getTextLabel(method, JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.M_PARAMETER_TYPES);
status.addFatalError(Messages.format(RefactoringCoreMessages.InlineMethodRefactoring_error_classFile, methodLabel));
return null;
}
methodDeclarationAstRoot = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(classFile, true);
}
ASTNode node = methodDeclarationAstRoot.findDeclaringNode(methodBinding.getMethodDeclaration().getKey());
if (node instanceof MethodDeclaration) {
return new SourceProvider(methodDeclarationAstRoot.getTypeRoot(), (MethodDeclaration) node);
}
}
status.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);
return null;
}
use of org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser in project eclipse.platform.runtime by eclipse.
the class MessageBundleRefactoring method processCompilationUnit.
private void processCompilationUnit(RefactoringStatus result, ICompilationUnit unit, IProgressMonitor monitor) throws CoreException {
monitor.beginTask("", 2);
CompilationUnit root = new RefactoringASTParser(AST.JLS3).parse(unit, true, new SubProgressMonitor(monitor, 1));
ASTRewrite rewriter = ASTRewrite.create(root.getAST());
processAST(result, root, rewriter, new SubProgressMonitor(monitor, 1));
TextFileChange change = new TextFileChange(unit.getElementName(), (IFile) unit.getResource());
try {
ITextFileBuffer buffer = RefactoringFileBuffers.acquire(unit);
IDocument document = buffer.getDocument();
change.setEdit(rewriter.rewriteAST(document, null));
} finally {
RefactoringFileBuffers.release(unit);
}
fChange.add(change);
monitor.done();
}
use of org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser in project che by eclipse.
the class ExtractTempRefactoring method checkNewSource.
private void checkNewSource(SubProgressMonitor monitor, RefactoringStatus result) throws CoreException {
String newCuSource = fChange.getPreviewContent(new NullProgressMonitor());
CompilationUnit newCUNode = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(newCuSource, fCu, true, true, monitor);
IProblem[] newProblems = RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, fCompilationUnitNode);
for (int i = 0; i < newProblems.length; i++) {
IProblem problem = newProblems[i];
if (problem.isError())
result.addEntry(new RefactoringStatusEntry((problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING), problem.getMessage(), new JavaStringStatusContext(newCuSource, SourceRangeFactory.create(problem))));
}
}
Aggregations