當前位置: 首頁>>代碼示例>>Java>>正文


Java ASTParser.setSource方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.dom.ASTParser.setSource方法的典型用法代碼示例。如果您正苦於以下問題:Java ASTParser.setSource方法的具體用法?Java ASTParser.setSource怎麽用?Java ASTParser.setSource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.dom.ASTParser的用法示例。


在下文中一共展示了ASTParser.setSource方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getField

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
 * @param methodname
 * @return
 */
public FieldDeclaration getField(   ) {
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	String s = getStaticVariable ( );
	if (s==null) return null;
	parser.setSource(s.toCharArray());
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	final  CompilationUnit cu = (CompilationUnit) parser.createAST(null);
	cu.accept(new ASTVisitor() {
		public boolean visit(FieldDeclaration node) {
			field = node;
			return true;
		}
	});		 
	return field;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:20,代碼來源:ClassExtension.java

示例2: getGraphWalkerClassAnnotation

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
 * @return
 */
public NormalAnnotation getGraphWalkerClassAnnotation() {
	String source = getSource ();
	if(source==null) return null;
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setSource(source.toCharArray());
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
	cu.accept(new ASTVisitor() {
		public boolean visit(NormalAnnotation node) {
			annotation = node;
			return true;
		}
	});
	if (this.generateAnnotation) return annotation;
	return null;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:20,代碼來源:ClassExtension.java

示例3: getGeneratedClassAnnotation

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public NormalAnnotation getGeneratedClassAnnotation() {
	String source = getGeneratedAnnotationSource ();
	if(source==null) return null;
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setSource(source.toCharArray());
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
	cu.accept(new ASTVisitor() {
		public boolean visit(NormalAnnotation node) {
			annotation = node;
			return true;
		}
	});
    return annotation;
	 
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:17,代碼來源:ClassExtension.java

示例4: parse

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public void parse() throws ParseException {
    ASTParser parser = ASTParser.newParser(AST.JLS8);
    parser.setSource(source.toCharArray());
    Map<String, String> options = JavaCore.getOptions();
    options.put("org.eclipse.jdt.core.compiler.source", "1.8");
    parser.setCompilerOptions(options);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setUnitName("Program.java");
    parser.setEnvironment(new String[] { classpath != null? classpath : "" },
            new String[] { "" }, new String[] { "UTF-8" }, true);
    parser.setResolveBindings(true);
    cu = (CompilationUnit) parser.createAST(null);

    List<IProblem> problems = Arrays.stream(cu.getProblems()).filter(p ->
                                        p.isError() &&
                                        p.getID() != IProblem.PublicClassMustMatchFileName && // we use "Program.java"
                                        p.getID() != IProblem.ParameterMismatch // Evidence varargs
                                    ).collect(Collectors.toList());
    if (problems.size() > 0)
        throw new ParseException(problems);
}
 
開發者ID:capergroup,項目名稱:bayou,代碼行數:22,代碼來源:Parser.java

示例5: toGroovyTypeModel

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public TypeModel toGroovyTypeModel(String source) {
    source = source.replaceAll("//(?i)\\s*" + quote("given") + SEPARATOR, "givenBlockStart();");
    source = source.replaceAll("//(?i)\\s*" + quote("when") + SEPARATOR, "whenBlockStart();");
    source = source.replaceAll("//(?i)\\s*" + quote("then") + SEPARATOR, "thenBlockStart();");

    ASTParser parser = ASTParser.newParser(JLS8);
    parser.setSource(source.toCharArray());
    parser.setKind(K_COMPILATION_UNIT);
    parser.setCompilerOptions(compilerOptions());

    CompilationUnit cu = (CompilationUnit) parser.createAST(null);
    astProxy.setTarget(cu.getAST());

    TypeVisitor visitor = testClassVisitorSupplier.get();
    cu.accept(visitor);
    return visitor.typeModel();
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:18,代碼來源:Spocker.java

示例6: getRecoveredAST

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private CompilationUnit getRecoveredAST(IDocument document, int offset, Document recoveredDocument) {
	CompilationUnit ast = SharedASTProvider.getInstance().getAST(fCompilationUnit, null);
	if (ast != null) {
		recoveredDocument.set(document.get());
		return ast;
	}

	char[] content= document.get().toCharArray();

	// clear prefix to avoid compile errors
	int index= offset - 1;
	while (index >= 0 && Character.isJavaIdentifierPart(content[index])) {
		content[index]= ' ';
		index--;
	}

	recoveredDocument.set(new String(content));

	final ASTParser parser= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
	parser.setResolveBindings(true);
	parser.setStatementsRecovery(true);
	parser.setSource(content);
	parser.setUnitName(fCompilationUnit.getElementName());
	parser.setProject(fCompilationUnit.getJavaProject());
	return (CompilationUnit) parser.createAST(new NullProgressMonitor());
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:27,代碼來源:OverrideCompletionProposal.java

示例7: isValidVarargsExpression

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
public static boolean isValidVarargsExpression(String string) {
  String trimmed = string.trim();
  if ("".equals(trimmed)) // speed up for a common case //$NON-NLS-1$
  return true;
  StringBuffer cuBuff = new StringBuffer();
  cuBuff.append("class A{ {m("); // $NON-NLS-1$
  int offset = cuBuff.length();
  cuBuff.append(trimmed).append(");}}"); // $NON-NLS-1$
  ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
  p.setSource(cuBuff.toString().toCharArray());
  CompilationUnit cu = (CompilationUnit) p.createAST(null);
  Selection selection = Selection.createFromStartLength(offset, trimmed.length());
  SelectionAnalyzer analyzer = new SelectionAnalyzer(selection, false);
  cu.accept(analyzer);
  ASTNode[] selectedNodes = analyzer.getSelectedNodes();
  if (selectedNodes.length == 0) return false;
  for (int i = 0; i < selectedNodes.length; i++) {
    if (!(selectedNodes[i] instanceof Expression)) return false;
  }
  return true;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:22,代碼來源:ChangeSignatureProcessor.java

示例8: createAst

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private CompilationUnit createAst() {
   // advise the parser to parse the code following to the Java Language Specification, Fourth Edition
   @SuppressWarnings("deprecation")
   // TODO: remove warning 
final ASTParser parser = ASTParser.newParser(AST.JLS4);

   // tells the parser, that it has to expect an ICompilationUnit as input
   parser.setKind(ASTParser.K_COMPILATION_UNIT);

   parser.setSource(compilationUnit);

   // binding service has to be explicitly requested at parse times
   parser.setResolveBindings(true);

   return (CompilationUnit) parser.createAST(new NullProgressMonitor());
 }
 
開發者ID:sealuzh,項目名稱:PerformanceHat,代碼行數:17,代碼來源:AstCompilationUnitDecorator.java

示例9: Parse

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private CompilationUnit Parse(String contentFile, String fileName) throws Exception
{
	File file = new File(fileName);
	IFile[] files = WorkspaceRoot.findFilesForLocationURI(file.toURI(), IResource.FILE);
	
	if (files.length > 1)
		throw new Exception("Ambigous parse request for file: " + fileName);
	else if (files.length == 0)
		throw new Exception("File is not part of the enlistment: " + fileName);
	
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	parser.setSource(contentFile.toCharArray());
	parser.setUnitName(files[0].getName());
	parser.setProject(JavaCore.create(files[0].getProject()));
	parser.setResolveBindings(true);
	
	CompilationUnit cu = (CompilationUnit)parser.createAST(null);
	return cu;
}
 
開發者ID:Microsoft,項目名稱:vsminecraft,代碼行數:21,代碼來源:JavaParser.java

示例10: getFieldSource

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
private static String getFieldSource(IField field, SourceTuple tuple) throws CoreException {
	if (Flags.isEnum(field.getFlags())) {
		String source= field.getSource();
		if (source != null)
			return source;
	} else {
		if (tuple.node == null) {
			ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
			parser.setSource(tuple.unit);
			tuple.node= (CompilationUnit) parser.createAST(null);
		}
		FieldDeclaration declaration= ASTNodeSearchUtil.getFieldDeclarationNode(field, tuple.node);
		if (declaration.fragments().size() == 1)
			return getSourceOfDeclararationNode(field, tuple.unit);
		VariableDeclarationFragment declarationFragment= ASTNodeSearchUtil.getFieldDeclarationFragmentNode(field, tuple.node);
		IBuffer buffer= tuple.unit.getBuffer();
		StringBuffer buff= new StringBuffer();
		buff.append(buffer.getText(declaration.getStartPosition(), ((ASTNode) declaration.fragments().get(0)).getStartPosition() - declaration.getStartPosition()));
		buff.append(buffer.getText(declarationFragment.getStartPosition(), declarationFragment.getLength()));
		buff.append(";"); //$NON-NLS-1$
		return buff.toString();
	}
	return ""; //$NON-NLS-1$
}
 
開發者ID:trylimits,項目名稱:Eclipse-Postfix-Code-Completion-Juno38,代碼行數:25,代碼來源:TypedSource.java

示例11: parsePartialCompilationUnit

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
static CompilationUnit parsePartialCompilationUnit(ICompilationUnit unit) {

		if (unit == null) {
			throw new IllegalArgumentException();
		}
		try {
			ASTParser c= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
			c.setSource(unit);
			c.setFocalPosition(0);
			c.setResolveBindings(false);
			c.setWorkingCopyOwner(null);
			ASTNode result= c.createAST(null);
			return (CompilationUnit) result;
		} catch (IllegalStateException e) {
			// convert ASTParser's complaints into old form
			throw new IllegalArgumentException();
		}
	}
 
開發者ID:trylimits,項目名稱:Eclipse-Postfix-Code-Completion,代碼行數:19,代碼來源:JavaHistoryActionImpl.java

示例12: parseSource

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
protected static void parseSource(IJavaProject project, final IType type,
	final String qualifiedName, List<String> typeParams,
	final Map<String, String> readableFields, final Map<String, String> writableFields,
	final Map<String, Set<String>> subclassMap) throws JavaModelException
{
	ICompilationUnit compilationUnit = (ICompilationUnit)type
		.getAncestor(IJavaElement.COMPILATION_UNIT);
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	parser.setSource(compilationUnit);
	parser.setResolveBindings(true);
	// parser.setIgnoreMethodBodies(true);
	CompilationUnit astUnit = (CompilationUnit)parser.createAST(null);
	astUnit.accept(new BeanPropertyVisitor(project, qualifiedName, typeParams, readableFields,
		writableFields, subclassMap));
}
 
開發者ID:mybatis,項目名稱:mybatipse,代碼行數:17,代碼來源:BeanPropertyCache.java

示例13: parseAndResolveSource

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
 * Parse a source file, attempting to resolve references in the AST. Valid Java files will usually
 * have errors in the CompilationUnit returned by this method, because classes, imports and
 * methods will be undefined (because we're only looking at a single file from a whole project).
 * Consequently, do not assume the returned object's getProblems() is an empty list. On the other
 * hand, {@link @parseSource} returns a CompilationUnit fit for syntax checking purposes.
 */
private static CompilationUnit parseAndResolveSource(String source) {
  ASTParser parser = createCompilationUnitParser();
  parser.setSource(source.toCharArray());
  parser.setResolveBindings(true);
  parser.setBindingsRecovery(true);
  parser.setEnvironment(
      EMPTY_STRING_ARRAY,
      EMPTY_STRING_ARRAY,
      EMPTY_STRING_ARRAY,
      true /* includeRunningVMBootclasspath */);
  parser.setUnitName("dontCare");

  return (CompilationUnit) parser.createAST(null);
}
 
開發者ID:bazelbuild,項目名稱:BUILD_file_generator,代碼行數:22,代碼來源:ReferencedClassesParser.java

示例14: getBodyMethod

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
 * @param methodname
 * @return
 */
public ExpressionStatement getBodyMethod(String methodname) {
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setSource(getBodyMethodSource (methodname).toCharArray());
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	final  CompilationUnit cu = (CompilationUnit) parser.createAST(null);
	cu.accept(new ASTVisitor() {
		public boolean visit(ExpressionStatement node) {
			expression = node;
			return true;
		}
	});		 
	return expression;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:18,代碼來源:ClassExtension.java

示例15: parse

import org.eclipse.jdt.core.dom.ASTParser; //導入方法依賴的package包/類
/**
 * @param compilationUnit
 * @param progressMonitor
 * @return
 * @throws JavaModelException
 */

public static CompilationUnit parse(final ICompilationUnit cu) {
	ASTParser parser = ASTParser.newParser(AST.JLS8);
	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	parser.setSource(cu);
	parser.setResolveBindings(true);
	parser.setEnvironment(null, null, null, true);
	parser.setBindingsRecovery(true);
	final CompilationUnit ast = (CompilationUnit) parser.createAST(new NullProgressMonitor());

	return ast;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:19,代碼來源:JDTManager.java


注:本文中的org.eclipse.jdt.core.dom.ASTParser.setSource方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。