当前位置: 首页>>代码示例>>Java>>正文


Java CompilationUnitDeclaration类代码示例

本文整理汇总了Java中org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnitDeclaration类的具体用法?Java CompilationUnitDeclaration怎么用?Java CompilationUnitDeclaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CompilationUnitDeclaration类属于org.eclipse.jdt.internal.compiler.ast包,在下文中一共展示了CompilationUnitDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getApplicableExtensionMethodsDefinedInProvider

import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; //导入依赖的package包/类
private static List<MethodBinding> getApplicableExtensionMethodsDefinedInProvider(EclipseNode typeNode, ReferenceBinding extensionMethodProviderBinding,
		TypeBinding receiverType) {
	
	List<MethodBinding> extensionMethods = new ArrayList<MethodBinding>();
	CompilationUnitScope cuScope = ((CompilationUnitDeclaration) typeNode.top().get()).scope;
	for (MethodBinding method : extensionMethodProviderBinding.methods()) {
		if (!method.isStatic()) continue;
		if (!method.isPublic()) continue;
		if (method.parameters == null || method.parameters.length == 0) continue;
		TypeBinding firstArgType = method.parameters[0];
		if (receiverType.isProvablyDistinct(firstArgType) && !receiverType.isCompatibleWith(firstArgType.erasure())) continue;
		TypeBinding[] argumentTypes = Arrays.copyOfRange(method.parameters, 1, method.parameters.length);
		if ((receiverType instanceof ReferenceBinding) && ((ReferenceBinding) receiverType).getExactMethod(method.selector, argumentTypes, cuScope) != null) continue;
		extensionMethods.add(method);
	}
	return extensionMethods;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:18,代码来源:PatchExtensionMethod.java

示例2: handleAnnotation

import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; //导入依赖的package包/类
/**
 * Handles the provided annotation node by first finding a qualifying instance of
 * {@link EclipseAnnotationHandler} and if one exists, calling it with a freshly cooked up
 * instance of {@link AnnotationValues}.
 * 
 * Note that depending on the printASTOnly flag, the {@link lombok.core.PrintAST} annotation
 * will either be silently skipped, or everything that isn't {@code PrintAST} will be skipped.
 * 
 * The HandlerLibrary will attempt to guess if the given annotation node represents a lombok annotation.
 * For example, if {@code lombok.*} is in the import list, then this method will guess that
 * {@code Getter} refers to {@code lombok.Getter}, presuming that {@link lombok.eclipse.handlers.HandleGetter}
 * has been loaded.
 * 
 * @param ast The Compilation Unit that contains the Annotation AST Node.
 * @param annotationNode The Lombok AST Node representing the Annotation AST Node.
 * @param annotation 'node.get()' - convenience parameter.
 */
public void handleAnnotation(CompilationUnitDeclaration ast, EclipseNode annotationNode, org.eclipse.jdt.internal.compiler.ast.Annotation annotation, long priority) {
	TypeResolver resolver = new TypeResolver(annotationNode.getImportList());
	TypeReference rawType = annotation.type;
	if (rawType == null) return;
	
	String fqn = resolver.typeRefToFullyQualifiedName(annotationNode, typeLibrary, toQualifiedName(annotation.type.getTypeName()));
	if (fqn == null) return;
	AnnotationHandlerContainer<?> container = annotationHandlers.get(fqn);
	if (container == null) return;
	if (priority != container.getPriority()) return;
	
	if (!annotationNode.isCompleteParse() && container.deferUntilPostDiet()) {
		if (needsHandling(annotation)) container.preHandle(annotation, annotationNode);
		return;
	}
	
	try {
		if (checkAndSetHandled(annotation)) container.handle(annotation, annotationNode);
	} catch (AnnotationValueDecodeFail fail) {
		fail.owner.setError(fail.getMessage(), fail.idx);
	} catch (Throwable t) {
		error(ast, String.format("Lombok annotation handler %s failed", container.handler.getClass()), t);
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:42,代码来源:HandlerLibrary.java

示例3: getAST

import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; //导入依赖的package包/类
public static EclipseAST getAST(CompilationUnitDeclaration ast, boolean forceRebuild) {
	EclipseAST existing = null;
	if (astCacheField != null) {
		try {
			existing = (EclipseAST) astCacheField.get(ast);
		} catch (Exception e) {
			// existing remains null
		}
	}
	
	if (existing == null) {
		existing = new EclipseAST(ast);
		if (astCacheField != null) try {
			astCacheField.set(ast, existing);
		} catch (Exception ignore) {
		}
	} else {
		existing.rebuild(forceRebuild);
	}
	
	return existing;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:23,代码来源:TransformEclipseAST.java

示例4: buildTree

import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; //导入依赖的package包/类
/** {@inheritDoc} */
@Override protected EclipseNode buildTree(ASTNode node, Kind kind) {
	switch (kind) {
	case COMPILATION_UNIT:
		return buildCompilationUnit((CompilationUnitDeclaration) node);
	case TYPE:
		return buildType((TypeDeclaration) node);
	case FIELD:
		return buildField((FieldDeclaration) node);
	case INITIALIZER:
		return buildInitializer((Initializer) node);
	case METHOD:
		return buildMethod((AbstractMethodDeclaration) node);
	case ARGUMENT:
		return buildLocal((Argument) node, kind);
	case LOCAL:
		return buildLocal((LocalDeclaration) node, kind);
	case STATEMENT:
		return buildStatement((Statement) node);
	case ANNOTATION:
		return buildAnnotation((Annotation) node, false);
	default:
		throw new AssertionError("Did not expect to arrive here: " + kind);
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:26,代码来源:EclipseAST.java

示例5: generateCleanMethod

import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; //导入依赖的package包/类
private MethodDeclaration generateCleanMethod(List<BuilderFieldData> builderFields, EclipseNode builderType, ASTNode source) {
	List<Statement> statements = new ArrayList<Statement>();
	
	for (BuilderFieldData bfd : builderFields) {
		if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) {
			bfd.singularData.getSingularizer().appendCleaningCode(bfd.singularData, builderType, statements);
		}
	}
	
	FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0);
	thisUnclean.receiver = new ThisReference(0, 0);
	statements.add(new Assignment(thisUnclean, new FalseLiteral(0, 0), 0));
	MethodDeclaration decl = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
	decl.selector = CLEAN_METHOD_NAME;
	decl.modifiers = ClassFileConstants.AccPrivate;
	decl.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	decl.returnType = TypeReference.baseTypeReference(TypeIds.T_void, 0);
	decl.statements = statements.toArray(new Statement[0]);
	decl.traverse(new SetGeneratedByVisitor(source), (ClassScope) null);
	return decl;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:22,代码来源:HandleBuilder.java

示例6: generateBuilderMethod

import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; //导入依赖的package包/类
public MethodDeclaration generateBuilderMethod(boolean isStatic, String builderMethodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, ASTNode source) {
	int pS = source.sourceStart, pE = source.sourceEnd;
	long p = (long) pS << 32 | pE;
	
	MethodDeclaration out = new MethodDeclaration(((CompilationUnitDeclaration) type.top().get()).compilationResult);
	out.selector = builderMethodName.toCharArray();
	out.modifiers = ClassFileConstants.AccPublic;
	if (isStatic) out.modifiers |= ClassFileConstants.AccStatic;
	out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
	out.typeParameters = copyTypeParams(typeParams, source);
	AllocationExpression invoke = new AllocationExpression();
	invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
	out.statements = new Statement[] {new ReturnStatement(invoke, pS, pE)};
	
	out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope);
	return out;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:19,代码来源:HandleBuilder.java

示例7: generateClearMethod

import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; //导入依赖的package包/类
private void generateClearMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType) {
	MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
	md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	md.modifiers = ClassFileConstants.AccPublic;
	
	FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
	thisDotField.receiver = new ThisReference(0, 0);
	FieldReference thisDotField2 = new FieldReference(data.getPluralName(), 0L);
	thisDotField2.receiver = new ThisReference(0, 0);
	md.selector = HandlerUtil.buildAccessorName("clear", new String(data.getPluralName())).toCharArray();
	MessageSend clearMsg = new MessageSend();
	clearMsg.receiver = thisDotField2;
	clearMsg.selector = "clear".toCharArray();
	Statement clearStatement = new IfStatement(new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.NOT_EQUAL), clearMsg, 0, 0);
	md.statements = returnStatement != null ? new Statement[] {clearStatement, returnStatement} : new Statement[] {clearStatement};
	md.returnType = returnType;
	injectMethod(builderType, md);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:19,代码来源:EclipseJavaUtilListSetSingularizer.java

示例8: log

import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; //导入依赖的package包/类
public void log(CompilationUnitDeclaration owner, String message, Object... params) {
	if (GLOBAL_DSS_DISABLE_SWITCH) return;
	DebugSnapshot snapshot = new DebugSnapshot(owner, -1, message, params);
	List<DebugSnapshot> list;
	
	synchronized (map) {
		list = map.get(owner);
		if (list == null) {
			list = new ArrayList<DebugSnapshot>();
			map.put(owner, list);
			list.add(snapshot);
		} else if (!list.isEmpty()) {
			list.add(snapshot);
		} else {
			// An empty list is an indicator that we no longer care about that particular CUD.
		}
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:19,代码来源:DebugSnapshotStore.java

示例9: process

import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; //导入依赖的package包/类
@Override
public void process(CompilationUnitDeclaration unit, int unitNumber) {
    mCurrentUnit = lookupEnvironment.unitBeingCompleted = unit;

    parser.getMethodBodies(unit);
    if (unit.scope != null) {
        unit.scope.faultInTypes();
        unit.scope.verifyMethods(lookupEnvironment.methodVerifier());
    }
    unit.resolve();
    unit.analyseCode();

    // This is where we differ from super: DON'T call generateCode().
    // Sadly we can't just set ignoreMethodBodies=true to have the same effect,
    // since that would also skip the analyseCode call, which we DO, want:
    //     unit.generateCode();

    if (options.produceReferenceInfo && unit.scope != null) {
        unit.scope.storeDependencyInfo();
    }
    unit.finalizeProblems();
    unit.compilationResult.totalUnitsKnown = totalUnits;
    lookupEnvironment.unitBeingCompleted = null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:EcjParser.java

示例10: parse

import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; //导入依赖的package包/类
@Nullable
private static Node parse(String code) {
  CompilerOptions options = new CompilerOptions();
  options.complianceLevel = options.sourceLevel = options.targetJDK = ClassFileConstants.JDK1_7;
  options.parseLiteralExpressionsAsConstants = true;
  ProblemReporter problemReporter = new ProblemReporter(
    DefaultErrorHandlingPolicies.exitOnFirstError(), options, new DefaultProblemFactory());
  Parser parser = new Parser(problemReporter, options.parseLiteralExpressionsAsConstants);
  parser.javadocParser.checkDocComment = false;
  EcjTreeConverter converter = new EcjTreeConverter();
  org.eclipse.jdt.internal.compiler.batch.CompilationUnit sourceUnit =
    new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(code.toCharArray(), "unitTest", "UTF-8");
  CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
  CompilationUnitDeclaration unit = parser.parse(sourceUnit, compilationResult);
  if (unit == null) {
    return null;
  }
  converter.visit(code, unit);
  List<? extends Node> nodes = converter.getAll();
  for (lombok.ast.Node node : nodes) {
    if (node instanceof lombok.ast.CompilationUnit) {
      return node;
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:LombokPsiConverterTest.java

示例11: generateBuilderMethod

import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; //导入依赖的package包/类
public MethodDeclaration generateBuilderMethod(String builderMethodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, ASTNode source) {
	int pS = source.sourceStart, pE = source.sourceEnd;
	long p = (long) pS << 32 | pE;
	
	MethodDeclaration out = new MethodDeclaration(
			((CompilationUnitDeclaration) type.top().get()).compilationResult);
	out.selector = builderMethodName.toCharArray();
	out.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic;
	out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
	out.typeParameters = copyTypeParams(typeParams, source);
	AllocationExpression invoke = new AllocationExpression();
	invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
	out.statements = new Statement[] {new ReturnStatement(invoke, pS, pE)};
	
	out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope);
	return out;
}
 
开发者ID:mobmead,项目名称:EasyMPermission,代码行数:19,代码来源:HandleBuilder.java

示例12: convert

import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; //导入依赖的package包/类
public static CompilationUnit convert(
    CompilationUnitDeclaration compilationUnitDeclaration,
    char[] contents,
    int flags,
    Map<String, String> options) {
  DefaultBindingResolver.BindingTables bindingTables = new DefaultBindingResolver.BindingTables();

  CompilationUnit compilationUnit =
      convert(
          compilationUnitDeclaration,
          contents,
          AST.JLS4,
          options,
          true,
          null,
          bindingTables,
          flags,
          new NullProgressMonitor(),
          true);
  compilationUnit.setProperty(
      "compilerBindingsToASTBindings", new HashMap(bindingTables.compilerBindingsToASTBindings));
  return compilationUnit;
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:CodenvyCompilationUnitResolver.java

示例13: buildCompilationUnit

import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; //导入依赖的package包/类
public static CompilationUnitDeclaration buildCompilationUnit(
    ISourceType[] sourceTypes,
    int flags,
    ProblemReporter problemReporter,
    CompilationResult compilationResult) {

  //		long start = System.currentTimeMillis();
  SourceTypeConverter converter = new SourceTypeConverter(flags, problemReporter);
  try {
    return converter.convert(sourceTypes, compilationResult);
  } catch (JavaModelException e) {
    return null;
    /*		} finally {
    			System.out.println("Spent " + (System.currentTimeMillis() - start) + "ms to convert " + ((JavaElement) converter.cu)
    			.toStringWithAncestors());
    */
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:SourceTypeConverter.java

示例14: process

import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; //导入依赖的package包/类
@Override public ASTNode process(Source in, Void irrelevant) throws ConversionProblem {
	CompilerOptions compilerOptions = ecjCompilerOptions();
	Parser parser = new Parser(new ProblemReporter(
			DefaultErrorHandlingPolicies.proceedWithAllProblems(),
			compilerOptions,
			new DefaultProblemFactory()
		), compilerOptions.parseLiteralExpressionsAsConstants);
	parser.javadocParser.checkDocComment = true;
	CompilationUnit sourceUnit = new CompilationUnit(in.getRawInput().toCharArray(), in.getName(), charset.name());
	CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
	CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
	
	if (cud.hasErrors()) {
		throw new ConversionProblem(String.format("Can't read file %s due to parse error: %s", in.getName(), compilationResult.getErrors()[0]));
	}
	
	return cud;
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:19,代码来源:Main.java

示例15: parseWithLombok

import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; //导入依赖的package包/类
@Override
protected ASTNode parseWithLombok(Source source) {
	CompilerOptions compilerOptions = ecjCompilerOptions();
	Parser parser = new Parser(new ProblemReporter(
			DefaultErrorHandlingPolicies.proceedWithAllProblems(),
			compilerOptions,
			new DefaultProblemFactory()
		), compilerOptions.parseLiteralExpressionsAsConstants);
	parser.javadocParser.checkDocComment = true;
	CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
	CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
	CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
	
	if (cud.hasErrors()) return null;
	
	EcjTreeConverter converter = new EcjTreeConverter();
	converter.visit(source.getRawInput(), cud);
	Node lombokized = converter.get();
	
	EcjTreeBuilder builder = new EcjTreeBuilder(source.getRawInput(), source.getName(), ecjCompilerOptions());
	builder.visit(lombokized);
	return builder.get();
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:24,代码来源:EcjTreeConverterType2Test.java


注:本文中的org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。