use of org.eclipse.jdt.core.dom.SingleVariableDeclaration in project che by eclipse.
the class InferTypeArgumentsConstraintCreator method visit.
@Override
public boolean visit(CatchClause node) {
SingleVariableDeclaration exception = node.getException();
IVariableBinding variableBinding = exception.resolveBinding();
VariableVariable2 cv = fTCModel.makeDeclaredVariableVariable(variableBinding, fCU);
setConstraintVariable(exception, cv);
return true;
}
use of org.eclipse.jdt.core.dom.SingleVariableDeclaration in project che by eclipse.
the class SourceAnalyzer method initialize.
public void initialize() {
Block body = fDeclaration.getBody();
// first collect the static imports. This is necessary to not mark
// static imported fields and methods as implicit visible.
fTypesToImport = new ArrayList<SimpleName>();
fStaticsToImport = new ArrayList<SimpleName>();
ImportReferencesCollector.collect(body, fTypeRoot.getJavaProject(), null, fTypesToImport, fStaticsToImport);
// Now collect implicit references and name references
body.accept(new UpdateCollector());
int numberOfLocals = LocalVariableIndex.perform(fDeclaration);
FlowContext context = new FlowContext(0, numberOfLocals + 1);
context.setConsiderAccessMode(true);
context.setComputeMode(FlowContext.MERGE);
InOutFlowAnalyzer flowAnalyzer = new InOutFlowAnalyzer(context);
FlowInfo info = flowAnalyzer.perform(getStatements());
for (Iterator<SingleVariableDeclaration> iter = fDeclaration.parameters().iterator(); iter.hasNext(); ) {
SingleVariableDeclaration element = iter.next();
IVariableBinding binding = element.resolveBinding();
ParameterData data = (ParameterData) element.getProperty(ParameterData.PROPERTY);
data.setAccessMode(info.getAccessMode(context, binding));
}
}
use of org.eclipse.jdt.core.dom.SingleVariableDeclaration in project che by eclipse.
the class FlowContext method isExceptionCaught.
boolean isExceptionCaught(ITypeBinding excpetionType) {
for (Iterator<List<CatchClause>> exceptions = fExceptionStack.iterator(); exceptions.hasNext(); ) {
for (Iterator<CatchClause> catchClauses = exceptions.next().iterator(); catchClauses.hasNext(); ) {
SingleVariableDeclaration caughtException = catchClauses.next().getException();
IVariableBinding binding = caughtException.resolveBinding();
if (binding == null)
continue;
ITypeBinding caughtype = binding.getType();
while (caughtype != null) {
if (caughtype == excpetionType)
return true;
caughtype = caughtype.getSuperclass();
}
}
}
return false;
}
use of org.eclipse.jdt.core.dom.SingleVariableDeclaration in project che by eclipse.
the class DelegateMethodCreator method createArguments.
@SuppressWarnings("unchecked")
private void createArguments(final MethodDeclaration declaration, final List<? extends ASTNode> arguments, boolean methodInvocation) {
Assert.isNotNull(declaration);
Assert.isNotNull(arguments);
SingleVariableDeclaration variable = null;
final int size = declaration.parameters().size();
for (int index = 0; index < size; index++) {
variable = (SingleVariableDeclaration) declaration.parameters().get(index);
if (methodInvocation) {
// we are creating method invocation parameters
final SimpleName expression = getAst().newSimpleName(variable.getName().getIdentifier());
((List<Expression>) arguments).add(expression);
} else {
// we are creating type info for the javadoc
final MethodRefParameter parameter = getAst().newMethodRefParameter();
parameter.setType(ASTNodeFactory.newType(getAst(), variable));
if ((index == size - 1) && declaration.isVarargs())
parameter.setVarargs(true);
((List<MethodRefParameter>) arguments).add(parameter);
}
}
}
use of org.eclipse.jdt.core.dom.SingleVariableDeclaration in project che by eclipse.
the class StubUtility2 method createDelegationStub.
public static MethodDeclaration createDelegationStub(ICompilationUnit unit, ASTRewrite rewrite, ImportRewrite imports, ImportRewriteContext context, IMethodBinding delegate, IVariableBinding delegatingField, CodeGenerationSettings settings) throws CoreException {
Assert.isNotNull(delegate);
Assert.isNotNull(delegatingField);
Assert.isNotNull(settings);
AST ast = rewrite.getAST();
MethodDeclaration decl = ast.newMethodDeclaration();
decl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, delegate.getModifiers() & ~Modifier.SYNCHRONIZED & ~Modifier.ABSTRACT & ~Modifier.NATIVE));
decl.setName(ast.newSimpleName(delegate.getName()));
decl.setConstructor(false);
createTypeParameters(imports, context, ast, delegate, decl);
decl.setReturnType2(imports.addImport(delegate.getReturnType(), ast, context));
List<SingleVariableDeclaration> params = createParameters(unit.getJavaProject(), imports, context, ast, delegate, null, decl);
createThrownExceptions(decl, delegate, imports, context, ast);
Block body = ast.newBlock();
decl.setBody(body);
String delimiter = StubUtility.getLineDelimiterUsed(unit);
Statement statement = null;
MethodInvocation invocation = ast.newMethodInvocation();
invocation.setName(ast.newSimpleName(delegate.getName()));
List<Expression> arguments = invocation.arguments();
for (int i = 0; i < params.size(); i++) arguments.add(ast.newSimpleName(params.get(i).getName().getIdentifier()));
if (settings.useKeywordThis) {
FieldAccess access = ast.newFieldAccess();
access.setExpression(ast.newThisExpression());
access.setName(ast.newSimpleName(delegatingField.getName()));
invocation.setExpression(access);
} else
invocation.setExpression(ast.newSimpleName(delegatingField.getName()));
if (delegate.getReturnType().isPrimitive() && delegate.getReturnType().getName().equals("void")) {
//$NON-NLS-1$
statement = ast.newExpressionStatement(invocation);
} else {
ReturnStatement returnStatement = ast.newReturnStatement();
returnStatement.setExpression(invocation);
statement = returnStatement;
}
body.statements().add(statement);
ITypeBinding declaringType = delegatingField.getDeclaringClass();
if (declaringType == null) {
// can be null for
return decl;
}
String qualifiedName = declaringType.getQualifiedName();
IPackageBinding packageBinding = declaringType.getPackage();
if (packageBinding != null) {
if (packageBinding.getName().length() > 0 && qualifiedName.startsWith(packageBinding.getName()))
qualifiedName = qualifiedName.substring(packageBinding.getName().length());
}
if (settings.createComments) {
/*
* TODO: have API for delegate method comments This is an inlined
* version of
* {@link CodeGeneration#getMethodComment(ICompilationUnit, String, MethodDeclaration, IMethodBinding, String)}
*/
delegate = delegate.getMethodDeclaration();
String declaringClassQualifiedName = delegate.getDeclaringClass().getQualifiedName();
String linkToMethodName = delegate.getName();
String[] parameterTypesQualifiedNames = StubUtility.getParameterTypeNamesForSeeTag(delegate);
String string = StubUtility.getMethodComment(unit, qualifiedName, decl, delegate.isDeprecated(), linkToMethodName, declaringClassQualifiedName, parameterTypesQualifiedNames, true, delimiter);
if (string != null) {
Javadoc javadoc = (Javadoc) rewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
decl.setJavadoc(javadoc);
}
}
return decl;
}
Aggregations