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


Java Parser类代码示例

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


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


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