List of usage examples for org.eclipse.jdt.internal.compiler.ast QualifiedAllocationExpression QualifiedAllocationExpression
public QualifiedAllocationExpression()
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
protected void classInstanceCreation(boolean isQualified) { // ClassInstanceCreationExpression ::= 'new' ClassType '(' ArgumentListopt ')' ClassBodyopt // ClassBodyopt produces a null item on the astStak if it produces NO class body // An empty class body produces a 0 on the length stack..... AllocationExpression alloc;/* www .j ava 2s . c o m*/ int length; if (((length = this.astLengthStack[this.astLengthPtr--]) == 1) && (this.astStack[this.astPtr] == null)) { //NO ClassBody this.astPtr--; if (isQualified) { alloc = new QualifiedAllocationExpression(); } else { alloc = new AllocationExpression(); } alloc.sourceEnd = this.endPosition; //the position has been stored explicitly if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) { this.expressionPtr -= length; System.arraycopy(this.expressionStack, this.expressionPtr + 1, alloc.arguments = new Expression[length], 0, length); } alloc.type = getTypeReference(0); checkForDiamond(alloc.type); //the default constructor with the correct number of argument //will be created and added by the TC (see createsInternalConstructorWithBinding) alloc.sourceStart = this.intStack[this.intPtr--]; pushOnExpressionStack(alloc); } else { dispatchDeclarationInto(length); TypeDeclaration anonymousTypeDeclaration = (TypeDeclaration) this.astStack[this.astPtr]; anonymousTypeDeclaration.declarationSourceEnd = this.endStatementPosition; anonymousTypeDeclaration.bodyEnd = this.endStatementPosition; if (anonymousTypeDeclaration.allocation != null) { anonymousTypeDeclaration.allocation.sourceEnd = this.endStatementPosition; checkForDiamond(anonymousTypeDeclaration.allocation.type); } if (length == 0 && !containsComment(anonymousTypeDeclaration.bodyStart, anonymousTypeDeclaration.bodyEnd)) { anonymousTypeDeclaration.bits |= ASTNode.UndocumentedEmptyBlock; } this.astPtr--; this.astLengthPtr--; } }
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
protected void consumeClassInstanceCreationExpressionQualifiedWithTypeArguments() { // ClassInstanceCreationExpression ::= Primary '.' 'new' TypeArguments SimpleName '(' ArgumentListopt ')' ClassBodyopt // ClassInstanceCreationExpression ::= ClassInstanceCreationExpressionName 'new' TypeArguments SimpleName '(' ArgumentListopt ')' ClassBodyopt QualifiedAllocationExpression alloc; int length;/* www. j a v a 2 s. c o m*/ if (((length = this.astLengthStack[this.astLengthPtr--]) == 1) && (this.astStack[this.astPtr] == null)) { //NO ClassBody this.astPtr--; alloc = new QualifiedAllocationExpression(); alloc.sourceEnd = this.endPosition; //the position has been stored explicitly if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) { this.expressionPtr -= length; System.arraycopy(this.expressionStack, this.expressionPtr + 1, alloc.arguments = new Expression[length], 0, length); } alloc.type = getTypeReference(0); checkForDiamond(alloc.type); length = this.genericsLengthStack[this.genericsLengthPtr--]; this.genericsPtr -= length; System.arraycopy(this.genericsStack, this.genericsPtr + 1, alloc.typeArguments = new TypeReference[length], 0, length); this.intPtr--; //the default constructor with the correct number of argument //will be created and added by the TC (see createsInternalConstructorWithBinding) alloc.sourceStart = this.intStack[this.intPtr--]; pushOnExpressionStack(alloc); } else { dispatchDeclarationInto(length); TypeDeclaration anonymousTypeDeclaration = (TypeDeclaration) this.astStack[this.astPtr]; anonymousTypeDeclaration.declarationSourceEnd = this.endStatementPosition; anonymousTypeDeclaration.bodyEnd = this.endStatementPosition; if (length == 0 && !containsComment(anonymousTypeDeclaration.bodyStart, anonymousTypeDeclaration.bodyEnd)) { anonymousTypeDeclaration.bits |= ASTNode.UndocumentedEmptyBlock; } this.astPtr--; this.astLengthPtr--; QualifiedAllocationExpression allocationExpression = anonymousTypeDeclaration.allocation; if (allocationExpression != null) { allocationExpression.sourceEnd = this.endStatementPosition; // handle type arguments length = this.genericsLengthStack[this.genericsLengthPtr--]; this.genericsPtr -= length; System.arraycopy(this.genericsStack, this.genericsPtr + 1, allocationExpression.typeArguments = new TypeReference[length], 0, length); allocationExpression.sourceStart = this.intStack[this.intPtr--]; checkForDiamond(allocationExpression.type); } } QualifiedAllocationExpression qae = (QualifiedAllocationExpression) this.expressionStack[this.expressionPtr]; if (qae.anonymousType == null) { this.expressionLengthPtr--; this.expressionPtr--; qae.enclosingInstance = this.expressionStack[this.expressionPtr]; this.expressionStack[this.expressionPtr] = qae; } qae.sourceStart = qae.enclosingInstance.sourceStart; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.BaseAllocationExpression.java
License:Open Source License
private AllocationExpression newAllocation(ReferenceBinding baseclass, AstGenerator gen) { if (this.enclosingInstance == null) { AllocationExpression alloc = new AllocationExpression(); alloc.type = gen.typeReference(baseclass); return alloc; } else {//from w w w . ja v a 2 s. com QualifiedAllocationExpression alloc = new QualifiedAllocationExpression(); alloc.enclosingInstance = this.enclosingInstance; alloc.type = gen.singleTypeReference(baseclass.sourceName); return alloc; } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstConverter.java
License:Open Source License
public static TypeDeclaration createNestedType(char[] name, int modifiers, boolean isNestedType, boolean isPurelyCopied, TypeDeclaration teamDecl, ReferenceBinding tsuperRole) { TypeDeclaration enclosingTypeDecl = teamDecl; if (tsuperRole != null && isNestedType) { ReferenceBinding srcEnclosing = tsuperRole.enclosingType(); // TODO (SH): recurse even more TypeDeclaration[] members = enclosingTypeDecl.memberTypes; if (members != null) for (int i = 0; i < members.length; i++) { if (CharOperation.equals(members[i].name, srcEnclosing.internalName())) { enclosingTypeDecl = members[i]; break; }//from w w w . j a v a 2 s. c o m } } TypeDeclaration nestedType = new TypeDeclaration(enclosingTypeDecl.compilationResult); nestedType.name = name; nestedType.modifiers = modifiers; nestedType.isGenerated = true; nestedType.isPurelyCopied = isPurelyCopied; int sStart = enclosingTypeDecl.sourceStart; int sEnd = enclosingTypeDecl.sourceEnd; if (enclosingTypeDecl.superclass != null) { sStart = enclosingTypeDecl.superclass.sourceStart; sEnd = enclosingTypeDecl.superclass.sourceEnd; } nestedType.declarationSourceStart = sStart; nestedType.declarationSourceEnd = sEnd; nestedType.sourceStart = sStart; nestedType.sourceEnd = sEnd; nestedType.bodyStart = sStart; nestedType.bodyEnd = sEnd; AstGenerator gen = new AstGenerator(sStart, sEnd); if (tsuperRole != null && tsuperRole.isInterface()) { ReferenceBinding superclass = tsuperRole.superclass(); if (superclass != null && CharOperation.equals(superclass.internalName(), IOTConstants.OTCONFINED)) { nestedType.superclass = gen.qualifiedTypeReference(IOTConstants.ORG_OBJECTTEAMS_TEAM_OTCONFINED); nestedType.superclass.resolvedType = superclass; } } if (tsuperRole != null && tsuperRole.isLocalType()) { nestedType.bits |= ASTNode.IsLocalType; if (tsuperRole.isAnonymousType()) { // have no name, need at least a super type // (otherwise ClassScope.checkAndSetModifiers() will fail) ReferenceBinding superType; ReferenceBinding[] superIfcs = tsuperRole.superInterfaces(); if (superIfcs != Binding.NO_SUPERINTERFACES) superType = superIfcs[0]; else superType = tsuperRole.superclass(); nestedType.allocation = new QualifiedAllocationExpression(); nestedType.allocation.type = gen.typeReference(superType); nestedType.allocation.anonymousType = nestedType; } AstEdit.addLocalTypeDeclaration(enclosingTypeDecl, nestedType); } else { AstEdit.addMemberTypeDeclaration(enclosingTypeDecl, nestedType); } if (tsuperRole != null && tsuperRole.roleModel != null && tsuperRole.roleModel.isRoleFile()) { // for role copied from a role file create an enclosing CUD to allow for // late role catch-up of this phantom role. ProblemReporter reporter = enclosingTypeDecl.scope.problemReporter(); CompilationResult compilationResult = new CompilationResult("nofile".toCharArray(), 0, 0, 0); //$NON-NLS-1$ CompilationUnitDeclaration cud = new CompilationUnitDeclaration(reporter, compilationResult, 0); nestedType.compilationResult = compilationResult; nestedType.compilationUnit = cud; cud.types = new TypeDeclaration[] { nestedType }; char[][] enclosingName = enclosingTypeDecl.binding.compoundName; char[][] tokens = CharOperation.arrayConcat(enclosingName, nestedType.name); long[] positions = new long[tokens.length]; Arrays.fill(positions, 0L); cud.currentPackage = new ImportReference(enclosingName, positions, false, ClassFileConstants.AccTeam); } // Create TypeBindings for this type enclosingTypeDecl.scope.addGeneratedType(nestedType); int state = enclosingTypeDecl.getModel().getState(); if (enclosingTypeDecl.isTeam()) state = enclosingTypeDecl.getTeamModel().getState(); // Create Type-Hierarchy? nestedType.scope .connectTypeHierarchyForGenerated(state >= ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY); // don't set past the state of the enclosing team: state = Math.min(state, ITranslationStates.STATE_LENV_CONNECT_TYPE_HIERARCHY); if (nestedType.getRoleModel() != null) nestedType.getRoleModel().setState(state); if (nestedType.isTeam() && nestedType.getTeamModel() != null) nestedType.getTeamModel().setState(state); return nestedType; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator.java
License:Open Source License
public QualifiedAllocationExpression qualifiedAllocation(Expression enclosingInstance, SingleTypeReference typeRef, Expression[] arguments) { QualifiedAllocationExpression result = new QualifiedAllocationExpression(); result.enclosingInstance = enclosingInstance; result.type = typeRef; // Note: QualifiedAllocationExpression for roles really needs a SingleTypeReference. result.arguments = arguments;//from w w w. j a v a 2 s . co m return setPos(result); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator.java
License:Open Source License
public QualifiedAllocationExpression anonymousAllocation(TypeReference superType, Expression[] arguments, TypeDeclaration anonymousType) { QualifiedAllocationExpression result = new QualifiedAllocationExpression(); result.enclosingInstance = null;//w w w . j a va2s . c om result.type = superType; result.arguments = arguments; result.anonymousType = anonymousType; anonymousType.allocation = result; return setPos(result); }
From source file:org.nabucco.framework.mda.template.java.extract.statement.JavaAstStatementExtractorVisitor.java
License:Open Source License
@Override public boolean visit(QualifiedAllocationExpression qualifiedAllocationExpression, BlockScope scope) { // TODO: Anonymous classes. this.getVisitorContext().addException(new JavaModelException("Anonymous classes are not supported.")); QualifiedAllocationExpression allocationCopy = new QualifiedAllocationExpression(); allocationCopy.enclosingInstance = copy(qualifiedAllocationExpression.enclosingInstance, scope); allocationCopy.arguments = copy(qualifiedAllocationExpression.arguments, scope); this.statement = allocationCopy; return false; }