本文整理汇总了Java中com.google.javascript.rhino.Node.getSourceOffset方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getSourceOffset方法的具体用法?Java Node.getSourceOffset怎么用?Java Node.getSourceOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.Node
的用法示例。
在下文中一共展示了Node.getSourceOffset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createNewProposals
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void createNewProposals(Node inspectedNode, Map<Integer, List<Proposal>> proposals, ArrayList<Var> internalVars, ArrayList<Var> externalVars) {
Node firstChild = inspectedNode.getFirstChild();
List<Proposal> ret = new ArrayList<>();
Predicate<Var> isClass = v -> v.getNode().getJSType().isConstructor();
internalVars.stream().filter(v->v.getNameNode().getSourceOffset() < firstChild.getSourceOffset())
.filter(isClass)
.map(v->new Proposal(v.getName())).forEach(ret::add);
externalVars.stream()
.filter(isClass)
.map(v->new Proposal(v.getName())).forEach(ret::add);
int sourceOffset = firstChild.getSourceOffset()+1;
if (sourceOffset < 1) {
sourceOffset = inspectedNode.getSourceOffset()+inspectedNode.getLength();
}
proposals.put(sourceOffset,ret);
}
示例2: createBlockProposals
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void createBlockProposals(String code, Node inspectedNode, Map<Integer, List<Proposal>> proposals, ArrayList<Var> internalVars, ArrayList<Var> externalVars) {
List<Proposal> ret = new ArrayList<>();
internalVars.stream().filter(v->v.getNameNode().getSourceOffset() < inspectedNode.getSourceOffset()).map(v->new Proposal(v.getName())).forEach(ret::add);
externalVars.stream().map(v->new Proposal(v.getName())).forEach(ret::add);
proposals.put(inspectedNode.getSourceOffset()+1,ret);
Node lastChild = inspectedNode.getLastChild();
ret = new ArrayList<>();
internalVars.stream().filter(v->v.getNameNode().getSourceOffset() < inspectedNode.getSourceOffset()).map(v->new Proposal(v.getName())).forEach(ret::add);
externalVars.stream().map(v->new Proposal(v.getName())).forEach(ret::add);
int sourceOffset = lastChild != null?lastChild.getSourceOffset()+lastChild.getLength():inspectedNode.getSourceOffset()+inspectedNode.getLength();
if (code.length() > sourceOffset && Character.isWhitespace(code.charAt(sourceOffset)))
++sourceOffset;
if (code.length() > sourceOffset && !proposals.containsKey(sourceOffset)) {
proposals.put(sourceOffset, ret);
}
}
示例3: createExprResultProposals
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void createExprResultProposals(String code, Node inspectedNode, Map<Integer, List<Proposal>> proposals, ArrayList<Var> internalVars, ArrayList<Var> externalVars) {
List<Proposal> ret = new ArrayList<>();
Node lastChild = inspectedNode.getLastChild();
internalVars.stream().filter(v->v.getNameNode().getSourceOffset() < inspectedNode.getSourceOffset()).map(v->new Proposal(v.getName())).forEach(ret::add);
externalVars.stream().map(v->new Proposal(v.getName())).forEach(ret::add);
int sourceOffset = lastChild != null?lastChild.getSourceOffset()+lastChild.getLength():inspectedNode.getSourceOffset()+inspectedNode.getLength();
while (sourceOffset < code.length() && (!Character.isWhitespace(sourceOffset))) {
++sourceOffset;
if (code.charAt(sourceOffset-1) == ';')
break;
}
if (sourceOffset < code.length() && !proposals.containsKey(sourceOffset)) {
proposals.put(sourceOffset, ret);
}
sourceOffset = inspectedNode.getSourceOffset();
if (sourceOffset >= 0) {
proposals.put(sourceOffset, ret);
}
}
示例4: skipWhitespaceBefore
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private int skipWhitespaceBefore(String code, Node currentNode) {
int idx = currentNode.getSourceOffset();
while (idx > 0 && Character.isWhitespace(code.charAt(idx-1))) {
--idx;
}
return idx;
}
示例5: createGetPropProposals
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void createGetPropProposals(String code, Node inspectedNode, Map<Integer, List<Proposal>> proposals, ArrayList<Var> internalVars, ArrayList<Var> externalVars) {
Node firstChild = inspectedNode.getFirstChild();
Optional<JSType> firstChildType = Optional.ofNullable(firstChild.getJSType());
if (firstChildType.isPresent()) {
JSType t = fixNullType(firstChildType.get());
if (t instanceof ObjectType) {
ObjectType ot = ObjectType.cast(t);
ArrayList<String> internalProperties = new ArrayList<>();
ArrayList<String> externalProperties = new ArrayList<>();
Comparator<String> sortProps = (s1,s2)->{
Optional<JSType> propertyType1 = Optional.ofNullable(ot.getPropertyType(s1));
Optional<JSType> propertyType2 = Optional.ofNullable(ot.getPropertyType(s2));
if (propertyType1.isPresent()) {
if (!propertyType2.isPresent())
return -1;
return compareJsType(propertyType1.get(),propertyType2.get());
}
if (propertyType2.isPresent())
return 1;
return 0;
};
ot.getPropertyNames().stream().filter(n -> !n.startsWith("__"))
.forEach(n -> {
if (isIntern(ot.getPropertyDefSite(n))) {
internalProperties.add(n);
} else {
externalProperties.add(n);
}
});
internalProperties.sort(sortProps);
externalProperties.sort(sortProps);
UnaryOperator<String> addFunctionBrackets = s -> {
Optional<JSType> propertyType = Optional.ofNullable(ot.getPropertyType(s));
boolean isFunction = propertyType.map(pt -> pt instanceof FunctionType).orElse(false);
return isFunction ? s + "()" : s;
};
internalProperties.replaceAll(addFunctionBrackets);
externalProperties.replaceAll(addFunctionBrackets);
List<Proposal> ret = new ArrayList<>();
int sourcePosition = firstChild.getSourceOffset();
if (sourcePosition > -1) {
sourcePosition += firstChild.getLength();
while (sourcePosition < code.length() &&
(Character.isWhitespace(code.charAt(sourcePosition)))) {
++sourcePosition;
}
if (sourcePosition < code.length() && '.' == code.charAt(sourcePosition))
++sourcePosition;
}
int sp = sourcePosition;
if (sp > -1) {
if (ot instanceof FunctionType) {
internalVars.stream().filter(v -> v.getNameNode().getSourceOffset() < sp).map(v -> new Proposal(v.getName())).forEach(ret::add);
internalProperties.stream().map(s -> new Proposal(s)).forEach(ret::add);
externalVars.stream().map(v -> new Proposal(v.getName())).forEach(ret::add);
externalProperties.stream().map(s -> new Proposal(s)).forEach(ret::add);
} else {
internalProperties.stream().map(s -> new Proposal(s)).forEach(ret::add);
externalProperties.stream().map(s -> new Proposal(s)).forEach(ret::add);
}
proposals.put(sourcePosition, ret);
}
}
}
}