private void handleVariableReference(VariableReference ref) { final String varName = ref.getName(); if (varName.length() != 0) { if (varName.charAt(0) == '$') { requestor.addPosition(ref.sourceStart(), ref.sourceEnd(), HL_GLOBAL_VARIABLE); } else if (varName.charAt(0) == '@') { if (varName.length() > 2 && varName.charAt(1) == '@') { requestor.addPosition(ref.sourceStart(), ref.sourceEnd(), HL_CLASS_VARIABLE); } else { requestor.addPosition(ref.sourceStart(), ref.sourceEnd(), HL_INSTANCE_VARIABLE); } } else { requestor.addPosition(ref.sourceStart(), ref.sourceEnd(), HL_LOCAL_VARIABLE); } } }
@Override protected JSMethod createMethod(FunctionStatement node) { JSMethod method = super.createMethod(node); if (method != null && method.isDeprecated()) { if (node.getName() != null) { requestor.addPosition( node.getName().sourceStart(), node.getName().sourceEnd(), JS_DEPRECATED); } else if (node.getParent() instanceof BinaryOperation && ((BinaryOperation) node.getParent()).getLeftExpression() instanceof PropertyExpression) { PropertyExpression exp = (PropertyExpression) ((BinaryOperation) node.getParent()).getLeftExpression(); requestor.addPosition( exp.getProperty().sourceStart(), exp.getProperty().sourceEnd(), JS_DEPRECATED); } else if (node.getParent() instanceof PropertyInitializer) { Expression name = ((PropertyInitializer) node.getParent()).getName(); requestor.addPosition(name.sourceStart(), name.sourceEnd(), JS_DEPRECATED); } } return method; }
private void handleEvaluatableExpression(ASTNode node) { int start = node.sourceStart(); int end = node.sourceEnd(); if (content[start] == '#' && content[start + 1] == '{') { if (content[end - 1] == '\r') { // FIXME JRuby bug --end; } if (content[end - 1] == '}') { requestor.addPosition(start, start + 2, HL_EVAL_EXPR); requestor.addPosition(end - 1, end - 0, HL_EVAL_EXPR); } } }
@Override public boolean visitGeneral(ASTNode node) throws Exception { if (!ACTIVE) { return true; } if (node instanceof RubyRegexpExpression || node instanceof RubyDRegexpExpression) { handleRegexp(node); } else if (node instanceof RubySymbolReference) { requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_SYMBOL); } else if (node instanceof VariableReference) { handleVariableReference((VariableReference) node); } else if (node instanceof RubyDVarExpression) { requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_LOCAL_VARIABLE); } else if (node instanceof RubyDAssgnExpression) { ASTNode var = ((RubyDAssgnExpression) node).getLeft(); requestor.addPosition(var.sourceStart(), var.sourceEnd(), HL_LOCAL_VARIABLE); } else if (node instanceof StringLiteral) { if (isStringLiteralNeeded(node)) { requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_STRING); } } else if (node instanceof NumericLiteral || node instanceof FloatNumericLiteral || node instanceof BigNumericLiteral) { requestor.addPosition(node.sourceStart(), node.sourceEnd(), HL_NUMBER); } else if (node instanceof RubyEvaluatableStringExpression) { handleEvaluatableExpression(node); } else if (node instanceof CallExpression) { final CallExpression call = (CallExpression) node; if (!(RubySyntaxUtils.isRubyOperator(call.getName()) || call.getReceiver() == null && RubyCodeScanner.isPseudoKeyword(call.getName()))) { final SimpleReference callName = call.getCallName(); if (callName.sourceStart() >= 0 && callName.sourceEnd() > callName.sourceStart()) { requestor.addPosition(callName.sourceStart(), callName.sourceEnd(), HL_DEFAULT); } } } else if (node instanceof Declaration) { final Declaration declaration = (Declaration) node; requestor.addPosition(declaration.getNameStart(), declaration.getNameEnd(), HL_DEFAULT); } else if (node instanceof RubyConstantDeclaration) { final RubyConstantDeclaration declaration = (RubyConstantDeclaration) node; final SimpleReference name = declaration.getName(); requestor.addPosition(name.sourceStart(), name.sourceEnd(), HL_CONST); } stack.push(node); return true; }
private void handleRegexp(ASTNode node) { int start = node.sourceStart(); int end = node.sourceEnd(); if (start >= 1 && content[start - 1] == '/') { --start; if (end < content.length && content[end] == '/') { ++end; } while (end < content.length && RubySyntaxUtils.isValidRegexpModifier(content[end])) { ++end; } } else if (start >= 3 && content[start - 3] == '%' && content[start - 2] == 'r') { char terminator = RubySyntaxUtils.getPercentStringTerminator(content[start - 1]); if (terminator != 0 && end < content.length && content[end] == terminator) { start -= 3; ++end; while (end < content.length && RubySyntaxUtils.isValidRegexpModifier(content[end])) { ++end; } } } requestor.addPosition(start, end, HL_REGEXP); }
public void reportProblem(IProblemIdentifier identifier, String message, int start, int end) { if (DEPRECATION.contains(identifier)) { requestor.addPosition(start, end, JS_DEPRECATED); } }