@Override public Object evaluate(ExpressionContext context) throws ExpressionExecutionException { Object thisElement = null; IEvaluationContext evaluationContext = contextProvider.get(); evaluationContext.newValue(XbaseScopeProvider.THIS, thisElement); if (context != null) { for (String elementName : context.getVariableNames()) { Object instance = context.getInstance(elementName); if (instance == null && context instanceof DynamicExpressionContext) { instance = ((DynamicExpressionContext) context).getDynInstance(elementName); } if (instance != null) { evaluationContext.newValue(QualifiedName.create(elementName), instance); } } } else { context = new ExpressionContext(); } IEvaluationResult result = elInterpreter.evaluate(xExpression, evaluationContext, CancelIndicator.NullImpl); if (result.getException() != null) { throw new ExpressionExecutionException("Boo!", result.getException()); } return result.getResult(); }
private void handleSecrecy( Entity session, Entity child, List<ITerm> knowers, FunctionSymbol setSymbol, String protName, ExpressionContext ctx, ITerm term) { LocationInfo loc = term.getLocation(); Entity rootEnt = session.findRootEntity(); FunctionTerm secrecyTerm = rootEnt.secrecyTerm( session, session.getIDSymbol().term(loc, child), child, knowers, term /* = payload*/, setSymbol, protName, loc); // System.out.println("secrecy term: " + secrecyTerm.getRepresentation()); ctx.addSessionGoalTerm(secrecyTerm); for (ITerm t : session.childChain(loc, child)) { ctx.addSessionGoalTerm(t); } }
// updates all expression specs which are evaluable public void updateEvaluables(String expr, CandidateTable cTable) throws SemanticException { String alias = cubeql.getAliasForTableName(cTable.getBaseTable().getName()); ExpressionContext ec = getExpressionContext(expr, alias); if (cTable.getColumns().contains(expr)) { // expression is directly materialized in candidate table ec.addDirectlyAvailable(cTable); } for (ExprSpecContext esc : ec.allExprs) { if (esc.getTblAliasToColumns().get(alias) == null) { log.debug("{} = {} is evaluable in {}", expr, esc, cTable); ec.addEvaluable(cubeql, cTable, esc); } else { Set<String> columns = esc.getTblAliasToColumns().get(alias); boolean isEvaluable = true; for (String col : columns) { if (!cTable.getColumns().contains(col.toLowerCase())) { if (!cubeql .getDeNormCtx() .addRefUsage(cTable, col, cTable.getBaseTable().getName())) { // check if it is available as reference, if not expression is not evaluable log.debug("{} = {} is not evaluable in {}", expr, esc, cTable); isEvaluable = false; break; } } } if (isEvaluable) { log.debug("{} = {} is evaluable in {}", expr, esc, cTable); ec.addEvaluable(cubeql, cTable, esc); } } } }
ExpressionContext getExpressionContext(String expr, String alias) { for (ExpressionContext ec : allExprsQueried.get(expr)) { if (ec.getSrcAlias().equals(alias)) { return ec; } } throw new IllegalArgumentException("no expression available for " + expr + " alias:" + alias); }
boolean hasAggregates() { for (Set<ExpressionContext> ecSet : allExprsQueried.values()) { for (ExpressionContext ec : ecSet) { if (ec.hasAggregates()) { return true; } } } return false; }
@Override public Result calculateResult( @NotNull Expression[] expressions, ExpressionContext expressionContext) { PsiFile file = PsiDocumentManager.getInstance(expressionContext.getProject()) .getPsiFile(expressionContext.getEditor().getDocument()); if (file instanceof LuaPsiFile) return new TextResult(file.getName()); return null; }
public boolean hasMeasures(String expr, CubeInterface cube) { String alias = cubeql.getAliasForTableName(cube.getName()); ExpressionContext ec = getExpressionContext(expr, alias); boolean hasMeasures = false; for (ExprSpecContext esc : ec.allExprs) { if (esc.getTblAliasToColumns().get(alias) != null) { for (String cubeCol : esc.getTblAliasToColumns().get(alias)) { if (cube.getMeasureByName(cubeCol) != null) { hasMeasures = true; break; } } } } ec.hasMeasures = hasMeasures; return hasMeasures; }
void addExpressionQueried(ExpressionContext expr) { String exprCol = expr.getExprCol().getName().toLowerCase(); Set<ExpressionContext> ecSet = allExprsQueried.get(exprCol); if (ecSet == null) { ecSet = new LinkedHashSet<ExpressionContext>(); allExprsQueried.put(exprCol, ecSet); } ecSet.add(expr); }
private void pickExpressionsForTable(CandidateTable cTable) { for (Map.Entry<String, Set<ExpressionContext>> ecEntry : allExprsQueried.entrySet()) { Set<ExpressionContext> ecSet = ecEntry.getValue(); for (ExpressionContext ec : ecSet) { if (ec.getSrcTable().getName().equals(cTable.getBaseTable().getName())) { if (!ec.directlyAvailableIn.contains(cTable)) { if (ec.evaluableExpressions.get(cTable) != null && !ec.evaluableExpressions.get(cTable).isEmpty()) { // pick first evaluable expression Set<PickedExpression> peSet = pickedExpressions.get(ecEntry.getKey()); if (peSet == null) { peSet = new HashSet<PickedExpression>(); pickedExpressions.put(ecEntry.getKey(), peSet); } peSet.add( new PickedExpression( ec.srcAlias, ec.evaluableExpressions.get(cTable).iterator().next())); } } } } } }
private void invokeCompletion(final ExpressionContext context) { final Project project = context.getProject(); final Editor editor = context.getEditor(); final PsiFile psiFile = editor != null ? PsiUtilBase.getPsiFileInEditor(editor, project) : null; Runnable runnable = () -> { if (project.isDisposed() || editor == null || editor.isDisposed() || psiFile == null || !psiFile.isValid()) return; // it's invokeLater, so another completion could have started if (CompletionServiceImpl.getCompletionService().getCurrentCompletion() != null) return; CommandProcessor.getInstance() .executeCommand( project, () -> { // if we're in some completion's insert handler, make sure our new completion // isn't treated as the second invocation CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion); invokeCompletionHandler(project, editor); Lookup lookup = LookupManager.getInstance(project).getActiveLookup(); if (lookup != null) { lookup.addLookupListener( new MyLookupListener(context, myCheckCompletionChar)); } }, "", null); }; ApplicationManager.getApplication().invokeLater(runnable); }
@Override public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) { if (params.length != 1) return null; final Result result = params[0].calculateResult(context); if (result == null) return null; Project project = context.getProject(); PsiExpression expr = MacroUtil.resultToPsiExpression(result, context); if (expr == null) return null; PsiType type = expr.getType(); if (type instanceof PsiArrayType) { return new PsiTypeResult(((PsiArrayType) type).getComponentType(), project); } if (type instanceof PsiClassType) { PsiClassType.ClassResolveResult resolveResult = ((PsiClassType) type).resolveGenerics(); PsiClass aClass = resolveResult.getElement(); if (aClass != null) { PsiClass iterableClass = JavaPsiFacade.getInstance(project) .findClass("java.lang.Iterable", aClass.getResolveScope()); if (iterableClass != null) { PsiSubstitutor substitutor = TypeConversionUtil.getClassSubstitutor( iterableClass, aClass, resolveResult.getSubstitutor()); if (substitutor != null) { PsiType parameterType = substitutor.substitute(iterableClass.getTypeParameters()[0]); if (parameterType instanceof PsiCapturedWildcardType) { parameterType = ((PsiCapturedWildcardType) parameterType).getWildcard(); } if (parameterType != null) { if (parameterType instanceof PsiWildcardType) { if (((PsiWildcardType) parameterType).isExtends()) { return new PsiTypeResult(((PsiWildcardType) parameterType).getBound(), project); } else return null; } return new PsiTypeResult(parameterType, project); } } } } } return null; }
@Override public void itemSelected(LookupEvent event) { LookupElement item = event.getItem(); if (item == null) return; char c = event.getCompletionChar(); if (myCheckCompletionChar && !LookupEvent.isSpecialCompletionChar(c)) { return; } final Project project = myContext.getProject(); if (project == null) { return; } Runnable runnable = () -> new WriteCommandAction(project) { @Override protected void run(@NotNull com.intellij.openapi.application.Result result) throws Throwable { Editor editor = myContext.getEditor(); if (editor != null) { TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); if (templateState != null) { templateState.considerNextTabOnLookupItemSelected(item); } } } }.execute(); if (ApplicationManager.getApplication().isUnitTestMode()) { runnable.run(); } else { ApplicationManager.getApplication() .invokeLater(runnable, ModalityState.current(), project.getDisposed()); } }
// for new-style (i.e., session) secrecy and channel goals public void buildGoalContext(ExpressionContext ctx, ITerm term) { Entity current = term.getScope().findFirstEntity(); LocationInfo loc = term.getLocation(); if (current == null || goal == null || !(goal.getOwner() instanceof Entity)) { // maybe due to disabled goal, which is warned for. if (goal != null) // should not get here! current .getErrorGatherer() .addError( loc, ErrorMessages.INTERNAL_ERROR_ANNOTATION_LOST, this.name, term.getRepresentation()); return; } Entity session = (Entity) goal.getOwner(); IScope root = session.findRoot(); if (goal instanceof SessionSecrecyGoal) { SessionSecrecyGoal secrGoal = (SessionSecrecyGoal) goal; handleSecrecy( session, current, knowers, secrGoal.getSetSymbol(), secrGoal.getSecrecyProtocolName(), ctx, term); } else { SessionChannelGoal chGoal = (SessionChannelGoal) goal; boolean undirectedAuth = chGoal.hasUndirectedAuthentication(); ITerm actor = current.getActorSymbol().term(); boolean senderIsActor = actor.equals(sender); boolean receiverIsActor = actor.equals(receiver); { if (sender != null && (receiver != null || undirectedAuth)) { if (chGoal.hasSecrecy()) { List<ITerm> knowers = new ArrayList<ITerm>(); knowers.add(sender); knowers.add(receiver); handleSecrecy( session, current, knowers, chGoal.getSetSymbol(), chGoal.getSecrecyProtocolName(), ctx, term); // retract secrecy on receive (i.e. add intruder to set of knowers): if (receiverIsActor) { ITerm retractSecr = root.findFunction(Prelude.ADD) .term( chGoal.getSetSymbol().term(session.getIDSymbol().term()), root.findConstant(Prelude.INTRUDER).term()); ctx.addSessionGoalTerm(retractSecr); } } if (chGoal.hasAuthentication() || chGoal.hasFreshness()) { List<ITerm> toAdd = new ArrayList<ITerm>(); ConstantSymbol cAuthProt = null; if (chGoal.hasAuthentication()) { cAuthProt = session.findRootEntity().findConstant(chGoal.getAuthenticationProtocolName()); } ConstantSymbol cFreshProt = null; if (chGoal.hasFreshness()) { cFreshProt = session.findRootEntity().findConstant(chGoal.getFreshnessProtocolName()); } if (senderIsActor) { // sender side if (chGoal.hasAuthentication()) { toAdd.add( root.findFunction(Prelude.WITNESS) .term( actor, chGoal.hasUndirectedAuthentication() ? root.findConstant(Prelude.INTRUDER).term() : receiver, cAuthProt.term(), term)); } /* if (chGoal.hasFreshness()) { toAdd.add(root.findFunction(Prelude.WITNESS).term(mappedSender.term(), <ceiver.term(), cFreshProt.term(), this)); }*/ } else { // receiver side if (chGoal.hasAuthentication()) { toAdd.add( root.findFunction(Prelude.REQUEST) .term(actor, sender, cAuthProt.term(), term, current.getIDSymbol().term())); } if (chGoal.hasFreshness()) { toAdd.add( root.findFunction(Prelude.REQUEST) .term( actor, sender, cFreshProt.term(), term, current.getIDSymbol().term())); } } for (ITerm t : toAdd) { ctx.addSessionGoalTerm(t); } } } } } }
@Override public void visitForStatement(GrForStatement forStatement) { // final StringBuilder builder = new StringBuilder(); builder.append("for("); final GrForClause clause = forStatement.getClause(); ExpressionContext forContext = context.extend(); if (clause instanceof GrForInClause) { final GrExpression expression = ((GrForInClause) clause).getIteratedExpression(); final GrVariable declaredVariable = clause.getDeclaredVariable(); LOG.assertTrue(declaredVariable != null); writeVariableWithoutSemicolonAndInitializer(builder, declaredVariable, context); builder.append(" : "); if (expression != null) { final ExpressionContext context = forContext.copy(); writeExpression(expression, builder, context); } } else if (clause instanceof GrTraditionalForClause) { final GrTraditionalForClause cl = (GrTraditionalForClause) clause; final GrCondition initialization = cl.getInitialization(); final GrExpression condition = cl.getCondition(); final GrExpression update = cl.getUpdate(); if (initialization instanceof GrParameter) { StringBuilder partBuilder = new StringBuilder(); writeVariableWithoutSemicolonAndInitializer( partBuilder, (GrParameter) initialization, context); final GrExpression initializer = ((GrParameter) initialization).getInitializerGroovy(); if (initializer != null) { final ExpressionContext partContext = forContext.copy(); partBuilder.append(" = "); writeExpression(initializer, partBuilder, partContext); for (String statement : partContext.myStatements) { builder.append(statement).append(", "); } builder.append(partBuilder); } } else if (initialization != null) { StringBuilder partBuilder = new StringBuilder(); final ExpressionContext partContext = forContext.copy(); genForPart(builder, initialization, new CodeBlockGenerator(partBuilder, partContext, null)); } builder.append(';'); if (condition != null) { genForPart(builder, condition, forContext.copy()); // todo??? } builder.append(';'); if (update != null) { genForPart(builder, update, forContext.copy()); } } builder.append(')'); final GrStatement body = forStatement.getBody(); if (body != null) { body.accept(new CodeBlockGenerator(builder, forContext, null)); } }
@Override public void rewriteContext(CubeQueryContext cubeql) throws SemanticException { ExpressionResolverContext exprCtx = cubeql.getExprCtx(); if (exprCtx == null) { exprCtx = new ExpressionResolverContext(cubeql); cubeql.setExprCtx(exprCtx); for (Map.Entry<String, Set<String>> entry : cubeql.getTblAliasToColumns().entrySet()) { String alias = entry.getKey(); // skip default alias if (alias == CubeQueryContext.DEFAULT_TABLE) { continue; } AbstractCubeTable tbl = cubeql.getCubeTableForAlias(alias); Set<String> columns = entry.getValue(); for (String column : columns) { CubeColumn col; if (tbl instanceof CubeInterface) { col = ((CubeInterface) tbl).getColumnByName(column); } else { col = ((Dimension) tbl).getColumnByName(column); } if (col instanceof ExprColumn) { exprCtx.addExpressionQueried( new ExpressionContext(cubeql, (ExprColumn) col, (AbstractBaseTable) tbl, alias)); } } } Set<String> exprsWithMeasures = new HashSet<String>(); for (String expr : cubeql.getQueriedExprs()) { if (cubeql.getExprCtx().hasMeasures(expr, cubeql.getCube())) { // expression has measures exprsWithMeasures.add(expr); } } cubeql.addQueriedExprsWithMeasures(exprsWithMeasures); } else { // prune invalid expressions cubeql.getExprCtx().pruneExpressions(); // prune candidate facts without any valid expressions if (cubeql.getCube() != null && !cubeql.getCandidateFacts().isEmpty()) { for (Map.Entry<String, Set<ExpressionContext>> ecEntry : exprCtx.allExprsQueried.entrySet()) { String expr = ecEntry.getKey(); Set<ExpressionContext> ecSet = ecEntry.getValue(); for (ExpressionContext ec : ecSet) { if (ec.getSrcTable().getName().equals(cubeql.getCube().getName())) { if (cubeql.getQueriedExprsWithMeasures().contains(expr)) { for (Iterator<Set<CandidateFact>> sItr = cubeql.getCandidateFactSets().iterator(); sItr.hasNext(); ) { Set<CandidateFact> factSet = sItr.next(); boolean evaluableInSet = false; for (CandidateFact cfact : factSet) { if (ec.isEvaluable(cfact)) { evaluableInSet = true; } } if (!evaluableInSet) { log.info( "Not considering fact table set:{} as {} is not evaluable", factSet, ec.exprCol.getName()); sItr.remove(); } } } else { for (Iterator<CandidateFact> i = cubeql.getCandidateFacts().iterator(); i.hasNext(); ) { CandidateFact cfact = i.next(); if (!ec.isEvaluable(cfact)) { log.info( "Not considering fact table:{} as {} is not evaluable", cfact, ec.exprCol.getName()); cubeql.addFactPruningMsgs( cfact.fact, CandidateTablePruneCause.expressionNotEvaluable(ec.exprCol.getName())); i.remove(); } } } } } } cubeql.pruneCandidateFactWithCandidateSet(CandidateTablePruneCode.EXPRESSION_NOT_EVALUABLE); } // prune candidate dims without any valid expressions if (cubeql.getDimensions() != null && !cubeql.getDimensions().isEmpty()) { for (Dimension dim : cubeql.getDimensions()) { for (Iterator<CandidateDim> i = cubeql.getCandidateDimTables().get(dim).iterator(); i.hasNext(); ) { CandidateDim cdim = i.next(); for (Map.Entry<String, Set<ExpressionContext>> ecEntry : exprCtx.allExprsQueried.entrySet()) { Set<ExpressionContext> ecSet = ecEntry.getValue(); for (ExpressionContext ec : ecSet) { if (ec.getSrcTable().getName().equals(cdim.getBaseTable().getName())) { if (!ec.isEvaluable(cdim)) { log.info( "Not considering dim table:{} as {} is not evaluable", cdim, ec.exprCol.getName()); cubeql.addDimPruningMsgs( dim, cdim.dimtable, CandidateTablePruneCause.expressionNotEvaluable(ec.exprCol.getName())); i.remove(); } } } } } } } } }
void pruneExpressions() { for (Set<ExpressionContext> ecSet : allExprsQueried.values()) { for (ExpressionContext ec : ecSet) { Set<ExprSpecContext> removedEsc = new HashSet<ExprSpecContext>(); for (Iterator<ExprSpecContext> iterator = ec.getAllExprs().iterator(); iterator.hasNext(); ) { ExprSpecContext esc = iterator.next(); boolean removed = false; // Go over expression dims and remove expression involving dimensions for which // candidate tables are // not there for (Dimension exprDim : esc.exprDims) { if (cubeql.getCandidateDims().get(exprDim) == null || cubeql.getCandidateDims().get(exprDim).isEmpty()) { log.info( "Removing expression {} as {} it does not have any candidate tables", esc, exprDim); iterator.remove(); removedEsc.add(esc); removed = true; break; } } if (removed) { continue; } // remove expressions which are not valid in the timerange queried // If an expression is defined as // ex = a + b // from t1 to t2; // ex = c + d // from t2 to t3 // With range queried, invalid expressions will be removed // If range is including more than one expression, queries can be unioned as an // improvement at later time. // But for now, they are not eligible expressions for (TimeRange range : cubeql.getTimeRanges()) { if (!esc.isValidInTimeRange(range)) { log.info("Removing expression {} as it is not valid in timerange queried", esc); iterator.remove(); removedEsc.add(esc); removed = true; break; } } if (removed) { continue; } // Go over expressions and remove expression containing unavailable columns in timerange // In the example above, // if ex = a +b ; and a is not available in timerange queried, it will be removed. for (TimeRange range : cubeql.getTimeRanges()) { boolean toRemove = false; for (Map.Entry<String, Set<String>> entry : esc.getTblAliasToColumns().entrySet()) { if (CubeQueryContext.DEFAULT_TABLE.equalsIgnoreCase(entry.getKey())) { continue; } AbstractBaseTable baseTable = (AbstractBaseTable) cubeql.getCubeTableForAlias(entry.getKey()); for (String col : entry.getValue()) { if (!baseTable.getColumnByName(col).isColumnAvailableInTimeRange(range)) { toRemove = true; break; } } if (toRemove) { break; } } if (toRemove) { log.info( "Removing expression {} as its columns are unavailable in timerange queried", esc); iterator.remove(); removedEsc.add(esc); removed = true; break; } } } for (Set<ExprSpecContext> evalSet : ec.evaluableExpressions.values()) { evalSet.removeAll(removedEsc); } } } }
/** Update all the element properties... */ public void updateSelection(JReportFrame newJrf) { // Improving speed... // Do nothing if there are elements selected... if (newJrf != null && newJrf.getSelectedElements().size() > 0) return; // Fix for numbers focus losing... if (newJrf == null) { this.setSelection(new Vector()); } else { this.setSelection(newJrf.getSelectedObjects()); } setInit(true); this.removeAllProperties(); this.jrf = newJrf; if (jrf == null || getSelection().size() == 0) { this.recreateSheet(); return; } try { Vector selectedElements = getSelection(); boolean sameParameterDescription = true; boolean sameParameterDefaultValueExpression = true; boolean sameParameterClassType = true; boolean sameParameterIsForPrompting = true; boolean sameFieldDescription = true; boolean sameFieldClassType = true; boolean sameVariableResetType = true; boolean sameVariableResetGroup = true; boolean sameVariableCalculationType = true; boolean sameVariableClassType = true; boolean sameVariableExpression = true; boolean sameVariableInitialValueExpression = true; boolean sameVariableIncrementGroup = true; boolean sameVariableIncrementType = true; boolean sameVariableIncrementerClass = true; boolean areAllparameters = true; boolean areAllfields = true; boolean areAllvariables = true; boolean isTheFirstElement = true; boolean areBuiltInParameters = false; // True if one ore more parameter is builtin... boolean areBuiltInVariables = false; // True if one ore more parameter is builtin... SubDataset subdataset = null; for (int i = 0; i < selectedElements.size(); ++i) { Object obj = selectedElements.elementAt(i); if (!(obj instanceof JRParameter)) { areAllparameters = false; } if (!(obj instanceof JRField)) { areAllfields = false; } if (!(obj instanceof JRVariable)) { areAllvariables = false; } if (isTheFirstElement) { subdataset = Misc.getObjectSubDataset(jrf.getReport(), obj); updateAllComboBoxes(subdataset); } else if (subdataset != null) { SubDataset s2 = Misc.getObjectSubDataset(subdataset, obj); if (s2 != subdataset) { subdataset = null; } } if (areAllparameters) { JRParameter param = (JRParameter) selectedElements.elementAt(i); if (!areBuiltInParameters) { areBuiltInParameters = param.isBuiltin(); } if (selectedElements.size() == 1) { // Single parameter selectes... setTextArea(isTheFirstElement, param.getName(), spParameterName); spParameterProperties.setValue(param.getProperties()); } if (sameParameterDescription) sameParameterDescription = setTextArea(isTheFirstElement, param.getDescription(), spParameterDescription); if (sameParameterDefaultValueExpression) sameParameterDefaultValueExpression = setTextArea( isTheFirstElement, param.getDefaultValueExpression(), spParameterDefaultValueExpression); if (sameParameterClassType) sameParameterClassType = setGenericSheetProperty( isTheFirstElement, param.getClassType(), spParameterClassType); if (sameParameterIsForPrompting) sameParameterIsForPrompting = this.setCheckBox( isTheFirstElement, param.isIsForPrompting(), false, spParameterIsForPrompting); } if (areAllfields) { JRField field = (JRField) selectedElements.elementAt(i); if (selectedElements.size() == 1) { // Single parameter selectes... setTextArea(isTheFirstElement, field.getName(), spFieldName); spFieldProperties.setValue(field.getProperties()); } if (sameFieldDescription) sameFieldDescription = setTextArea(isTheFirstElement, field.getDescription(), spFieldDescription); if (sameFieldClassType) sameFieldClassType = setGenericSheetProperty(isTheFirstElement, field.getClassType(), spFieldClassType); } if (areAllvariables) { JRVariable variable = (JRVariable) selectedElements.elementAt(i); if (!areBuiltInVariables) { areBuiltInVariables = variable.isBuiltin(); } if (selectedElements.size() == 1) { // Single parameter selectes... setTextArea(isTheFirstElement, variable.getName(), spVariableName); } if (subdataset != null) { if (sameVariableResetType) sameVariableResetType = setTagComboBox(isTheFirstElement, variable.getResetType(), spVariableResetType); if (sameVariableResetGroup) sameVariableResetGroup = setTagComboBox(isTheFirstElement, variable.getResetGroup(), spVariableResetGroup); if (sameVariableIncrementType) sameVariableIncrementType = setTagComboBox( isTheFirstElement, variable.getIncrementType(), spVariableIncrementType); if (sameVariableIncrementGroup) sameVariableIncrementGroup = setTagComboBox( isTheFirstElement, variable.getIncrementGroup(), spVariableIncrementGroup); } if (sameVariableCalculationType) sameVariableCalculationType = setTagComboBox( isTheFirstElement, variable.getCalculation(), spVariableCalculationType); if (sameVariableIncrementerClass) sameVariableIncrementerClass = setTextArea( isTheFirstElement, variable.getIncrementerFactoryClass(), spVariableIncrementerClass); if (sameVariableClassType) sameVariableClassType = setGenericSheetProperty( isTheFirstElement, variable.getClassType(), spVariableClassType); if (sameVariableExpression) sameVariableExpression = setTextArea(isTheFirstElement, variable.getExpression(), spVariableExpression); if (sameVariableInitialValueExpression) sameVariableInitialValueExpression = setTextArea( isTheFirstElement, variable.getInitialValueExpression(), spVariableInitialValueExpression); } isTheFirstElement = false; } // TO DO: change this! // get the common subdataset... if (subdataset != null) { ExpressionContext ec = new ExpressionContext(); ec.setSubDataset(subdataset); spParameterDefaultValueExpression.setExpressionContext(ec); spVariableExpression.setExpressionContext(ec); spVariableInitialValueExpression.setExpressionContext(ec); } spParameterDefaultValueExpression.setLabelError(null); spParameterDefaultValueExpression.updateLabel(); spVariableExpression.setLabelError(null); spVariableExpression.updateLabel(); spVariableInitialValueExpression.setLabelError(null); spVariableInitialValueExpression.updateLabel(); if (areAllparameters) { String commonStr = it.businesslogic.ireport.util.I18n.getString( "parameterProperties", "Parameter Properties"); if (getSelection().size() == 1) this.addSheetProperty(commonStr, spParameterName); spParameterIsForPrompting.setDefaultValue(new Boolean(true)); this.addSheetProperty(commonStr, spParameterClassType); spParameterClassType.setLabelColor( (sameParameterClassType) ? mandatoryPropertiesLabelColor : sharedDifferentValueLabelColor); if (!areBuiltInParameters) { spParameterName.setReadOnly(false); spParameterClassType.setReadOnly(false); spParameterIsForPrompting.setLabelColor( (sameParameterIsForPrompting) ? mandatoryPropertiesLabelColor : sharedDifferentValueLabelColor); this.addSheetProperty(commonStr, spParameterIsForPrompting); spParameterDefaultValueExpression.setLabelColor( (sameParameterDefaultValueExpression) ? mandatoryPropertiesLabelColor : sharedDifferentValueLabelColor); this.addSheetProperty(commonStr, spParameterDefaultValueExpression); if (getSelection().size() == 1) this.addSheetProperty(commonStr, spParameterProperties); } else { spParameterName.setReadOnly(true); spParameterClassType.setReadOnly(true); } } else if (areAllfields) { String commonStr = it.businesslogic.ireport.util.I18n.getString("fieldProperties", "Field Properties"); if (getSelection().size() == 1) this.addSheetProperty(commonStr, spFieldName); spFieldClassType.setLabelColor( (sameFieldClassType) ? mandatoryPropertiesLabelColor : sharedDifferentValueLabelColor); this.addSheetProperty(commonStr, spFieldClassType); spFieldDescription.setLabelColor( (sameFieldDescription) ? mandatoryPropertiesLabelColor : sharedDifferentValueLabelColor); this.addSheetProperty(commonStr, spFieldDescription); if (getSelection().size() == 1) this.addSheetProperty(commonStr, spFieldProperties); } else if (areAllvariables) { String commonStr = it.businesslogic.ireport.util.I18n.getString( "variableProperties", "Variable Properties"); if (getSelection().size() == 1) this.addSheetProperty(commonStr, spVariableName); spVariableClassType.setLabelColor( (sameVariableClassType) ? mandatoryPropertiesLabelColor : sharedDifferentValueLabelColor); this.addSheetProperty(commonStr, spVariableClassType); if (!areBuiltInVariables) { spVariableName.setReadOnly(false); spVariableClassType.setReadOnly(false); spVariableCalculationType.setLabelColor( (sameVariableCalculationType) ? mandatoryPropertiesLabelColor : sharedDifferentValueLabelColor); this.addSheetProperty(commonStr, spVariableCalculationType); if (subdataset != null) { spVariableResetType.setLabelColor( (sameVariableResetType) ? mandatoryPropertiesLabelColor : sharedDifferentValueLabelColor); this.addSheetProperty(commonStr, spVariableResetType); spVariableResetGroup.setLabelColor( (sameVariableResetGroup) ? mandatoryPropertiesLabelColor : sharedDifferentValueLabelColor); this.addSheetProperty(commonStr, spVariableResetGroup); spVariableIncrementType.setLabelColor( (sameVariableIncrementType) ? mandatoryPropertiesLabelColor : sharedDifferentValueLabelColor); this.addSheetProperty(commonStr, spVariableIncrementType); spVariableIncrementGroup.setLabelColor( (sameVariableIncrementGroup) ? mandatoryPropertiesLabelColor : sharedDifferentValueLabelColor); this.addSheetProperty(commonStr, spVariableIncrementGroup); if (!sameVariableResetType || !spVariableResetType.getValue().equals("Group")) { spVariableResetGroup.setReadOnly(true); } else { spVariableResetGroup.setReadOnly(false); } if (!sameVariableIncrementType || !spVariableIncrementType.getValue().equals("Group")) { spVariableIncrementGroup.setReadOnly(true); } else { spVariableIncrementGroup.setReadOnly(false); } } spVariableIncrementerClass.setLabelColor( (sameVariableIncrementerClass) ? mandatoryPropertiesLabelColor : sharedDifferentValueLabelColor); this.addSheetProperty(commonStr, spVariableIncrementerClass); spVariableExpression.setLabelColor( (sameVariableExpression) ? mandatoryPropertiesLabelColor : sharedDifferentValueLabelColor); this.addSheetProperty(commonStr, spVariableExpression); spVariableInitialValueExpression.setLabelColor( (sameVariableInitialValueExpression) ? mandatoryPropertiesLabelColor : sharedDifferentValueLabelColor); this.addSheetProperty(commonStr, spVariableInitialValueExpression); } else { spVariableName.setReadOnly(true); spVariableClassType.setReadOnly(true); } } this.recreateSheet(); } catch (Exception ex) { ex.printStackTrace(); } finally { } setInit(false); }
private ExpressionContext expression(int _p) throws RecognitionException { ParserRuleContext _parentctx = _ctx; int _parentState = getState(); ExpressionContext _localctx = new ExpressionContext(_ctx, _parentState); ExpressionContext _prevctx = _localctx; int _startState = 2; enterRecursionRule(_localctx, 2, RULE_expression, _p); int _la; try { int _alt; enterOuterAlt(_localctx, 1); { setState(30); switch (_input.LA(1)) { case BOOLNOT: case BWNOT: case ADD: case SUB: { _localctx = new UnaryContext(_localctx); _ctx = _localctx; _prevctx = _localctx; setState(8); _la = _input.LA(1); if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << BOOLNOT) | (1L << BWNOT) | (1L << ADD) | (1L << SUB))) != 0))) { _errHandler.recoverInline(this); } else { consume(); } setState(9); expression(12); } break; case LP: { _localctx = new PrecedenceContext(_localctx); _ctx = _localctx; _prevctx = _localctx; setState(10); match(LP); setState(11); expression(0); setState(12); match(RP); } break; case OCTAL: case HEX: case DECIMAL: { _localctx = new NumericContext(_localctx); _ctx = _localctx; _prevctx = _localctx; setState(14); _la = _input.LA(1); if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << OCTAL) | (1L << HEX) | (1L << DECIMAL))) != 0))) { _errHandler.recoverInline(this); } else { consume(); } } break; case VARIABLE: { _localctx = new ExternalContext(_localctx); _ctx = _localctx; _prevctx = _localctx; setState(15); match(VARIABLE); setState(28); switch (getInterpreter().adaptivePredict(_input, 2, _ctx)) { case 1: { setState(16); match(LP); setState(25); _la = _input.LA(1); if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << LP) | (1L << BOOLNOT) | (1L << BWNOT) | (1L << ADD) | (1L << SUB) | (1L << VARIABLE) | (1L << OCTAL) | (1L << HEX) | (1L << DECIMAL))) != 0)) { { setState(17); expression(0); setState(22); _errHandler.sync(this); _la = _input.LA(1); while (_la == COMMA) { { { setState(18); match(COMMA); setState(19); expression(0); } } setState(24); _errHandler.sync(this); _la = _input.LA(1); } } } setState(27); match(RP); } break; } } break; default: throw new NoViableAltException(this); } _ctx.stop = _input.LT(-1); setState(70); _errHandler.sync(this); _alt = getInterpreter().adaptivePredict(_input, 5, _ctx); while (_alt != 2 && _alt != org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER) { if (_alt == 1) { if (_parseListeners != null) triggerExitRuleEvent(); _prevctx = _localctx; { setState(68); switch (getInterpreter().adaptivePredict(_input, 4, _ctx)) { case 1: { _localctx = new MuldivContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); setState(32); if (!(precpred(_ctx, 11))) throw new FailedPredicateException(this, "precpred(_ctx, 11)"); setState(33); _la = _input.LA(1); if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << MUL) | (1L << DIV) | (1L << REM))) != 0))) { _errHandler.recoverInline(this); } else { consume(); } setState(34); expression(12); } break; case 2: { _localctx = new AddsubContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); setState(35); if (!(precpred(_ctx, 10))) throw new FailedPredicateException(this, "precpred(_ctx, 10)"); setState(36); _la = _input.LA(1); if (!(_la == ADD || _la == SUB)) { _errHandler.recoverInline(this); } else { consume(); } setState(37); expression(11); } break; case 3: { _localctx = new BwshiftContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); setState(38); if (!(precpred(_ctx, 9))) throw new FailedPredicateException(this, "precpred(_ctx, 9)"); setState(39); _la = _input.LA(1); if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << LSH) | (1L << RSH) | (1L << USH))) != 0))) { _errHandler.recoverInline(this); } else { consume(); } setState(40); expression(10); } break; case 4: { _localctx = new BoolcompContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); setState(41); if (!(precpred(_ctx, 8))) throw new FailedPredicateException(this, "precpred(_ctx, 8)"); setState(42); _la = _input.LA(1); if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << LT) | (1L << LTE) | (1L << GT) | (1L << GTE))) != 0))) { _errHandler.recoverInline(this); } else { consume(); } setState(43); expression(9); } break; case 5: { _localctx = new BooleqneContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); setState(44); if (!(precpred(_ctx, 7))) throw new FailedPredicateException(this, "precpred(_ctx, 7)"); setState(45); _la = _input.LA(1); if (!(_la == EQ || _la == NE)) { _errHandler.recoverInline(this); } else { consume(); } setState(46); expression(8); } break; case 6: { _localctx = new BwandContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); setState(47); if (!(precpred(_ctx, 6))) throw new FailedPredicateException(this, "precpred(_ctx, 6)"); setState(48); match(BWAND); setState(49); expression(7); } break; case 7: { _localctx = new BwxorContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); setState(50); if (!(precpred(_ctx, 5))) throw new FailedPredicateException(this, "precpred(_ctx, 5)"); setState(51); match(BWXOR); setState(52); expression(6); } break; case 8: { _localctx = new BworContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); setState(53); if (!(precpred(_ctx, 4))) throw new FailedPredicateException(this, "precpred(_ctx, 4)"); setState(54); match(BWOR); setState(55); expression(5); } break; case 9: { _localctx = new BoolandContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); setState(56); if (!(precpred(_ctx, 3))) throw new FailedPredicateException(this, "precpred(_ctx, 3)"); setState(57); match(BOOLAND); setState(58); expression(4); } break; case 10: { _localctx = new BoolorContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); setState(59); if (!(precpred(_ctx, 2))) throw new FailedPredicateException(this, "precpred(_ctx, 2)"); setState(60); match(BOOLOR); setState(61); expression(3); } break; case 11: { _localctx = new ConditionalContext(new ExpressionContext(_parentctx, _parentState)); pushNewRecursionContext(_localctx, _startState, RULE_expression); setState(62); if (!(precpred(_ctx, 1))) throw new FailedPredicateException(this, "precpred(_ctx, 1)"); setState(63); match(COND); setState(64); expression(0); setState(65); match(COLON); setState(66); expression(1); } break; } } } setState(72); _errHandler.sync(this); _alt = getInterpreter().adaptivePredict(_input, 5, _ctx); } } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { unrollRecursionContexts(_parentctx); } return _localctx; }
// checks if expr is evaluable public boolean isEvaluable(String expr, CandidateTable cTable) { ExpressionContext ec = getExpressionContext(expr, cubeql.getAliasForTableName(cTable.getBaseTable().getName())); return ec.isEvaluable(cTable); }