public static boolean parseApplicationHandlerDefinitionSignature(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "parseApplicationHandlerDefinitionSignature")) return false; boolean r; //application handled definition in script only makes sense inside <using terms of> statement if (b.getUserData(IS_PARSING_USING_TERMS_FROM_STATEMENT) != Boolean.TRUE || b.getUserData(PARSING_TELL_COMPOUND_STATEMENT) == Boolean.TRUE) return false; StringHolder parsedCommandName = new StringHolder(); String toldApplicationName = getTargetApplicationName(b); PsiBuilder.Marker m2 = enter_section_(b, l, _COLLAPSE_, "<parse Application Handler Definition"); r = parseDictionaryCommandNameInner(b, l + 1, parsedCommandName, toldApplicationName, true, null); exit_section_(b, l, m2, DICTIONARY_COMMAND_NAME, r, false, null); if (!r) return false; // TODO: 06/12/15 may be try to avoid creating PSI here!.. List<AppleScriptCommand> allCommandsWithName = getAllCommandsWithName(b, parsedCommandName.value, toldApplicationName, false, null); for (AppleScriptCommand command : allCommandsWithName) { r = parseParametersForCommand(b, l + 1, command);//custom parsing here if (r) { break; } } boolean incompleteHandlerCall = !r && allCommandsWithName.size() > 0 && (b.getTokenType() == NLS || b.eof()); return r || incompleteHandlerCall; }
/** * If inside tell (only in a tell?) compound statement - first check it's terms */ public static boolean parseExpression(PsiBuilder b, int l, String dictionaryTermToken, Parser expression) { if (!recursion_guard_(b, l, "parseExpression")) return false; if (!nextTokenIsFast(b, dictionaryTermToken)) return false; boolean r; //check application terms first if (b.getUserData(PARSING_TELL_COMPOUND_STATEMENT) == Boolean.TRUE) { String toldAppName = peekTargetApplicationName(b); if (!StringUtil.isEmpty(toldAppName)) { StringHolder parsedName = new StringHolder(); PsiBuilder.Marker mComName = enter_section_(b, l, _AND_, "<parse Expression>"); r = parseCommandNameForApplication(b, l + 1, parsedName, toldAppName, true); exit_section_(b, l, mComName, null, r, false, null); if (r) return false; if (ParsableScriptSuiteRegistryHelper.isPropertyWithPrefixExist(toldAppName, dictionaryTermToken)) { return false; // PsiBuilder.Marker m = enter_section_(b, l, _AND_, null, "<dictionary constant>"); // r = parseDictionaryConstant(b, l + 1); // exit_section_(b, l, m, r, false, null); // if (r) return false; } } } return expression.parse(b, l + 1); }
private static boolean parseCommandParameterSelector(PsiBuilder b, int l, AppleScriptCommand command, StringHolder parsedParameterSelector) { if (!recursion_guard_(b, l, "parseCommandParameterSelector")) return false; boolean r = false; PsiBuilder.Marker m = enter_section_(b, l, _NONE_, "<parse Command Parameter Selector>");//todo check this _AND_ parsedParameterSelector.value = b.getTokenText() == null ? "" : b.getTokenText(); while (!b.eof() && b.getTokenType() != NLS && b.getTokenType() != COMMENT) { b.advanceLexer(); if (command.getParameterByName(parsedParameterSelector.value) != null) { r = true; break; } parsedParameterSelector.value += " " + b.getTokenText(); } exit_section_(b, l, m, COMMAND_PARAMETER_SELECTOR, r, false, null); return r; }
private static boolean parseStdLibCommandName(PsiBuilder b, int l, StringHolder parsedName) { if (!recursion_guard_(b, l, "parseStdLibCommandName")) return false; boolean r = false; parsedName.value = ""; parsedName.value = b.getTokenText() == null ? "" : b.getTokenText(); PsiBuilder.Marker m = enter_section_(b); boolean commandWithPrefixExists = ParsableScriptSuiteRegistryHelper.isStdCommandWithPrefixExist(parsedName.value); String nextTokenText = parsedName.value; while (b.getTokenText() != null && commandWithPrefixExists) { b.advanceLexer(); //advance lexer in any case nextTokenText += " " + b.getTokenText(); commandWithPrefixExists = ParsableScriptSuiteRegistryHelper.isStdCommandWithPrefixExist(nextTokenText); if (commandWithPrefixExists) { parsedName.value = nextTokenText; } else if (ParsableScriptSuiteRegistryHelper.isStdCommand(parsedName.value)) { r = true; break; } } exit_section_(b, m, null, r); return r; }
public static boolean parseDictionaryCommandName(PsiBuilder b, int l) { boolean r; if (nextTokenIs(b, NLS)) { return false; } StringHolder parsedCommandName = new StringHolder(); String toldApplicationName = getTargetApplicationName(b); boolean areThereUseStatements = b.getUserData(WAS_USE_STATEMENT_USED) == Boolean.TRUE; Set<String> applicationsToImport = null; if (areThereUseStatements) { applicationsToImport = b.getUserData(USED_APPLICATION_NAMES); } PsiBuilder.Marker m = enter_section_(b, l, _COLLAPSE_, "<parse ApplicationDictionary Command Name>"); r = parseDictionaryCommandNameInner(b, l + 1, parsedCommandName, toldApplicationName, areThereUseStatements, applicationsToImport); exit_section_(b, l, m, DICTIONARY_COMMAND_NAME, r, false, null); return r; }
/** * @param b {@link PsiBuilder} * @param l level deep * @param isPluralForm if parsing plural form of a class name * @param checkForUseStatements parser rule for the check if there are use statements in the script * @return true in case rule matches, false otherwise */ public static boolean parseDictionaryClassName(PsiBuilder b, int l, final boolean isPluralForm, @NotNull Parser checkForUseStatements) { if (!recursion_guard_(b, l, "parseDictionaryClassName")) return false; boolean r; final String s = b.getTokenText(); if (s == null || s.length() == 0 || !AppleScriptNames.isIdentifierStart(s.charAt(0))) return false; final String toldApplicationName = getTargetApplicationName(b); final boolean areThereUseStatements = checkForUseStatements.parse(b, l + 1); Set<String> applicationsToImportFrom = null; if (areThereUseStatements) { applicationsToImportFrom = b.getUserData(USED_APPLICATION_NAMES); } final StringHolder currentTokenText = new StringHolder(); currentTokenText.value = s; r = parseDictionaryClassName(b, l + 1, currentTokenText, isPluralForm, toldApplicationName, areThereUseStatements, applicationsToImportFrom); return r; }
/** * @param b {@link PsiBuilder} * @param l level deep * @return true if parsed token(s) is the property of the scripting additions library */ private static boolean tryToParseStdProperty(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "tryToParseStdProperty")) return false; boolean r = false; PsiBuilder.Marker m = enter_section_(b); StringHolder currentTokenText = new StringHolder(); currentTokenText.value = b.getTokenText() == null ? "" : b.getTokenText(); boolean propertyWithPrefixExists = ParsableScriptSuiteRegistryHelper .isStdPropertyWithPrefixExist(currentTokenText.value); String nextTokenText = currentTokenText.value; while (b.getTokenText() != null && propertyWithPrefixExists) { b.advanceLexer(); //advance lexer in any case nextTokenText += " " + b.getTokenText(); propertyWithPrefixExists = ParsableScriptSuiteRegistryHelper.isStdPropertyWithPrefixExist(nextTokenText); if (propertyWithPrefixExists) { currentTokenText.value = nextTokenText; } else if (ParsableScriptSuiteRegistryHelper.isStdProperty(currentTokenText.value)) { r = true; break; } } exit_section_(b, m, null, r); return r; }
/** * @param b {@link PsiBuilder} * @param l level deep * @param applicationName name of the application * @return true if parsed token(s) is the property of the specified application */ private static boolean tryToParseApplicationProperty(PsiBuilder b, int l, @NotNull String applicationName) { if (!recursion_guard_(b, l, "tryToParseApplicationProperty")) return false; boolean r = false; PsiBuilder.Marker m = enter_section_(b); StringHolder currentTokenText = new StringHolder(); currentTokenText.value = b.getTokenText() == null ? "" : b.getTokenText(); boolean propertyWithPrefixExist = ParsableScriptSuiteRegistryHelper.isPropertyWithPrefixExist(applicationName, currentTokenText.value); //find the longest lexeme String nextTokenText = currentTokenText.value; while (b.getTokenText() != null && propertyWithPrefixExist) { b.advanceLexer(); //advance lexer in any case nextTokenText += " " + b.getTokenText(); propertyWithPrefixExist = ParsableScriptSuiteRegistryHelper.isPropertyWithPrefixExist(applicationName, nextTokenText); if (propertyWithPrefixExist) { currentTokenText.value = nextTokenText; } else if (ParsableScriptSuiteRegistryHelper.isApplicationProperty(applicationName, currentTokenText.value)) { r = true; break; } } exit_section_(b, m, null, r); return r; }
/** * Accept and return parameters, having various types. */ public int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short, StringHolder a_string, DoubleHolder a_double ) { System.out.println("SERVER: ***** Test passing multiple parameters"); System.out.println("SERVER: Received:"); System.out.println("SERVER: octet " + an_octet.value); System.out.println("SERVER: short " + a_short.value); System.out.println("SERVER: string " + a_string.value); // Returning incremented values. an_octet.value++; a_short.value++; // OUT parameter, return only. a_double.value = 1; a_string.value += " [return]"; return 452572; }
/** * Test passing multiple parameters in both directions. */ public void testParameters() { System.out.println("***** Pass multiple parameters."); // Holder classes are required to simulate passing // "by reference" (modification is returned back to the server). ByteHolder a_byte = new ByteHolder((byte) 0); ShortHolder a_short = new ShortHolder((short) 3); StringHolder a_string = new StringHolder("[string 4]"); // This is an 'out' parameter; the value must not be passed to servant. DoubleHolder a_double = new DoubleHolder(56.789); int returned = object.passSimple(a_byte, 2, a_short, a_string, a_double); System.out.println(" Returned value " + returned); System.out.println(" Returned parameters: "); System.out.println(" octet " + a_byte.value); System.out.println(" short " + a_short.value); System.out.println(" string '" + a_string.value+"'"); System.out.println(" double " + a_double.value); }
/** * @param b {@link PsiBuilder} * @param l level deep * @param parsedName holder for parsed command name string * @param toldApplicationName name of the application to which all messages are sent by default (it's * terminology is queried first) * @param areThereUseStatements if there are use statements in script * @param applicationsToImportFrom list of application names to use for dictionary terms lookup * @return true if rule matches, false otherwise */ private static boolean parseDictionaryCommandNameInner(PsiBuilder b, int l, @NotNull StringHolder parsedName, @NotNull String toldApplicationName, boolean areThereUseStatements, @Nullable Set<String> applicationsToImportFrom) { if (!recursion_guard_(b, l, "parseDictionaryCommandNameInner")) return false; boolean r; parsedName.value = ""; // TODO: 12/1/2015 could be command with name which does not exist in this target app but in stanradr additions or // CocoaStandard dictionary or in use application dictionary. search all here?? to find the longest dictionary term //if there are use statements, do not check terms from scripting additions library (they should be explicitly imported in this case) boolean checkStdLib = !areThereUseStatements || applicationsToImportFrom == null || applicationsToImportFrom.contains(ApplicationDictionary.SCRIPTING_ADDITIONS_LIBRARY); ParsableScriptSuiteRegistryHelper.ensureKnownApplicationInitialized(toldApplicationName); r = parseCommandNameForApplication(b, l + 1, parsedName, toldApplicationName, checkStdLib); if (r) return true; if (areThereUseStatements) { if (applicationsToImportFrom != null && !applicationsToImportFrom.isEmpty()) { for (String appName : applicationsToImportFrom) { //in case of SCRIPTING_ADDITIONS 'StandardAdditions' app name is added to app names import list ParsableScriptSuiteRegistryHelper.ensureKnownApplicationInitialized(appName); r = parseCommandNameForApplication(b, l + 1, parsedName, appName, false); if (r) return true; } } } if (checkStdLib) { r = parseStdLibCommandName(b, l + 1, parsedName); if (r) return true; } // Could be command from Cocoa Standard library which was not yet checked, because applicationName == ScriptingAdditions. // The could happen when parsing <using terms from scripting additions> stms r = parseCommandNameForApplication(b, l + 1, parsedName, ApplicationDictionary.COCOA_STANDARD_LIBRARY, checkStdLib); return r; }
/** * <<< COMMAND_HANDLER_CALL >>> */ // commandName commandParameters? public static boolean parseCommandHandlerCallExpression(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "parseCommandHandlerCallExpression")) return false; boolean r; if (nextTokenIs(b, NLS)) return false; final String s = b.getTokenText(); if (s == null || s.length() == 0 || !AppleScriptNames.isIdentifierStart(s.charAt(0))) return false; StringHolder parsedCommandName = new StringHolder(); //get current application name to which messages will be sent in the current block String toldApplicationName = getTargetApplicationName(b); //if there are <use statements> present in the script boolean areThereUseStatements = b.getUserData(WAS_USE_STATEMENT_USED) == Boolean.TRUE; Set<String> applicationsToImport = null; if (areThereUseStatements) { //adding list of application names from use statements applicationsToImport = b.getUserData(USED_APPLICATION_NAMES); } PsiBuilder.Marker m2 = enter_section_(b, l, _COLLAPSE_, "<parse Command Handler Call Expression>"); // TODO: 19/12/15 need to parse command name together with parameters for each possible application in order to be // able to parse the longest possible application name ('open for access' std lib vs 'open' from application dict) r = parseDictionaryCommandNameInner(b, l + 1, parsedCommandName, toldApplicationName, areThereUseStatements, applicationsToImport); exit_section_(b, l, m2, DICTIONARY_COMMAND_NAME, r, false, null); if (!r) return false; // TODO: 06/12/15 may be try to avoid creating PSI here!.. List<AppleScriptCommand> allCommandsWithName = getAllCommandsWithName(b, parsedCommandName.value, toldApplicationName, areThereUseStatements, applicationsToImport); for (AppleScriptCommand command : allCommandsWithName) { r = parseParametersForCommand(b, l + 1, command); if (r) { break; } } boolean incompleteHandlerCall = !r && allCommandsWithName.size() > 0 && (b.getTokenType() == NLS || b.eof()); return r || incompleteHandlerCall; }
private static boolean parseParameterForCommand(PsiBuilder b, int l, AppleScriptCommand command, StringHolder parsedParameterSelector, boolean givenForm, boolean first) { if (!recursion_guard_(b, l, "parseParameterForCommand")) return false; boolean r; PsiBuilder.Marker m = enter_section_(b, l, _NONE_, "<parse Parameter For Command>");//todo check here if it works r = parseGivenParameter(b, l + 1, command, parsedParameterSelector, givenForm, first); //todo and here exit and enter once again if it is true?? if (!r) r = parseBooleanParameter(b, l + 1, command, parsedParameterSelector); exit_section_(b, l, m, COMMAND_PARAMETER, r, false, null); return r; }
private static boolean parseBooleanParameter(PsiBuilder b, int l, AppleScriptCommand command, StringHolder parsedParameterSelector) { if (!recursion_guard_(b, l, "parseBooleanParameter")) return false; boolean r; //need to rollback with/without if there is no match PsiBuilder.Marker m = enter_section_(b, l, _NONE_, "<parse Boolean Parameter>"); b.putUserData(PARSING_COMMAND_HANDLER_BOOLEAN_PARAMETER, true); r = consumeToken(b, WITH); if (!r) r = consumeToken(b, WITHOUT); if (!r) r = consumeToken(b, LAND); //for cases like: '...with regexp and all occurrences without case sensitive' r = r && parseCommandParameterSelector(b, l + 1, command, parsedParameterSelector); exit_section_(b, l, m, null, r, false, null); b.putUserData(PARSING_COMMAND_HANDLER_BOOLEAN_PARAMETER, false); return r; }
private static boolean parseGivenParameter(PsiBuilder b, int l, AppleScriptCommand command, StringHolder parsedParameterSelector, boolean givenForm, boolean first) { if (!recursion_guard_(b, l, "parseGivenParameter")) return false; PsiBuilder.Marker m = enter_section_(b, l, _NONE_, "<parse Given Parameter>"); boolean r = !givenForm || first || consumeToken(b, COMMA);//if it is a given form and not the first parameter -> // should be comma r = r && parseCommandParameterSelector(b, l + 1, command, parsedParameterSelector); final CommandParameter parameterDefinition = command.getParameterByName(parsedParameterSelector.value); //todo: parameter value expression could be incorrectly parsed and needed to be rolled backed (__AND__ modifier?) //as in example: mount volume "" in AppleTalk zone "" (in - parsed as range ref form) if (givenForm) r = consumeToken(b, COLON); r = r && parseCommandParameterValue(b, l + 1, parameterDefinition); exit_section_(b, l, m, null, r, false, null); return r; }
public static boolean parseDictionaryConstant(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "parseDictionaryConstant")) return false; boolean r, propertyOrClassExists = false; String toldApplicationName = getTargetApplicationName(b); //TODO: to think how to better handle such situations? // (if there are too many constants defined -> lead to many incorrect parsing errors like // 'end' tell/repeat etc is not detected // dictionary constant could appear only if we are inside dictionary command call boolean insideExpression = (b.getUserData(PARSING_COMMAND_HANDLER_CALL_PARAMETERS) == Boolean.TRUE || b.getUserData(PARSING_COMMAND_ASSIGNMENT_STATEMENT) == Boolean.TRUE) || b.getUserData(PARSING_LITERAL_EXPRESSION) == Boolean.TRUE; if (!ApplicationDictionary.COCOA_STANDARD_LIBRARY.equals(toldApplicationName) && !insideExpression)//only inside // tell statements? return false; final StringHolder currentTokenText = new StringHolder(); currentTokenText.value = ""; boolean areThereUseStatements = b.getUserData(WAS_USE_STATEMENT_USED) == Boolean.TRUE; Set<String> applicationsToImportFrom = null; if (areThereUseStatements) { applicationsToImportFrom = b.getUserData(USED_APPLICATION_NAMES); } r = tryToParseApplicationConstant(b, l + 1, toldApplicationName); if (r) return true; if (areThereUseStatements && insideExpression) { if (applicationsToImportFrom != null && !applicationsToImportFrom.isEmpty()) { for (String appName : applicationsToImportFrom) { r = tryToParseApplicationConstant(b, l + 1, appName); if (r) return true; } } } else { r = tryToParseStdConstant(b, l + 1); if (r) return true; r = tryToParseApplicationConstant(b, l + 1, ApplicationDictionary.COCOA_STANDARD_LIBRARY); if (r) return true; } return false; }
private static boolean tryToParseStdConstant(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "tryToParseStdConstant")) return false; StringHolder currentTokenText = new StringHolder(); currentTokenText.value = b.getTokenText() == null ? "" : b.getTokenText(); boolean r = false, propertyOrClassExists = false, constantWithPrefixExists = ParsableScriptSuiteRegistryHelper .isStdConstantWithPrefixExist(currentTokenText.value); String nextTokenText = currentTokenText.value; PsiBuilder.Marker m = enter_section_(b); while (b.getTokenText() != null && constantWithPrefixExists) { b.advanceLexer(); nextTokenText += " " + b.getTokenText(); constantWithPrefixExists = ParsableScriptSuiteRegistryHelper.isStdConstantWithPrefixExist(nextTokenText); if (constantWithPrefixExists) { currentTokenText.value = nextTokenText; } else if (ParsableScriptSuiteRegistryHelper.isStdConstant(currentTokenText.value)) { r = true; break; } } if (r) { // grammar allows className and propertyName as primaryExpression, so we should match the longest token between // className or propertyName tokens. We check and return false if the property or class with the longer name // exists, as it will be parsed later currentTokenText.value += " " + b.getTokenText(); propertyOrClassExists = ParsableScriptSuiteRegistryHelper .isStdPropertyWithPrefixExist(currentTokenText.value) || ParsableScriptSuiteRegistryHelper .isStdClassWithPrefixExist(currentTokenText.value); } r = r && !propertyOrClassExists; exit_section_(b, m, null, r); return r; }
private static boolean tryToParseApplicationConstant(PsiBuilder b, int l, @NotNull String applicationName) { if (!recursion_guard_(b, l, "tryToParseApplicationConstant")) return false; StringHolder currentTokenText = new StringHolder(); currentTokenText.value = b.getTokenText() == null ? "" : b.getTokenText(); boolean r = false, propertyOrClassExists = false, constantWithPrefixExists = ParsableScriptSuiteRegistryHelper .isConstantWithPrefixExist(applicationName, currentTokenText.value); String nextTokenText = currentTokenText.value; PsiBuilder.Marker m = enter_section_(b); while (b.getTokenText() != null && constantWithPrefixExists) { b.advanceLexer(); nextTokenText += " " + b.getTokenText(); constantWithPrefixExists = ParsableScriptSuiteRegistryHelper .isConstantWithPrefixExist(applicationName, nextTokenText); if (constantWithPrefixExists) { currentTokenText.value = nextTokenText; } else if (ParsableScriptSuiteRegistryHelper.isApplicationConstant(applicationName, currentTokenText.value)) { r = true; break; } } if (r) { // grammar allows className and propertyName as primaryExpression, so we should match the longest token between // className or propertyName tokens. We check and return false if the property or class with the longer name // exists, as it will be parsed later propertyOrClassExists = ParsableScriptSuiteRegistryHelper .isPropertyWithPrefixExist(applicationName, currentTokenText.value) || ParsableScriptSuiteRegistryHelper .isClassWithPrefixExist(applicationName, currentTokenText.value); if (propertyOrClassExists) { currentTokenText.value += " " + b.getTokenText(); propertyOrClassExists = ParsableScriptSuiteRegistryHelper .isPropertyWithPrefixExist(applicationName, currentTokenText.value) || ParsableScriptSuiteRegistryHelper .isClassWithPrefixExist(applicationName, currentTokenText.value); } } r = r && !propertyOrClassExists; exit_section_(b, m, null, r); return r; }
/** {@inheritDoc} */ public String get_string() throws TypeMismatch { try { return ((StringHolder) holder).value; } catch (ClassCastException cex) { TypeMismatch m = new TypeMismatch(); m.initCause(cex); throw m; } }
/** {@inheritDoc} */ public String extract_string() throws BAD_OPERATION { check(TCKind._tk_string); return ((StringHolder) has).value; }
/** * @param b {@link PsiBuilder} * @param l level deep * @param parsedName holder for parsed term string * @param applicationName name of the application, which dictionary terms will be queried * @param checkStdLib whether to check in scripting additions library if no terms were found in this application * @return true if command name was parsed */ private static boolean parseCommandNameForApplication(PsiBuilder b, int l, StringHolder parsedName, @NotNull String applicationName, boolean checkStdLib) { if (!recursion_guard_(b, l, "parseCommandNameForApplication")) return false; boolean r = false; parsedName.value = ""; PsiBuilder.Marker m = enter_section_(b); parsedName.value = b.getTokenText() == null ? "" : b.getTokenText(); boolean commandWithPrefixExists = ParsableScriptSuiteRegistryHelper.isCommandWithPrefixExist(applicationName, parsedName.value); String nextTokenText = parsedName.value; while (b.getTokenText() != null && commandWithPrefixExists) { b.advanceLexer(); //advance lexer to the next token nextTokenText += " " + b.getTokenText(); commandWithPrefixExists = ParsableScriptSuiteRegistryHelper .isCommandWithPrefixExist(applicationName, nextTokenText); if (commandWithPrefixExists) { //if command with prefix exists, append token text parsedName.value = nextTokenText; } else if (ParsableScriptSuiteRegistryHelper.isApplicationCommand(applicationName, parsedName.value)) { //if there is std command with longer prefix exists do not parse it here r = !checkStdLib || !ParsableScriptSuiteRegistryHelper.isStdCommandWithPrefixExist(nextTokenText); // if there is class name with longer prefix exists !! AND !! next is NLS token => do not this as command name // boolean longerClassNameExists = ParsableScriptSuiteRegistryHelper // .isClassWithPrefixExist(applicationName, nextTokenText); // if (r && longerClassNameExists) { // while (b.getTokenType() != NLS) { // b.advanceLexer(); // nextTokenText += " " + b.getTokenText(); // } // r = ParsableScriptSuiteRegistryHelper.isApplicationClass(applicationName, nextTokenText); // } r = r && !ParsableScriptSuiteRegistryHelper.isClassWithPrefixExist(applicationName, nextTokenText); break; } } exit_section_(b, m, null, r); return r; }
/** * @param b {@link PsiBuilder} * @param l Level deep * @param currentTokenText Text string of the token being parsed * @param isPluralForm Whether we are parsing class name in plural form * @param toldApplicationName The name of the application (which is the target of all messages in current block) * dictionary of which will be queried first of all when searching for class names * @param areThereUseStatements Whether there are use statements used in the script, in which case standard library * Should be specified explicitly * @param applicationsToImportFrom Set list of the applications (if specified) attached to script from use statements * @return true if class name parsed */ private static boolean parseDictionaryClassName(PsiBuilder b, int l, StringHolder currentTokenText, final boolean isPluralForm, @NotNull String toldApplicationName, final boolean areThereUseStatements, final @Nullable Set<String> applicationsToImportFrom) { boolean r, propertyExists = false; PsiBuilder.Marker m = enter_section_(b); r = parseApplicationClassName(b, l + 1, currentTokenText, isPluralForm, toldApplicationName); if (r) { // grammar allows className and propertyName as primaryExpression, so we should match the longest token between // className or propertyName tokens. Here we check and return false if the property with the longer name exists, // as it will be parsed later currentTokenText.value += " " + b.getTokenText(); propertyExists = ParsableScriptSuiteRegistryHelper .isPropertyWithPrefixExist(toldApplicationName, currentTokenText.value); } exit_section_(b, m, null, r && !propertyExists); if (propertyExists) return false; if (r) return true; if (areThereUseStatements) { // if there are <use> statements in script (with importing dictionary terms condition), checking dictionary for // each application if (applicationsToImportFrom != null && !applicationsToImportFrom.isEmpty()) { for (String appName : applicationsToImportFrom) { m = enter_section_(b); r = parseApplicationClassName(b, l + 1, currentTokenText, isPluralForm, appName); if (r) { // check here as well for the property with longer name currentTokenText.value += " " + b.getTokenText(); propertyExists = ParsableScriptSuiteRegistryHelper .isPropertyWithPrefixExist(appName, currentTokenText.value); } exit_section_(b, m, null, r && !propertyExists); if (propertyExists) return false; if (r) return true; } } } else { m = enter_section_(b); r = parseStdClassName(b, l + 1, currentTokenText, isPluralForm); exit_section_(b, m, null, r); if (r) return true; } // It looks like not always CocoaStandard classes(and other terms) could be presented in applications terminology, // so in this case we check CocoaStandard here m = enter_section_(b); r = parseApplicationClassName(b, l + 1, currentTokenText, isPluralForm, ApplicationDictionary.COCOA_STANDARD_LIBRARY); if (r) { // grammar allows className and propertyName as primaryExpression, so we should match the longest token between // className or propertyName tokens. Here we check and return false if the property with the longer name exists, // as it will be parsed later currentTokenText.value += " " + b.getTokenText(); propertyExists = ParsableScriptSuiteRegistryHelper .isPropertyWithPrefixExist(toldApplicationName, currentTokenText.value); } exit_section_(b, m, null, r && !propertyExists); return !propertyExists && r; }
/** * Passes various parameters in both directions. The parameters that * shoud also return the values are wrapped into holders. */ public int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short, StringHolder a_string, DoubleHolder a_double ) { InputStream in = null; try { // Get the stream where the parameters must be written: OutputStream out = _request("passSimple", true); // Write the parameters. out.write_octet(an_octet.value); out.write_long(a_long); out.write_short(a_short.value); out.write_string(a_string.value); // Invoke the method. in = _invoke(out); // Read the returned values. int result = in.read_long(); // Read the inout and out parameters. an_octet.value = in.read_octet(); a_short.value = in.read_short(); a_string.value = in.read_string(); a_double.value = in.read_double(); return result; } catch (ApplicationException ex) { // Handle excepion on remote side. in = ex.getInputStream(); throw new MARSHAL(ex.getId()); } catch (RemarshalException _rm) { // Handle instruction to resend the parameters. return passSimple(an_octet, a_long, a_short, a_string, a_double); } finally { _releaseReply(in); } }
/** * Passes various parameters in both directions. * The parameters that must return the value are wrapped in holders. */ int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short, StringHolder a_string, DoubleHolder a_double );