• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Parser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: parse

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的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


示例2: process

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的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


示例3: parseWithLombok

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的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


示例4: parseWithTargetCompiler

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
@Override
protected ASTNode parseWithTargetCompiler(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;
	
	return cud;
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:18,代码来源:EcjTreeConverterType2Test.java


示例5: parseWithTargetCompiler

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
@Override
protected ASTNode parseWithTargetCompiler(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;
	return cud;
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:17,代码来源:EcjTreeBuilderTest.java


示例6: parseWithTargetCompiler

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
protected Node parseWithTargetCompiler(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);
	return converter.get();
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:19,代码来源:EcjTreeConverterType1Test.java


示例7: CompletionUnitStructureRequestor

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
public CompletionUnitStructureRequestor(
		ICompilationUnit unit,
		CompilationUnitElementInfo unitInfo,
		Parser parser,
		ASTNode assistNode,
		Map bindingCache,
		Map elementCache,
		Map elementWithProblemCache,
		Map newElements) {
	super(unit, unitInfo, newElements);
	this.parser = parser;
	this.assistNode = assistNode;
	this.bindingCache = bindingCache;
	this.elementCache = elementCache;
	this.elementWithProblemCache = elementWithProblemCache;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:CompletionUnitStructureRequestor.java


示例8: installStubs

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
public void installStubs(final Resource resource) {
  boolean _isInfoFile = this.isInfoFile(resource);
  if (_isInfoFile) {
    return;
  }
  final CompilationUnit compilationUnit = this.getCompilationUnit(resource);
  IErrorHandlingPolicy _proceedWithAllProblems = DefaultErrorHandlingPolicies.proceedWithAllProblems();
  CompilerOptions _compilerOptions = this.getCompilerOptions(resource);
  DefaultProblemFactory _defaultProblemFactory = new DefaultProblemFactory();
  ProblemReporter _problemReporter = new ProblemReporter(_proceedWithAllProblems, _compilerOptions, _defaultProblemFactory);
  final Parser parser = new Parser(_problemReporter, true);
  final CompilationResult compilationResult = new CompilationResult(compilationUnit, 0, 1, (-1));
  final CompilationUnitDeclaration result = parser.dietParse(compilationUnit, compilationResult);
  if ((result.types != null)) {
    for (final TypeDeclaration type : result.types) {
      {
        ImportReference _currentPackage = result.currentPackage;
        char[][] _importName = null;
        if (_currentPackage!=null) {
          _importName=_currentPackage.getImportName();
        }
        List<String> _map = null;
        if (((List<char[]>)Conversions.doWrapArray(_importName))!=null) {
          final Function1<char[], String> _function = (char[] it) -> {
            return String.valueOf(it);
          };
          _map=ListExtensions.<char[], String>map(((List<char[]>)Conversions.doWrapArray(_importName)), _function);
        }
        String _join = null;
        if (_map!=null) {
          _join=IterableExtensions.join(_map, ".");
        }
        final String packageName = _join;
        final JvmDeclaredType jvmType = this.createType(type, packageName);
        resource.getContents().add(jvmType);
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:40,代码来源:JavaDerivedStateComputer.java


示例9: transform

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
/**
 * This method is called immediately after Eclipse finishes building a CompilationUnitDeclaration, which is
 * the top-level AST node when Eclipse parses a source file. The signature is 'magic' - you should not
 * change it!
 * 
 * Eclipse's parsers often operate in diet mode, which means many parts of the AST have been left blank.
 * Be ready to deal with just about anything being null, such as the Statement[] arrays of the Method AST nodes.
 * 
 * @param parser The Eclipse parser object that generated the AST. Not actually used; mostly there to satisfy parameter rules for lombok.patcher scripts.
 * @param ast The AST node belonging to the compilation unit (java speak for a single source file).
 */
public static void transform(Parser parser, CompilationUnitDeclaration ast) {
	if (disableLombok) return;
	
	if (Symbols.hasSymbol("lombok.disable")) return;
	
	// Do NOT abort if (ast.bits & ASTNode.HasAllMethodBodies) != 0 - that doesn't work.
	
	try {
		DebugSnapshotStore.INSTANCE.snapshot(ast, "transform entry");
		long histoToken = lombokTracker == null ? 0L : lombokTracker.start();
		EclipseAST existing = getAST(ast, false);
		new TransformEclipseAST(existing).go();
		if (lombokTracker != null) lombokTracker.end(histoToken);
		DebugSnapshotStore.INSTANCE.snapshot(ast, "transform exit");
	} catch (Throwable t) {
		DebugSnapshotStore.INSTANCE.snapshot(ast, "transform error: %s", t.getClass().getSimpleName());
		try {
			String message = "Lombok can't parse this source: " + t.toString();
			
			EclipseAST.addProblemToCompilationResult(ast.getFileName(), ast.compilationResult, false, message, 0, 0);
			t.printStackTrace();
		} catch (Throwable t2) {
			try {
				error(ast, "Can't create an error in the problems dialog while adding: " + t.toString(), t2);
			} catch (Throwable t3) {
				//This seems risky to just silently turn off lombok, but if we get this far, something pretty
				//drastic went wrong. For example, the eclipse help system's JSP compiler will trigger a lombok call,
				//but due to class loader shenanigans we'll actually get here due to a cascade of
				//ClassNotFoundErrors. This is the right action for the help system (no lombok needed for that JSP compiler,
				//of course). 'disableLombok' is static, but each context classloader (e.g. each eclipse OSGi plugin) has
				//it's own edition of this class, so this won't turn off lombok everywhere.
				disableLombok = true;
			}
		}
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:48,代码来源:TransformEclipseAST.java


示例10: parseMemberValue

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
private Expression parseMemberValue(char[] memberValue) {
  // memberValue must not be null
  if (this.parser == null) {
    this.parser = new Parser(this.problemReporter, true);
  }
  return this.parser.parseMemberValue(memberValue, 0, memberValue.length, this.unit);
}
 
开发者ID:eclipse,项目名称:che,代码行数:8,代码来源:SourceTypeConverter.java


示例11: parseWithEcj

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
private void parseWithEcj(Source source) {
	if (VERBOSE) {
		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);
		parser.parse(sourceUnit, compilationResult);
	}
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:15,代码来源:PerformanceTest.java


示例12: resolveDocument

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
public void resolveDocument() {
	try {
		IPath path = new Path(this.document.getPath());
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0));
		JavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
		JavaProject javaProject = (JavaProject) model.getJavaProject(project);

		this.options = new CompilerOptions(javaProject.getOptions(true));
		ProblemReporter problemReporter =
				new ProblemReporter(
						DefaultErrorHandlingPolicies.proceedWithAllProblems(),
						this.options,
						new DefaultProblemFactory());

		// Re-parse using normal parser, IndexingParser swallows several nodes, see comment above class.
		this.basicParser = new Parser(problemReporter, false);
		this.basicParser.reportOnlyOneSyntaxError = true;
		this.basicParser.scanner.taskTags = null;
		this.cud = this.basicParser.parse(this.compilationUnit, new CompilationResult(this.compilationUnit, 0, 0, this.options.maxProblemsPerUnit));

		// Use a non model name environment to avoid locks, monitors and such.
		INameEnvironment nameEnvironment = new JavaSearchNameEnvironment(javaProject, JavaModelManager.getJavaModelManager().getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY, true/*add primary WCs*/));
		this.lookupEnvironment = new LookupEnvironment(this, this.options, problemReporter, nameEnvironment);
		reduceParseTree(this.cud);
		this.lookupEnvironment.buildTypeBindings(this.cud, null);
		this.lookupEnvironment.completeTypeBindings();
		this.cud.scope.faultInTypes();
		this.cud.resolve();
	} catch (Exception e) {
		if (JobManager.VERBOSE) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:35,代码来源:SourceIndexer.java


示例13: getParser

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
private Parser getParser() {
	if (this.parser == null) {
		this.compilerOptions = new CompilerOptions(JavaCore.getOptions());
		ProblemReporter problemReporter =
			new ProblemReporter(
				DefaultErrorHandlingPolicies.proceedWithAllProblems(),
				this.compilerOptions,
				new DefaultProblemFactory());
		this.parser = new Parser(problemReporter, true);
	}
	return this.parser;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:13,代码来源:BasicSearchEngine.java


示例14: getNtermIndex

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
private int getNtermIndex(int start, int sym, int buffer_position) {
	int highest_symbol = sym - NT_OFFSET,
		tok = this.lexStream.kind(this.buffer[buffer_position]);
	this.lexStream.reset(this.buffer[buffer_position + 1]);

	//
	// Initialize stack index of temp_stack and initialize maximum
	// position of state stack that is still useful.
	//
	this.tempStackTop = 0;
	this.tempStack[this.tempStackTop] = start;

	int act = Parser.ntAction(start, highest_symbol);
	if (act > NUM_RULES) { // goto action?
		this.tempStack[this.tempStackTop + 1] = act;
		act = Parser.tAction(act, tok);
	}

	while(act <= NUM_RULES) {
		//
		// Process all goto-reduce actions following reduction,
		// until a goto action is computed ...
		//
		do {
			this.tempStackTop -= (Parser.rhs[act]-1);
			if (this.tempStackTop < 0)
				return Parser.non_terminal_index[highest_symbol];
			if (this.tempStackTop == 0)
				highest_symbol = Parser.lhs[act];
			act = Parser.ntAction(this.tempStack[this.tempStackTop], Parser.lhs[act]);
		} while(act <= NUM_RULES);
		this.tempStack[this.tempStackTop + 1] = act;
		act = Parser.tAction(act, tok);
	}

	return Parser.non_terminal_index[highest_symbol];
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:38,代码来源:DiagnoseParser.java


示例15: getNTermTemplate

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
private int[] getNTermTemplate(int sym) {
	int templateIndex = Parser.recovery_templates_index[sym];
   	if(templateIndex > 0) {
   		int[] result = new int[Parser.recovery_templates.length];
   		int count = 0;
   		for(int j = templateIndex; Parser.recovery_templates[j] != 0; j++) {
   			result[count++] = Parser.recovery_templates[j];
   		}
   		System.arraycopy(result, 0, result = new int[count], 0, count);
   		return result;
   	} else {
       	return null;
   	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:15,代码来源:DiagnoseParser.java


示例16: transform

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
/**
 * This method is called immediately after Eclipse finishes building a CompilationUnitDeclaration, which is
 * the top-level AST node when Eclipse parses a source file. The signature is 'magic' - you should not
 * change it!
 * 
 * Eclipse's parsers often operate in diet mode, which means many parts of the AST have been left blank.
 * Be ready to deal with just about anything being null, such as the Statement[] arrays of the Method AST nodes.
 * 
 * @param parser The Eclipse parser object that generated the AST. Not actually used; mostly there to satisfy parameter rules for lombok.patcher scripts.
 * @param ast The AST node belonging to the compilation unit (java speak for a single source file).
 */
public static void transform(Parser parser, CompilationUnitDeclaration ast) {
	if (disableLombok) return;
	
	if (Symbols.hasSymbol("lombok.disable")) return;
	
	// Do NOT abort if (ast.bits & ASTNode.HasAllMethodBodies) != 0 - that doesn't work.
	
	try {
		DebugSnapshotStore.INSTANCE.snapshot(ast, "transform entry");
		EclipseAST existing = getAST(ast, false);
		new TransformEclipseAST(existing).go();
		DebugSnapshotStore.INSTANCE.snapshot(ast, "transform exit");
	} catch (Throwable t) {
		DebugSnapshotStore.INSTANCE.snapshot(ast, "transform error: %s", t.getClass().getSimpleName());
		try {
			String message = "Lombok can't parse this source: " + t.toString();
			
			EclipseAST.addProblemToCompilationResult(ast, false, message, 0, 0);
			t.printStackTrace();
		} catch (Throwable t2) {
			try {
				error(ast, "Can't create an error in the problems dialog while adding: " + t.toString(), t2);
			} catch (Throwable t3) {
				//This seems risky to just silently turn off lombok, but if we get this far, something pretty
				//drastic went wrong. For example, the eclipse help system's JSP compiler will trigger a lombok call,
				//but due to class loader shenanigans we'll actually get here due to a cascade of
				//ClassNotFoundErrors. This is the right action for the help system (no lombok needed for that JSP compiler,
				//of course). 'disableLombok' is static, but each context classloader (e.g. each eclipse OSGi plugin) has
				//it's own edition of this class, so this won't turn off lombok everywhere.
				disableLombok = true;
			}
		}
	}
}
 
开发者ID:redundent,项目名称:lombok,代码行数:46,代码来源:TransformEclipseAST.java


示例17: transform

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
public static void transform(Parser parser, CompilationUnitDeclaration ast) throws IOException {
	Util.invokeMethod(TRANSFORM, parser, ast);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:4,代码来源:PatchFixesHider.java


示例18: transform_swapped

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
public static void transform_swapped(CompilationUnitDeclaration ast, Parser parser) throws IOException {
	Util.invokeMethod(TRANSFORM_SWAPPED, ast, parser);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:4,代码来源:PatchFixesHider.java


示例19: transform_swapped

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
public static void transform_swapped(CompilationUnitDeclaration ast, Parser parser) {
	transform(parser, ast);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:4,代码来源:TransformEclipseAST.java


示例20: convert

import org.eclipse.jdt.internal.compiler.parser.Parser; //导入依赖的package包/类
private CompilationUnitDeclaration convert(
    ISourceType[] sourceTypes, CompilationResult compilationResult) throws JavaModelException {
  this.unit = new CompilationUnitDeclaration(this.problemReporter, compilationResult, 0);
  // not filled at this point

  if (sourceTypes.length == 0) return this.unit;
  SourceTypeElementInfo topLevelTypeInfo = (SourceTypeElementInfo) sourceTypes[0];
  org.eclipse.jdt.core.ICompilationUnit cuHandle =
      topLevelTypeInfo.getHandle().getCompilationUnit();
  this.cu = (ICompilationUnit) cuHandle;

  final CompilationUnitElementInfo compilationUnitElementInfo =
      (CompilationUnitElementInfo) ((JavaElement) this.cu).getElementInfo();
  if (this.has1_5Compliance
      && (compilationUnitElementInfo.annotationNumber
              >= CompilationUnitElementInfo.ANNOTATION_THRESHOLD_FOR_DIET_PARSE
          || (compilationUnitElementInfo.hasFunctionalTypes && (this.flags & LOCAL_TYPE) != 0))) {
    // If more than 10 annotations, diet parse as this is faster, but not if
    // the client wants local and anonymous types to be converted
    // (https://bugs.eclipse.org/bugs/show_bug.cgi?id=254738)
    // Also see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=405843
    if ((this.flags & LOCAL_TYPE) == 0) {
      return new Parser(this.problemReporter, true).dietParse(this.cu, compilationResult);
    } else {
      return new Parser(this.problemReporter, true).parse(this.cu, compilationResult);
    }
  }

  /* only positions available */
  int start = topLevelTypeInfo.getNameSourceStart();
  int end = topLevelTypeInfo.getNameSourceEnd();

  /* convert package and imports */
  String[] packageName = ((PackageFragment) cuHandle.getParent()).names;
  if (packageName.length > 0)
    // if its null then it is defined in the default package
    this.unit.currentPackage =
        createImportReference(packageName, start, end, false, ClassFileConstants.AccDefault);
  IImportDeclaration[] importDeclarations =
      topLevelTypeInfo.getHandle().getCompilationUnit().getImports();
  int importCount = importDeclarations.length;
  this.unit.imports = new ImportReference[importCount];
  for (int i = 0; i < importCount; i++) {
    ImportDeclaration importDeclaration = (ImportDeclaration) importDeclarations[i];
    ISourceImport sourceImport = (ISourceImport) importDeclaration.getElementInfo();
    String nameWithoutStar = importDeclaration.getNameWithoutStar();
    this.unit.imports[i] =
        createImportReference(
            Util.splitOn('.', nameWithoutStar, 0, nameWithoutStar.length()),
            sourceImport.getDeclarationSourceStart(),
            sourceImport.getDeclarationSourceEnd(),
            importDeclaration.isOnDemand(),
            sourceImport.getModifiers());
  }
  /* convert type(s) */
  try {
    int typeCount = sourceTypes.length;
    final TypeDeclaration[] types = new TypeDeclaration[typeCount];
    /*
     * We used a temporary types collection to prevent this.unit.types from being null during a call to
     * convert(...) when the source is syntactically incorrect and the parser is flushing the unit's types.
     * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=97466
     */
    for (int i = 0; i < typeCount; i++) {
      SourceTypeElementInfo typeInfo = (SourceTypeElementInfo) sourceTypes[i];
      types[i] = convert((SourceType) typeInfo.getHandle(), compilationResult);
    }
    this.unit.types = types;
    return this.unit;
  } catch (AnonymousMemberFound e) {
    return new Parser(this.problemReporter, true).parse(this.cu, compilationResult);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:74,代码来源:SourceTypeConverter.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java GetSnapshotDiffReportResponseProto类代码示例发布时间:2022-05-22
下一篇:
Java Finder类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap