private void addFactoryMethod(EclipseNode singletonClass, TypeDeclaration astNode, TypeReference typeReference, TypeDeclaration innerClass, FieldDeclaration field) { MethodDeclaration factoryMethod = new MethodDeclaration(astNode.compilationResult); factoryMethod.modifiers = AccStatic | ClassFileConstants.AccPublic; factoryMethod.returnType = typeReference; factoryMethod.sourceStart = astNode.sourceStart; factoryMethod.sourceEnd = astNode.sourceEnd; factoryMethod.selector = "getInstance".toCharArray(); factoryMethod.bits = ECLIPSE_DO_NOT_TOUCH_FLAG; long pS = factoryMethod.sourceStart; long pE = factoryMethod.sourceEnd; long p = (long) pS << 32 | pE; FieldReference ref = new FieldReference(field.name, p); ref.receiver = new SingleNameReference(innerClass.name, p); ReturnStatement statement = new ReturnStatement(ref, astNode.sourceStart, astNode.sourceEnd); factoryMethod.statements = new Statement[]{statement}; EclipseHandlerUtil.injectMethod(singletonClass, factoryMethod); }
@Override public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { CtMethod<Object> m = factory.Core().createMethod(); m.setSimpleName(CharOperation.charToString(methodDeclaration.selector)); if (methodDeclaration.binding != null) { m.setExtendedModifiers(getModifiers(methodDeclaration.binding.modifiers, true, true)); } for (CtExtendedModifier extendedModifier : getModifiers(methodDeclaration.modifiers, false, true)) { m.addModifier(extendedModifier.getKind()); // avoid to keep implicit AND explicit modifier of the same kind. } m.setDefaultMethod(methodDeclaration.isDefaultMethod()); context.enter(m, methodDeclaration); // Create block if (!methodDeclaration.isAbstract() && (methodDeclaration.modifiers & ClassFileConstants.AccNative) == 0) { context.enter(getFactory().Core().createBlock(), methodDeclaration); context.exit(methodDeclaration); } // We consider the receiver as a standard argument (i.e. as a parameter) Receiver receiver = methodDeclaration.receiver; if (receiver != null) { receiver.traverse(this, methodDeclaration.scope); } return true; }
public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { if (!methodDeclaration.isDefaultConstructor()) { bodyDeclarations.add(methodDeclaration); } return false; } public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) {
if (md.isAbstract()) return; if (md.isNative()) return; if ((md.modifiers & ExtraCompilerModifiers.AccSemicolonBody) != 0)
int argumentsLength = argumentTypes.length; MethodDeclaration methodDeclaration = new MethodDeclaration(this.compilationResult); methodDeclaration.selector = methodBinding.selector; methodDeclaration.sourceStart = this.sourceStart; methodDeclaration.bindArguments();
analyseArguments(classScope.environment(), flowInfo, this.arguments, this.binding); if ((returnTypeBinding == TypeBinding.VOID) || isAbstract()) { if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) { this.bits |= ASTNode.NeedFreeReturn; if (!this.binding.isStatic() && (this.bits & ASTNode.CanBeStatic) != 0 && !this.isDefaultMethod()) { if(!this.binding.isOverriding() && !this.binding.isImplementing()) { if (this.binding.isPrivate() || this.binding.isFinal() || this.binding.declaringClass.isFinal()) {
analyseArguments(flowInfo, this.arguments, this.binding); else analyseArguments18(flowInfo, this.arguments, this.binding); if ((returnTypeBinding == TypeBinding.VOID) || isAbstract()) { if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) { this.bits |= ASTNode.NeedFreeReturn; if (!this.binding.isStatic() && (this.bits & ASTNode.CanBeStatic) != 0 && !this.isDefaultMethod()) { if(!this.binding.isOverriding() && !this.binding.isImplementing()) { if (this.binding.isPrivate() || this.binding.isFinal() || this.binding.declaringClass.isFinal()) {
protected void consumeMethodHeaderDefaultValue() { // MethodHeaderDefaultValue ::= DefaultValue MethodDeclaration md = (MethodDeclaration) this.astStack[this.astPtr]; int length = this.expressionLengthStack[this.expressionLengthPtr--]; if (length == 1) { this.intPtr--; // we get rid of the position of the default keyword this.intPtr--; // we get rid of the position of the default keyword if(md.isAnnotationMethod()) { ((AnnotationMethodDeclaration)md).defaultValue = this.expressionStack[this.expressionPtr]; md.modifiers |= ClassFileConstants.AccAnnotationDefault; } this.expressionPtr--; this.recordStringLiterals = true; } if(this.currentElement != null) { if(md.isAnnotationMethod()) { this.currentElement.updateSourceEndIfNecessary(((AnnotationMethodDeclaration)md).defaultValue.sourceEnd); } } } protected void consumeMethodHeaderExtendedDims() {
@Override public void endVisit(MethodDeclaration x, ClassScope scope) { try { if (x.isNative()) { processNativeMethod(x); } else { List<JStatement> statements = pop(x.statements); curMethod.body.getBlock().addStmts(statements); } popMethodInfo(); } catch (Throwable e) { throw translateException(x, e); } }
public void resolveStatements() { super.resolveStatements(); if (this.arguments != null) { this.scope.problemReporter().annotationMembersCannotHaveParameters(this);
analyseArguments(flowInfo); if ((returnTypeBinding == TypeBinding.VOID) || isAbstract()) { if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) { this.bits |= ASTNode.NeedFreeReturn;
((MethodDeclaration)method).analyseCode(this.scope, parentContext, flowInfo.copy());
if (md.isAbstract()) return; if (md.isNative()) return; if ((md.modifiers & ExtraCompilerModifiers.AccSemicolonBody) != 0)
int argumentsLength = argumentTypes.length; MethodDeclaration methodDeclaration = new MethodDeclaration(this.compilationResult); methodDeclaration.selector = methodBinding.selector; methodDeclaration.sourceStart = this.sourceStart; methodDeclaration.bindArguments();
analyseArguments(classScope.environment(), flowInfo, this.arguments, this.binding); if ((returnTypeBinding == TypeBinding.VOID) || isAbstract()) { if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) { this.bits |= ASTNode.NeedFreeReturn; if (!this.binding.isStatic() && (this.bits & ASTNode.CanBeStatic) != 0 && !this.isDefaultMethod()) { if(!this.binding.isOverriding() && !this.binding.isImplementing()) { if (this.binding.isPrivate() || this.binding.isFinal() || this.binding.declaringClass.isFinal()) {
analyseArguments(flowInfo, this.arguments, this.binding); else analyseArguments18(flowInfo, this.arguments, this.binding); if ((returnTypeBinding == TypeBinding.VOID) || isAbstract()) { if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) { this.bits |= ASTNode.NeedFreeReturn; if (!this.binding.isStatic() && (this.bits & ASTNode.CanBeStatic) != 0 && !this.isDefaultMethod()) { if(!this.binding.isOverriding() && !this.binding.isImplementing()) { if (this.binding.isPrivate() || this.binding.isFinal() || this.binding.declaringClass.isFinal()) {
protected void consumeMethodHeaderDefaultValue() { // MethodHeaderDefaultValue ::= DefaultValue MethodDeclaration md = (MethodDeclaration) this.astStack[this.astPtr]; int length = this.expressionLengthStack[this.expressionLengthPtr--]; if (length == 1) { this.intPtr--; // we get rid of the position of the default keyword this.intPtr--; // we get rid of the position of the default keyword if(md.isAnnotationMethod()) { ((AnnotationMethodDeclaration)md).defaultValue = this.expressionStack[this.expressionPtr]; md.modifiers |= ClassFileConstants.AccAnnotationDefault; } this.expressionPtr--; this.recordStringLiterals = true; } if(this.currentElement != null) { if(md.isAnnotationMethod()) { this.currentElement.updateSourceEndIfNecessary(((AnnotationMethodDeclaration)md).defaultValue.sourceEnd); } } } protected void consumeMethodHeaderExtendedDims() {
if (md.isNative()) return; if ((md.modifiers & ExtraCompilerModifiers.AccSemicolonBody) != 0)
public void resolveStatements() { super.resolveStatements(); if (this.arguments != null) { this.scope.problemReporter().annotationMembersCannotHaveParameters(this);
((MethodDeclaration)method).analyseCode(this.scope, parentContext, flowInfo.copy());