/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.groovy.scripts.internal;
import org.codehaus.groovy.GroovyBugError;
import org.codehaus.groovy.ast.*;
import org.codehaus.groovy.ast.expr.*;
import org.codehaus.groovy.ast.stmt.BlockStatement;
import org.codehaus.groovy.ast.stmt.CatchStatement;
import org.codehaus.groovy.ast.stmt.ForStatement;
import org.codehaus.groovy.ast.stmt.Statement;
import org.codehaus.groovy.control.ClassNodeResolver;
import org.codehaus.groovy.control.CompilationUnit;
import org.codehaus.groovy.control.ResolveVisitor;
import org.codehaus.groovy.control.SourceUnit;
import org.codehaus.groovy.syntax.Types;
import org.codehaus.groovy.transform.trait.Traits;
import org.objectweb.asm.Opcodes;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Modifier;
import java.util.*;
/**
* A Gradle version of the Groovy {@link ResolveVisitor} that takes some shortcuts to make resolving faster. It tries to be as close as the original implementation, while having a significant impact
* on performance, by taking advantage of knowlegdge of Gradle default imports, including a mapping from simple name to fully qualified class name. It also avoids unnecessary lookups of classnodes.
*
* @since 2.12
*/
public class GradleResolveVisitor extends ResolveVisitor {
private ClassNode currentClass;
// note: BigInteger and BigDecimal are also imported by default
public static final String[] DEFAULT_IMPORTS = {"java.lang.", "java.io.", "java.net.", "java.util.", "groovy.lang.", "groovy.util."};
private final Map<String, List<String>> simpleNameToFQN;
private final String[] gradlePublicPackages;
private CompilationUnit compilationUnit;
private SourceUnit source;
private VariableScope currentScope;
private boolean isTopLevelProperty = true;
private boolean inPropertyExpression;
private boolean inClosure;
private Map<String, GenericsType> genericParameterNames = new HashMap<String, GenericsType>();
private Set<FieldNode> fieldTypesChecked = new HashSet<FieldNode>();
private boolean checkingVariableTypeInDeclaration;
private ImportNode currImportNode;
private MethodNode currentMethod;
private ClassNodeResolver classNodeResolver;
/**
* A ConstructedNestedClass consists of an outer class and a name part, denoting a nested class with an unknown number of levels down. This allows resolve tests to skip this node for further inner
* class searches and combinations with imports, since the outer class we know is already resolved.
*/
private static class ConstructedNestedClass extends ClassNode {
private final ClassNode knownEnclosingType;
public ConstructedNestedClass(ClassNode outer, String inner) {
super(outer.getName() + "$" + replacePoints(inner), Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
this.knownEnclosingType = outer;
this.isPrimaryNode = false;
}
public boolean hasPackageName() {
if (redirect() != this) {
return super.hasPackageName();
}
return knownEnclosingType.hasPackageName();
}
public String setName(String name) {
if (redirect() != this) {
return super.setName(name);
} else {
throw new GroovyBugError("ConstructedNestedClass#setName should not be called");
}
}
}
private static String replacePoints(String name) {
return name.replace('.', '$');
}
/**
* we use ConstructedClassWithPackage to limit the resolving the compiler does when combining package names and class names. The idea that if we use a package, then we do not want to replace the
* '.' with a '$' for the package part, only for the class name part. There is also the case of a imported class, so this logic can't be done in these cases...
*/
private static class ConstructedClassWithPackage extends ClassNode {
private final String prefix;
private String className;
public ConstructedClassWithPackage(String pkg, String name) {
super(pkg + name, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
isPrimaryNode = false;
this.prefix = pkg;
this.className = name;
}
public String getName() {
if (redirect() != this) {
return super.getName();
}
return prefix + className;
}
public boolean hasPackageName() {
if (redirect() != this) {
return super.hasPackageName();
}
return getName().indexOf('.') != -1;
}
public String setName(String name) {
if (redirect() != this) {
return super.setName(name);
} else {
throw new GroovyBugError("ConstructedClassWithPackage#setName should not be called");
}
}
}
/**
* we use LowerCaseClass to limit the resolving the compiler does for vanilla names starting with a lower case letter. The idea that if we use a vanilla name with a lower case letter, that this is
* in most cases no class. If it is a class the class needs to be imported explicitly. The effect is that in an expression like "def foo = bar" we do not have to use a loadClass call to check the
* name foo and bar for being classes. Instead we will ask the module for an alias for this name which is much faster.
*/
private static class LowerCaseClass extends ClassNode {
private final String className;
public LowerCaseClass(String name) {
super(name, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
isPrimaryNode = false;
this.className = name;
}
public String getName() {
if (redirect() != this) {
return super.getName();
}
return className;
}
public boolean hasPackageName() {
if (redirect() != this) {
return super.hasPackageName();
}
return false;
}
public String setName(String name) {
if (redirect() != this) {
return super.setName(name);
} else {
throw new GroovyBugError("LowerCaseClass#setName should not be called");
}
}
}
public GradleResolveVisitor(CompilationUnit cu, String[] exportedPackages, Map<String, List<String>> simpleNameToFQN) {
super(cu);
compilationUnit = cu;
this.classNodeResolver = new ClassNodeResolver();
this.simpleNameToFQN = simpleNameToFQN;
this.gradlePublicPackages = exportedPackages;
}
public void startResolving(ClassNode node, SourceUnit source) {
this.source = source;
visitClass(node);
}
protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) {
VariableScope oldScope = currentScope;
currentScope = node.getVariableScope();
Map<String, GenericsType> oldPNames = genericParameterNames;
genericParameterNames = new HashMap<String, GenericsType>(genericParameterNames);
resolveGenericsHeader(node.getGenericsTypes());
Parameter[] paras = node.getParameters();
for
没有合适的资源?快使用搜索试试~ 我知道了~
gradle-3.1-src.zip
共2000个文件
java:6122个
groovy:3233个
gradle:730个
需积分: 9 11 下载量 187 浏览量
2016-09-30
22:45:04
上传
评论
收藏 17.52MB ZIP 举报
温馨提示
官网下载不成功的,可以直接在这里下载。 官网原下载地址:https://services.gradle.org/distributions/
资源推荐
资源详情
资源评论
收起资源包目录
gradle-3.1-src.zip (2000个子文件)
gradle_cunit_main.c 1KB
suite_operators.c 395B
main.c 348B
src.c 322B
platform-windows.c 229B
platform-mac.c 188B
platform-linux.c 186B
test_minus.c 165B
test_plus.c 161B
lib.c 128B
lib.c 126B
plus.c 115B
main.c 115B
hello.c 92B
hello.c 92B
minus.c 70B
main.c 63B
main.c 59B
unused.c 42B
accents.c 14B
main.cpp 615B
main.cpp 615B
hello.cpp 528B
src.cpp 325B
util.cpp 211B
test_minus.cpp 211B
test_plus.cpp 208B
hello.cpp 190B
hello.cpp 190B
main.cpp 189B
test_main.cpp 153B
hello.cpp 122B
plus.cpp 115B
hello.cpp 111B
hello.cpp 101B
hello.cpp 101B
hello.cpp 100B
main.cpp 92B
main.cpp 92B
hello.cpp 83B
main.cpp 78B
minus.cpp 70B
main.cpp 63B
main.cpp 59B
main.cpp 59B
main.cpp 59B
main.cpp 59B
main.cpp 59B
bootstrap.min.css 104KB
javadoc.css 14KB
base.css 6KB
tree.css 5KB
base-style.css 3KB
release-notes.css 3KB
print.css 2KB
userguide.css 2KB
dsl.css 2KB
docs.css 2KB
style.css 2KB
style.css 2KB
style.css 1KB
scenario-report-style.css 868B
style.css 50B
style.css 36B
main.css 0B
main.css 0B
main.css 0B
main.css 0B
main.css 0B
main.css 0B
main.css 0B
main.css 0B
gtest-param-util-generated.h 188KB
gtest-type-util.h 181KB
gtest.h 86KB
gtest-param-test.h 74KB
gtest-port.h 67KB
gtest-internal.h 43KB
TestDB.h 40KB
gtest-printers.h 31KB
gtest-tuple.h 28KB
gtest-param-util.h 24KB
TestRun.h 22KB
CUnit.h 19KB
gtest_pred_impl.h 15KB
gtest-death-test-internal.h 13KB
gtest-death-test.h 11KB
gtest-typed-test.h 10KB
gtest-spi.h 10KB
gtest-filepath.h 9KB
gtest-message.h 9KB
gtest-linked_ptr.h 8KB
CUError.h 8KB
gtest-string.h 7KB
gtest-test-part.h 6KB
Util.h 6KB
MyMem.h 4KB
Basic.h 4KB
Automated.h 3KB
gtest_prod.h 2KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
前端小开发仔
- 粉丝: 70
- 资源: 122
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功