List of usage examples for org.eclipse.jdt.internal.compiler.ast ExplicitConstructorCall This
int This
To view the source code for org.eclipse.jdt.internal.compiler.ast ExplicitConstructorCall This.
Click Source Link
From source file:org.eclipse.ajdt.core.parserbridge.AJSourceElementNotifier.java
License:Open Source License
protected void notifySourceElementRequestor(AbstractMethodDeclaration methodDeclaration) { // range check boolean isInRange = initialPosition <= methodDeclaration.declarationSourceStart && eofPosition >= methodDeclaration.declarationSourceEnd; if (methodDeclaration.isClinit()) { this.visitIfNeeded(methodDeclaration); return;//from ww w . j av a 2s. co m } if (methodDeclaration.isDefaultConstructor()) { if (reportReferenceInfo) { ConstructorDeclaration constructorDeclaration = (ConstructorDeclaration) methodDeclaration; ExplicitConstructorCall constructorCall = constructorDeclaration.constructorCall; if (constructorCall != null) { switch (constructorCall.accessMode) { case ExplicitConstructorCall.This: requestor.acceptConstructorReference(typeNames[nestedTypeIndex - 1], constructorCall.arguments == null ? 0 : constructorCall.arguments.length, constructorCall.sourceStart); break; case ExplicitConstructorCall.Super: case ExplicitConstructorCall.ImplicitSuper: requestor.acceptConstructorReference(superTypeNames[nestedTypeIndex - 1], constructorCall.arguments == null ? 0 : constructorCall.arguments.length, constructorCall.sourceStart); break; } } } return; } char[][] argumentTypes = null; char[][] argumentNames = null; boolean isVarArgs = false; Argument[] arguments = methodDeclaration.arguments; if (arguments != null) { char[][][] argumentTypesAndNames = this.getArguments(arguments); argumentTypes = argumentTypesAndNames[0]; argumentNames = argumentTypesAndNames[1]; isVarArgs = arguments[arguments.length - 1].isVarArgs(); } char[][] thrownExceptionTypes = getThrownExceptions(methodDeclaration); // by default no selector end position int selectorSourceEnd = -1; if (methodDeclaration.isConstructor()) { selectorSourceEnd = this.sourceEnds.get(methodDeclaration); if (isInRange) { int currentModifiers = methodDeclaration.modifiers; if (isVarArgs) currentModifiers |= ClassFileConstants.AccVarargs; // remember deprecation so as to not lose it below boolean deprecated = (currentModifiers & ClassFileConstants.AccDeprecated) != 0 || hasDeprecatedAnnotation(methodDeclaration.annotations); ISourceElementRequestor.MethodInfo methodInfo = new ISourceElementRequestor.MethodInfo(); methodInfo.isConstructor = true; methodInfo.declarationStart = methodDeclaration.declarationSourceStart; methodInfo.modifiers = deprecated ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated : currentModifiers & ExtraCompilerModifiers.AccJustFlag; methodInfo.name = methodDeclaration.selector; methodInfo.nameSourceStart = methodDeclaration.sourceStart; methodInfo.nameSourceEnd = selectorSourceEnd; methodInfo.parameterTypes = argumentTypes; methodInfo.parameterNames = argumentNames; methodInfo.exceptionTypes = thrownExceptionTypes; methodInfo.typeParameters = getTypeParameterInfos(methodDeclaration.typeParameters()); methodInfo.categories = (char[][]) this.nodesToCategories.get(methodDeclaration); methodInfo.annotations = methodDeclaration.annotations; methodInfo.node = methodDeclaration; requestor.enterConstructor(methodInfo); } if (reportReferenceInfo) { ConstructorDeclaration constructorDeclaration = (ConstructorDeclaration) methodDeclaration; ExplicitConstructorCall constructorCall = constructorDeclaration.constructorCall; if (constructorCall != null) { switch (constructorCall.accessMode) { case ExplicitConstructorCall.This: requestor.acceptConstructorReference(typeNames[nestedTypeIndex - 1], constructorCall.arguments == null ? 0 : constructorCall.arguments.length, constructorCall.sourceStart); break; case ExplicitConstructorCall.Super: case ExplicitConstructorCall.ImplicitSuper: requestor.acceptConstructorReference(superTypeNames[nestedTypeIndex - 1], constructorCall.arguments == null ? 0 : constructorCall.arguments.length, constructorCall.sourceStart); break; } } } this.visitIfNeeded(methodDeclaration); if (isInRange) { requestor.exitConstructor(methodDeclaration.declarationSourceEnd); } return; } selectorSourceEnd = this.sourceEnds.get(methodDeclaration); // AspectJ Change Begin // recreate source locations for Pointcuts and Advice org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration ajmDec = new org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration( new org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult( methodDeclaration.compilationResult.fileName, methodDeclaration.compilationResult.unitIndex, methodDeclaration.compilationResult.totalUnitsKnown, 500)); if (ajmDec instanceof PointcutDeclaration) { selectorSourceEnd = methodDeclaration.sourceStart + methodDeclaration.selector.length - 1; } if (ajmDec instanceof AdviceDeclaration) { selectorSourceEnd = methodDeclaration.sourceStart + ((AdviceDeclaration) ajmDec).kind.getName().length() - 1; } // AspectJ Change End if (isInRange) { int currentModifiers = methodDeclaration.modifiers; if (isVarArgs) currentModifiers |= ClassFileConstants.AccVarargs; // remember deprecation so as to not lose it below boolean deprecated = (currentModifiers & ClassFileConstants.AccDeprecated) != 0 || hasDeprecatedAnnotation(methodDeclaration.annotations); TypeReference returnType = methodDeclaration instanceof MethodDeclaration ? ((MethodDeclaration) methodDeclaration).returnType : null; ISourceElementRequestor.MethodInfo methodInfo = new ISourceElementRequestor.MethodInfo(); methodInfo.isAnnotation = methodDeclaration instanceof AnnotationMethodDeclaration; methodInfo.declarationStart = methodDeclaration.declarationSourceStart; methodInfo.modifiers = deprecated ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated : currentModifiers & ExtraCompilerModifiers.AccJustFlag; methodInfo.returnType = returnType == null ? null : CharOperation.concatWith(returnType.getParameterizedTypeName(), '.'); methodInfo.name = methodDeclaration.selector; methodInfo.nameSourceStart = methodDeclaration.sourceStart; methodInfo.nameSourceEnd = selectorSourceEnd; methodInfo.parameterTypes = argumentTypes; methodInfo.parameterNames = argumentNames; methodInfo.exceptionTypes = thrownExceptionTypes; methodInfo.typeParameters = getTypeParameterInfos(methodDeclaration.typeParameters()); methodInfo.categories = (char[][]) this.nodesToCategories.get(methodDeclaration); methodInfo.annotations = methodDeclaration.annotations; methodInfo.node = methodDeclaration; requestor.enterMethod(methodInfo); } this.visitIfNeeded(methodDeclaration); if (isInRange) { if (methodDeclaration instanceof AnnotationMethodDeclaration) { AnnotationMethodDeclaration annotationMethodDeclaration = (AnnotationMethodDeclaration) methodDeclaration; Expression expression = annotationMethodDeclaration.defaultValue; if (expression != null) { requestor.exitMethod(methodDeclaration.declarationSourceEnd, expression); return; } } requestor.exitMethod(methodDeclaration.declarationSourceEnd, (org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression) null); } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.DeclaredLifting.java
License:Open Source License
private static void prepareArgLifting(TypeDeclaration teamDecl, ConstructorDeclaration ctor) { if (ctor.arguments == null || ctor.ignoreFurtherInvestigation) return; // nothing to do List<LocalDeclaration> localVariables = new LinkedList<LocalDeclaration>(); boolean changeSuperCallToCopiedThis = false; boolean chainArgAdded = false; for (int idx = 0; idx < ctor.arguments.length; idx++) { Argument argument = ctor.arguments[idx]; TypeBinding param = ctor.binding.parameters[idx]; int dims = param.dimensions(); param = param.leafComponentType(); // don't use RoleTypeBinding.isRoleWithoutExplicitAnchor, because // type wrapping in signature has not been done yet. if (isLiftableRoleOf(param, teamDecl.binding) && !ctor.isTSuper) { int start = argument.type.sourceStart; int end = argument.type.sourceEnd; AstGenerator gen = new AstGenerator(start, end); if (!chainArgAdded) { // do this only once: // reserve space for a marker arg that could be added during copying: LocalDeclaration chainVar = gen.localVariable("_OT$chainArg".toCharArray(), //$NON-NLS-1$ teamDecl.scope.getJavaLangObject(), null); chainVar.isPlaceHolder = true; localVariables.add(chainVar); chainArgAdded = true;//from www .j av a 2 s .c o m } // create local variable similar as for declared lifting char[] oldName = argument.name; char[] newName = CharOperation.concat(OT_DOLLAR_NAME, oldName); // cast might be needed if this collides with signature weakening // (cf. CopyInheritance.weakenSignature) Expression rhs = gen.castExpression(gen.singleNameReference(newName), gen.createArrayTypeReference(((ReferenceBinding) param).getRealType(), dims), // cast is guarded by isLiftableRoleOf() above CastExpression.RAW); argument.updateName(newName); // only potentially need lifting in a constructor (once copied) LocalDeclaration declaration = gen.localVariable(oldName, AstClone.copyTypeReference(argument.type), rhs); // assign real argument declaration.isPreparingForLifting = true; localVariables.add(declaration); // replace references in super-call: if (ctor.constructorCall != null) { // replace argn with _OT$argn in ctor call: ReplaceSingleNameVisitor.performReplacement(ctor.constructorCall, ctor.scope, oldName, newName); changeSuperCallToCopiedThis = (ctor.constructorCall.accessMode != ExplicitConstructorCall.This); } } if (changeSuperCallToCopiedThis) { // add a marker argument to this call: ExplicitConstructorCall call = ctor.constructorCall; call.accessMode = ExplicitConstructorCall.This; AstGenerator gen = new AstGenerator(call.sourceStart, call.sourceEnd); int numArgs = 0; if (call.arguments == null) { call.arguments = new Expression[1]; } else { numArgs = call.arguments.length; System.arraycopy(call.arguments, 0, call.arguments = new Expression[numArgs + 1], 0, numArgs); } call.arguments[numArgs] = TSuperHelper.createMarkerArgExpr(teamDecl.binding.superclass, gen); MethodModel.getModel(ctor); // side effect. } } if (!localVariables.isEmpty()) { // add local variable declartions to the front of statements int statsLen = (ctor.statements == null) ? 0 : ctor.statements.length; Statement[] statements = new Statement[localVariables.size() + statsLen]; int i = 0; for (Iterator<LocalDeclaration> iter = localVariables.iterator(); iter.hasNext();) { statements[i++] = iter.next(); } if (ctor.statements != null) System.arraycopy(ctor.statements, 0, statements, i, statsLen); ctor.setStatements(statements); } }