概述
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void createGetPropProposals(String code, Node inspectedNode, Map> proposals, ArrayList internalVars, ArrayList externalVars) {
Node firstChild = inspectedNode.getFirstChild();
Optional firstChildType = Optional.ofNullable(firstChild.getJSType());
if (firstChildType.isPresent()) {
JSType t = fixNullType(firstChildType.get());
if (t instanceof ObjectType) {
ObjectType ot = ObjectType.cast(t);
ArrayList internalProperties = new ArrayList<>();
ArrayList externalProperties = new ArrayList<>();
Comparator sortProps = (s1,s2)->{
Optional propertyType1 = Optional.ofNullable(ot.getPropertyType(s1));
Optional 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 addFunctionBrackets = s -> {
Optional 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 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);
}
}
}
}
最后
以上就是刻苦眼睛为你收集整理的java getlength_Java Node.getLength方法代码示例的全部内容,希望文章能够帮你解决java getlength_Java Node.getLength方法代码示例所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复