List of usage examples for org.eclipse.jdt.internal.compiler.ast CaseStatement CaseStatement
public CaseStatement(Expression constantExpression, int sourceEnd, int sourceStart)
From source file:lombok.eclipse.handlers.ast.EclipseASTMaker.java
License:Open Source License
@Override public ASTNode visitSwitch(final lombok.ast.Switch node, final Void p) { final SwitchStatement switchStatement = new SwitchStatement(); switchStatement.expression = build(node.getExpression()); List<Statement> caseStatements = new ArrayList<Statement>(); for (lombok.ast.Case caze : node.getCases()) { final CaseStatement caseStatement = new CaseStatement( caze.getPattern() == null ? null : build(caze.getPattern(), Expression.class), 0, 0); setGeneratedByAndCopyPos(caseStatement, source, posHintOf(node)); caseStatements.add(caseStatement); caseStatements.addAll(build(caze.getStatements(), Statement.class)); }//from w w w . j a va2s .c o m switchStatement.statements = caseStatements.toArray(new Statement[caseStatements.size()]); return switchStatement; }
From source file:lombok.eclipse.handlers.singulars.EclipseJavaUtilListSingularizer.java
License:Open Source License
@Override public void appendBuildCode(SingularData data, EclipseNode builderType, List<Statement> statements, char[] targetVariableName) { if (useGuavaInstead(builderType)) { guavaListSetSingularizer.appendBuildCode(data, builderType, statements, targetVariableName); return;//from w w w. j a va 2 s. com } List<Statement> switchContents = new ArrayList<Statement>(); /* case 0: (empty) break; */ { switchContents.add(new CaseStatement(makeIntLiteral(new char[] { '0' }, null), 0, 0)); MessageSend invoke = new MessageSend(); invoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0); invoke.selector = "emptyList".toCharArray(); switchContents.add(new Assignment(new SingleNameReference(data.getPluralName(), 0), invoke, 0)); switchContents.add(new BreakStatement(null, 0, 0)); } /* case 1: (singleton) break; */ { switchContents.add(new CaseStatement(makeIntLiteral(new char[] { '1' }, null), 0, 0)); FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L); thisDotField.receiver = new ThisReference(0, 0); MessageSend thisDotFieldGet0 = new MessageSend(); thisDotFieldGet0.receiver = thisDotField; thisDotFieldGet0.selector = new char[] { 'g', 'e', 't' }; thisDotFieldGet0.arguments = new Expression[] { makeIntLiteral(new char[] { '0' }, null) }; Expression[] args = new Expression[] { thisDotFieldGet0 }; MessageSend invoke = new MessageSend(); invoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0); invoke.selector = "singletonList".toCharArray(); invoke.arguments = args; switchContents.add(new Assignment(new SingleNameReference(data.getPluralName(), 0), invoke, 0)); switchContents.add(new BreakStatement(null, 0, 0)); } /* default: Create by passing builder field to constructor. */ { switchContents.add(new CaseStatement(null, 0, 0)); Expression argToUnmodifiable; /* new j.u.ArrayList<Generics>(this.pluralName); */ { FieldReference thisDotPluralName = new FieldReference(data.getPluralName(), 0L); thisDotPluralName.receiver = new ThisReference(0, 0); TypeReference targetTypeExpr = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS); targetTypeExpr = addTypeArgs(1, false, builderType, targetTypeExpr, data.getTypeArgs()); AllocationExpression constructorCall = new AllocationExpression(); constructorCall.type = targetTypeExpr; constructorCall.arguments = new Expression[] { thisDotPluralName }; argToUnmodifiable = constructorCall; } /* pluralname = Collections.unmodifiableList(-newlist-); */ { MessageSend unmodInvoke = new MessageSend(); unmodInvoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0); unmodInvoke.selector = "unmodifiableList".toCharArray(); unmodInvoke.arguments = new Expression[] { argToUnmodifiable }; switchContents .add(new Assignment(new SingleNameReference(data.getPluralName(), 0), unmodInvoke, 0)); } } SwitchStatement switchStat = new SwitchStatement(); switchStat.statements = switchContents.toArray(new Statement[switchContents.size()]); switchStat.expression = getSize(builderType, data.getPluralName(), true); TypeReference localShadowerType = new QualifiedTypeReference(Eclipse.fromQualifiedName(data.getTargetFqn()), NULL_POSS); localShadowerType = addTypeArgs(1, false, builderType, localShadowerType, data.getTypeArgs()); LocalDeclaration varDefStat = new LocalDeclaration(data.getPluralName(), 0, 0); varDefStat.type = localShadowerType; statements.add(varDefStat); statements.add(switchStat); }
From source file:lombok.eclipse.handlers.singulars.EclipseJavaUtilSingularizer.java
License:Open Source License
protected List<Statement> createJavaUtilSetMapInitialCapacitySwitchStatements(SingularData data, EclipseNode builderType, boolean mapMode, String emptyCollectionMethod, String singletonCollectionMethod, String targetType) { List<Statement> switchContents = new ArrayList<Statement>(); char[] keyName = mapMode ? (new String(data.getPluralName()) + "$key").toCharArray() : data.getPluralName(); if (emptyCollectionMethod != null) { // case 0: (empty); break; switchContents.add(new CaseStatement(makeIntLiteral(new char[] { '0' }, null), 0, 0)); /* pluralName = java.util.Collections.emptyCollectionMethod(); */ { MessageSend invoke = new MessageSend(); invoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0); invoke.selector = emptyCollectionMethod.toCharArray(); switchContents.add(new Assignment(new SingleNameReference(data.getPluralName(), 0), invoke, 0)); }//from w w w. jav a 2 s . c o m switchContents.add(new BreakStatement(null, 0, 0)); } if (singletonCollectionMethod != null) { // case 1: (singleton); break; switchContents.add(new CaseStatement(makeIntLiteral(new char[] { '1' }, null), 0, 0)); /* !mapMode: pluralName = java.util.Collections.singletonCollectionMethod(this.pluralName.get(0)); mapMode: pluralName = java.util.Collections.singletonCollectionMethod(this.pluralName$key.get(0), this.pluralName$value.get(0)); */ { FieldReference thisDotKey = new FieldReference(keyName, 0L); thisDotKey.receiver = new ThisReference(0, 0); MessageSend thisDotKeyGet0 = new MessageSend(); thisDotKeyGet0.receiver = thisDotKey; thisDotKeyGet0.selector = new char[] { 'g', 'e', 't' }; thisDotKeyGet0.arguments = new Expression[] { makeIntLiteral(new char[] { '0' }, null) }; Expression[] args; if (mapMode) { char[] valueName = (new String(data.getPluralName()) + "$value").toCharArray(); FieldReference thisDotValue = new FieldReference(valueName, 0L); thisDotValue.receiver = new ThisReference(0, 0); MessageSend thisDotValueGet0 = new MessageSend(); thisDotValueGet0.receiver = thisDotValue; thisDotValueGet0.selector = new char[] { 'g', 'e', 't' }; thisDotValueGet0.arguments = new Expression[] { makeIntLiteral(new char[] { '0' }, null) }; args = new Expression[] { thisDotKeyGet0, thisDotValueGet0 }; } else { args = new Expression[] { thisDotKeyGet0 }; } MessageSend invoke = new MessageSend(); invoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0); invoke.selector = singletonCollectionMethod.toCharArray(); invoke.arguments = args; switchContents.add(new Assignment(new SingleNameReference(data.getPluralName(), 0), invoke, 0)); } switchContents.add(new BreakStatement(null, 0, 0)); } { // default: switchContents.add(new CaseStatement(null, 0, 0)); switchContents.addAll(createJavaUtilSimpleCreationAndFillStatements(data, builderType, mapMode, false, true, emptyCollectionMethod == null, targetType)); } SwitchStatement switchStat = new SwitchStatement(); switchStat.statements = switchContents.toArray(new Statement[switchContents.size()]); switchStat.expression = getSize(builderType, keyName, true); TypeReference localShadowerType = new QualifiedTypeReference(fromQualifiedName(data.getTargetFqn()), NULL_POSS); localShadowerType = addTypeArgs(mapMode ? 2 : 1, false, builderType, localShadowerType, data.getTypeArgs()); LocalDeclaration varDefStat = new LocalDeclaration(data.getPluralName(), 0, 0); varDefStat.type = localShadowerType; return Arrays.asList(varDefStat, switchStat); }
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
protected void consumeCaseLabel() { // SwitchLabel ::= 'case' ConstantExpression ':' this.expressionLengthPtr--; Expression expression = this.expressionStack[this.expressionPtr--]; CaseStatement caseStatement = new CaseStatement(expression, expression.sourceEnd, this.intStack[this.intPtr--]); // Look for $fall-through$ tag in leading comment for case statement if (hasLeadingTagComment(FALL_THROUGH_TAG, caseStatement.sourceStart)) { caseStatement.bits |= ASTNode.DocumentedFallthrough; }//from w w w . ja va2 s .co m pushOnAstStack(caseStatement); }
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
protected void consumeDefaultLabel() { // SwitchLabel ::= 'default' ':' CaseStatement defaultStatement = new CaseStatement(null, this.intStack[this.intPtr--], this.intStack[this.intPtr--]); // Look for $fall-through$ tag in leading comment for case statement if (hasLeadingTagComment(FALL_THROUGH_TAG, defaultStatement.sourceStart)) { defaultStatement.bits |= ASTNode.DocumentedFallthrough; }// ww w.ja v a2s.co m pushOnAstStack(defaultStatement); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator.java
License:Open Source License
public CaseStatement caseStatement(Expression constExpr) { return new CaseStatement(constExpr, this.sourceStart, this.sourceEnd); }