use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.
the class Bindings method getTypeBoundsForSubsignature.
private static Set<ITypeBinding> getTypeBoundsForSubsignature(ITypeBinding typeParameter) {
ITypeBinding[] typeBounds = typeParameter.getTypeBounds();
int count = typeBounds.length;
if (count == 0)
return Collections.emptySet();
Set<ITypeBinding> result = new HashSet<ITypeBinding>(typeBounds.length);
for (int i = 0; i < typeBounds.length; i++) {
ITypeBinding bound = typeBounds[i];
if (//$NON-NLS-1$
"java.lang.Object".equals(typeBounds[0].getQualifiedName()))
continue;
else if (containsTypeVariables(bound))
// try to achieve effect of "rename type variables"
result.add(bound.getErasure());
else if (bound.isRawType())
result.add(bound.getTypeDeclaration());
else
result.add(bound);
}
return result;
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project che by eclipse.
the class SourceAnalyzer method checkActivation.
public RefactoringStatus checkActivation() throws JavaModelException {
RefactoringStatus result = new RefactoringStatus();
if (!fTypeRoot.isStructureKnown()) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_syntax_errors, JavaStatusContext.create(fTypeRoot));
return result;
}
IProblem[] problems = ASTNodes.getProblems(fDeclaration, ASTNodes.NODE_ONLY, ASTNodes.ERROR);
if (problems.length > 0) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_declaration_has_errors, JavaStatusContext.create(fTypeRoot, fDeclaration));
return result;
}
final IMethodBinding declarationBinding = fDeclaration.resolveBinding();
if (declarationBinding != null) {
final int modifiers = declarationBinding.getModifiers();
if (Modifier.isAbstract(modifiers)) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_abstract_methods, JavaStatusContext.create(fTypeRoot, fDeclaration));
return result;
} else if (Modifier.isNative(modifiers)) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_native_methods, JavaStatusContext.create(fTypeRoot, fDeclaration));
return result;
}
} else {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_methoddeclaration_has_errors, JavaStatusContext.create(fTypeRoot));
return result;
}
ActivationAnalyzer analyzer = new ActivationAnalyzer();
fDeclaration.accept(analyzer);
result.merge(analyzer.status);
if (!result.hasFatalError()) {
List<SingleVariableDeclaration> parameters = fDeclaration.parameters();
fParameters = new HashMap<IVariableBinding, ParameterData>(parameters.size() * 2);
for (Iterator<SingleVariableDeclaration> iter = parameters.iterator(); iter.hasNext(); ) {
SingleVariableDeclaration element = iter.next();
IVariableBinding binding = element.resolveBinding();
if (binding == null) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_declaration_has_errors, JavaStatusContext.create(fTypeRoot, fDeclaration));
return result;
}
fParameters.put(binding, (ParameterData) element.getProperty(ParameterData.PROPERTY));
}
fNames = new HashMap<IBinding, NameData>();
fImplicitReceivers = new ArrayList<Expression>(2);
fTypeParameterReferences = new ArrayList<NameData>(0);
fTypeParameterMapping = new HashMap<ITypeBinding, NameData>();
ITypeBinding declaringType = declarationBinding.getDeclaringClass();
if (declaringType == null) {
result.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_SourceAnalyzer_typedeclaration_has_errors, JavaStatusContext.create(fTypeRoot));
return result;
}
ITypeBinding[] typeParameters = declaringType.getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
NameData data = new NameData(typeParameters[i].getName());
fTypeParameterReferences.add(data);
fTypeParameterMapping.put(typeParameters[i], data);
}
fMethodTypeParameterReferences = new ArrayList<NameData>(0);
fMethodTypeParameterMapping = new HashMap<ITypeBinding, NameData>();
IMethodBinding method = declarationBinding;
typeParameters = method.getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
NameData data = new NameData(typeParameters[i].getName());
fMethodTypeParameterReferences.add(data);
fMethodTypeParameterMapping.put(typeParameters[i], data);
}
}
if (fDeclaration.isVarargs()) {
List<SingleVariableDeclaration> parameters = fDeclaration.parameters();
VarargAnalyzer vAnalyzer = new VarargAnalyzer(parameters.get(parameters.size() - 1).getName().resolveBinding());
fDeclaration.getBody().accept(vAnalyzer);
}
return result;
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project che by eclipse.
the class SourceProvider method replaceParameterWithExpression.
private void replaceParameterWithExpression(ASTRewrite rewriter, CallContext context, ImportRewrite importRewrite) throws CoreException {
Expression[] arguments = context.arguments;
try {
ITextFileBuffer buffer = RefactoringFileBuffers.acquire(context.compilationUnit);
for (int i = 0; i < arguments.length; i++) {
Expression expression = arguments[i];
String expressionString = null;
if (expression instanceof SimpleName) {
expressionString = ((SimpleName) expression).getIdentifier();
} else {
try {
expressionString = buffer.getDocument().get(expression.getStartPosition(), expression.getLength());
} catch (BadLocationException exception) {
JavaPlugin.log(exception);
continue;
}
}
ParameterData parameter = getParameterData(i);
List<SimpleName> references = parameter.references();
for (Iterator<SimpleName> iter = references.iterator(); iter.hasNext(); ) {
ASTNode element = iter.next();
Expression newExpression = (Expression) rewriter.createStringPlaceholder(expressionString, expression.getNodeType());
AST ast = rewriter.getAST();
ITypeBinding explicitCast = ASTNodes.getExplicitCast(expression, (Expression) element);
if (explicitCast != null) {
CastExpression cast = ast.newCastExpression();
if (NecessaryParenthesesChecker.needsParentheses(expression, cast, CastExpression.EXPRESSION_PROPERTY)) {
newExpression = createParenthesizedExpression(newExpression, ast);
}
cast.setExpression(newExpression);
ImportRewriteContext importRewriteContext = new ContextSensitiveImportRewriteContext(expression, importRewrite);
cast.setType(importRewrite.addImport(explicitCast, ast, importRewriteContext));
expression = newExpression = cast;
}
if (NecessaryParenthesesChecker.needsParentheses(expression, element.getParent(), element.getLocationInParent())) {
newExpression = createParenthesizedExpression(newExpression, ast);
}
rewriter.replace(element, newExpression, null);
}
}
} finally {
RefactoringFileBuffers.release(context.compilationUnit);
}
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project che by eclipse.
the class SourceProvider method getReceiver.
private String getReceiver(CallContext context, int modifiers, ImportRewriteContext importRewriteContext) {
String receiver = context.receiver;
ITypeBinding invocationType = ASTNodes.getEnclosingType(context.invocation);
ITypeBinding sourceType = fDeclaration.resolveBinding().getDeclaringClass();
if (!context.receiverIsStatic && Modifier.isStatic(modifiers)) {
if ("this".equals(receiver) && invocationType != null && Bindings.equals(invocationType, sourceType)) {
//$NON-NLS-1$
receiver = null;
} else {
receiver = context.importer.addImport(sourceType, importRewriteContext);
}
}
return receiver;
}
use of org.eclipse.jdt.core.dom.ITypeBinding in project che by eclipse.
the class TargetProvider method create.
public static TargetProvider create(MethodDeclaration declaration) {
IMethodBinding method = declaration.resolveBinding();
if (method == null)
return new ErrorTargetProvider(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.TargetProvider_method_declaration_not_unique));
ITypeBinding type = method.getDeclaringClass();
if (type.isLocal()) {
if (((IType) type.getJavaElement()).isBinary()) {
return new ErrorTargetProvider(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.TargetProvider_cannot_local_method_in_binary));
} else {
IType declaringClassOfLocal = (IType) type.getDeclaringClass().getJavaElement();
return new LocalTypeTargetProvider(declaringClassOfLocal.getCompilationUnit(), declaration);
}
} else {
return new MemberTypeTargetProvider(declaration.resolveBinding());
}
}
Aggregations