• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ASTProvider类的典型用法和代码示例

java 1次浏览

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

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

示例1: getParameterTypeNamesForSeeTag

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private static String[] getParameterTypeNamesForSeeTag(IMethod overridden) {
  try {
    CheASTParser parser = CheASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
    parser.setProject(overridden.getJavaProject());
    IBinding[] bindings = parser.createBindings(new IJavaElement[] {overridden}, null);
    if (bindings.length == 1 && bindings[0] instanceof IMethodBinding) {
      return getParameterTypeNamesForSeeTag((IMethodBinding) bindings[0]);
    }
  } catch (IllegalStateException e) {
    // method does not exist
  }
  // fall back code. Not good for generic methods!
  String[] paramTypes = overridden.getParameterTypes();
  String[] paramTypeNames = new String[paramTypes.length];
  for (int i = 0; i < paramTypes.length; i++) {
    paramTypeNames[i] = Signature.toString(Signature.getTypeErasure(paramTypes[i]));
  }
  return paramTypeNames;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:20,
代码来源:StubUtility.java

示例2: isValidExpression

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
public static boolean isValidExpression(String string) {
  String trimmed = string.trim();
  if ("".equals(trimmed)) // speed up for a common case //$NON-NLS-1$
  return false;
  StringBuffer cuBuff = new StringBuffer();
  cuBuff
      .append(CONST_CLASS_DECL)
      .append("Object") // $NON-NLS-1$
      .append(CONST_ASSIGN);
  int offset = cuBuff.length();
  cuBuff.append(trimmed).append(CONST_CLOSE);
  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 selected = analyzer.getFirstSelectedNode();
  return (selected instanceof Expression)
      && trimmed.equals(
          cuBuff.substring(
              cu.getExtendedStartPosition(selected),
              cu.getExtendedStartPosition(selected) + cu.getExtendedLength(selected)));
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:25,
代码来源:ChangeSignatureProcessor.java

示例3: isValidVarargsExpression

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的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

示例4: checkCompilationofDeclaringCu

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private RefactoringStatus checkCompilationofDeclaringCu() throws CoreException {
  ICompilationUnit cu = getCu();
  TextChange change = fChangeManager.get(cu);
  String newCuSource = change.getPreviewContent(new NullProgressMonitor());
  CompilationUnit newCUNode =
      new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL)
          .parse(newCuSource, cu, true, false, null);
  IProblem[] problems =
      RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, fBaseCuRewrite.getRoot());
  RefactoringStatus result = new RefactoringStatus();
  for (int i = 0; i < problems.length; i++) {
    IProblem problem = problems[i];
    if (shouldReport(problem, newCUNode))
      result.addEntry(
          new RefactoringStatusEntry(
              (problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING),
              problem.getMessage(),
              new JavaStringStatusContext(newCuSource, SourceRangeFactory.create(problem))));
  }
  return result;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:22,
代码来源:ChangeSignatureProcessor.java

示例5: checkNewSource

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private void checkNewSource(SubProgressMonitor monitor, RefactoringStatus result)
    throws CoreException {
  String newCuSource = fChange.getPreviewContent(new NullProgressMonitor());
  CompilationUnit newCUNode =
      new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL)
          .parse(newCuSource, fCu, true, true, monitor);
  IProblem[] newProblems =
      RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, fCompilationUnitNode);
  for (int i = 0; i < newProblems.length; i++) {
    IProblem problem = newProblems[i];
    if (problem.isError())
      result.addEntry(
          new RefactoringStatusEntry(
              (problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING),
              problem.getMessage(),
              new JavaStringStatusContext(newCuSource, SourceRangeFactory.create(problem))));
  }
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:19,
代码来源:ExtractTempRefactoring.java

示例6: checkSource

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private void checkSource(SubProgressMonitor monitor, RefactoringStatus result)
    throws CoreException {
  String newCuSource = fChange.getPreviewContent(new NullProgressMonitor());
  CompilationUnit newCUNode =
      new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL)
          .parse(newCuSource, fCu, true, true, monitor);

  IProblem[] newProblems =
      RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, fCuRewrite.getRoot());
  for (int i = 0; i < newProblems.length; i++) {
    IProblem problem = newProblems[i];
    if (problem.isError())
      result.addEntry(
          new RefactoringStatusEntry(
              (problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING),
              problem.getMessage(),
              new JavaStringStatusContext(newCuSource, SourceRangeFactory.create(problem))));
  }
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:20,
代码来源:ExtractConstantRefactoring.java

示例7: parseWithASTProvider

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
/**
 * Tries to get the shared AST from the ASTProvider. If the shared AST is not available, parses
 * the type root with a RefactoringASTParser that uses settings similar to the ASTProvider.
 *
 * @param typeRoot the type root
 * @param resolveBindings whether bindings are to be resolved if a new AST needs to be created
 * @param pm an {@link IProgressMonitor}, or <code>null</code>
 * @return the parsed CompilationUnit
 */
public static CompilationUnit parseWithASTProvider(
    ITypeRoot typeRoot, boolean resolveBindings, IProgressMonitor pm) {
  CompilationUnit cuNode =
      SharedASTProvider.getAST(typeRoot, SharedASTProvider.WAIT_ACTIVE_ONLY, pm);
  if (cuNode != null) {
    return cuNode;
  } else {
    return new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL)
        .parse(
            typeRoot,
            null,
            resolveBindings,
            ASTProvider.SHARED_AST_STATEMENT_RECOVERY,
            ASTProvider.SHARED_BINDING_RECOVERY,
            pm);
  }
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:27,
代码来源:RefactoringASTParser.java

示例8: checkInitialConditions

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
  if (fVisibility < 0)
    fVisibility = (fField.getFlags() & (Flags.AccPublic | Flags.AccProtected | Flags.AccPrivate));
  RefactoringStatus result = new RefactoringStatus();
  result.merge(Checks.checkAvailability(fField));
  if (result.hasFatalError()) return result;
  fRoot =
      new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL)
          .parse(fField.getCompilationUnit(), true, pm);
  ISourceRange sourceRange = fField.getNameRange();
  ASTNode node = NodeFinder.perform(fRoot, sourceRange.getOffset(), sourceRange.getLength());
  if (node == null) {
    return mappingErrorFound(result, node);
  }
  fFieldDeclaration =
      (VariableDeclarationFragment) ASTNodes.getParent(node, VariableDeclarationFragment.class);
  if (fFieldDeclaration == null) {
    return mappingErrorFound(result, node);
  }
  if (fFieldDeclaration.resolveBinding() == null) {
    if (!processCompilerError(result, node))
      result.addFatalError(RefactoringCoreMessages.SelfEncapsulateField_type_not_resolveable);
    return result;
  }
  computeUsedNames();
  return result;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:29,
代码来源:SelfEncapsulateFieldRefactoring.java

示例9: checkConstructorParameterNames

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private RefactoringStatus checkConstructorParameterNames() {
	RefactoringStatus result= new RefactoringStatus();
	CompilationUnit cuNode= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(fType.getCompilationUnit(), false);
	MethodDeclaration[] nodes= getConstructorDeclarationNodes(findTypeDeclaration(fType, cuNode));
	for (int i= 0; i < nodes.length; i++) {
		MethodDeclaration constructor= nodes[i];
		for (Iterator<SingleVariableDeclaration> iter= constructor.parameters().iterator(); iter.hasNext();) {
			SingleVariableDeclaration param= iter.next();
			if (fEnclosingInstanceFieldName.equals(param.getName().getIdentifier())) {
				String[] keys= new String[] { BasicElementLabels.getJavaElementName(param.getName().getIdentifier()), BasicElementLabels.getJavaElementName(fType.getElementName())};
				String msg= Messages.format(RefactoringCoreMessages.MoveInnerToTopRefactoring_name_used, keys);
				result.addError(msg, JavaStatusContext.create(fType.getCompilationUnit(), param));
			}
		}
	}
	return result;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:18,
代码来源:MoveInnerToTopRefactoring.java

示例10: removeUnrealReferences

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private SearchResultGroup[] removeUnrealReferences(SearchResultGroup[] groups) {
	List<SearchResultGroup> result= new ArrayList<SearchResultGroup>(groups.length);
	for (int i= 0; i < groups.length; i++) {
		SearchResultGroup group= groups[i];
		ICompilationUnit cu= group.getCompilationUnit();
		if (cu == null)
			continue;
		CompilationUnit cuNode= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(cu, false);
		SearchMatch[] allSearchResults= group.getSearchResults();
		List<SearchMatch> realConstructorReferences= new ArrayList<SearchMatch>(Arrays.asList(allSearchResults));
		for (int j= 0; j < allSearchResults.length; j++) {
			SearchMatch searchResult= allSearchResults[j];
			if (! isRealConstructorReferenceNode(ASTNodeSearchUtil.getAstNode(searchResult, cuNode)))
				realConstructorReferences.remove(searchResult);
		}
		if (! realConstructorReferences.isEmpty())
			result.add(new SearchResultGroup(group.getResource(), realConstructorReferences.toArray(new SearchMatch[realConstructorReferences.size()])));
	}
	return result.toArray(new SearchResultGroup[result.size()]);
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:21,
代码来源:ConstructorReferenceFinder.java

示例11: getImplicitConstructorReferencesInClassCreations

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private List<SearchMatch> getImplicitConstructorReferencesInClassCreations(WorkingCopyOwner owner, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
	//XXX workaround for jdt core bug 23112
	SearchPattern pattern= SearchPattern.createPattern(fType, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
	IJavaSearchScope scope= RefactoringScopeFactory.create(fType);
	SearchResultGroup[] refs= RefactoringSearchEngine.search(pattern, owner, scope, pm, status);
	List<SearchMatch> result= new ArrayList<SearchMatch>();
	for (int i= 0; i < refs.length; i++) {
		SearchResultGroup group= refs[i];
		ICompilationUnit cu= group.getCompilationUnit();
		if (cu == null)
			continue;
		CompilationUnit cuNode= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(cu, false);
		SearchMatch[] results= group.getSearchResults();
		for (int j= 0; j < results.length; j++) {
			SearchMatch searchResult= results[j];
			ASTNode node= ASTNodeSearchUtil.getAstNode(searchResult, cuNode);
			if (isImplicitConstructorReferenceNodeInClassCreations(node))
				result.add(searchResult);
		}
	}
	return result;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:23,
代码来源:ConstructorReferenceFinder.java

示例12: isValidExpression

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
public static boolean isValidExpression(String string){
	String trimmed= string.trim();
	if ("".equals(trimmed)) //speed up for a common case //$NON-NLS-1$
		return false;
	StringBuffer cuBuff= new StringBuffer();
	cuBuff.append(CONST_CLASS_DECL)
		  .append("Object") //$NON-NLS-1$
		  .append(CONST_ASSIGN);
	int offset= cuBuff.length();
	cuBuff.append(trimmed)
		  .append(CONST_CLOSE);
	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 selected= analyzer.getFirstSelectedNode();
	return (selected instanceof Expression) &&
			trimmed.equals(cuBuff.substring(cu.getExtendedStartPosition(selected), cu.getExtendedStartPosition(selected) + cu.getExtendedLength(selected)));
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:22,
代码来源:ChangeSignatureProcessor.java

示例13: isValidVarargsExpression

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的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:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:25,
代码来源:ChangeSignatureProcessor.java

示例14: checkInitialConditions

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
	if (fVisibility < 0)
		fVisibility= (fField.getFlags() & (Flags.AccPublic | Flags.AccProtected | Flags.AccPrivate));
	RefactoringStatus result=  new RefactoringStatus();
	result.merge(Checks.checkAvailability(fField));
	if (result.hasFatalError())
		return result;
	fRoot= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(fField.getCompilationUnit(), true, pm);
	ISourceRange sourceRange= fField.getNameRange();
	ASTNode node= NodeFinder.perform(fRoot, sourceRange.getOffset(), sourceRange.getLength());
	if (node == null) {
		return mappingErrorFound(result, node);
	}
	fFieldDeclaration= (VariableDeclarationFragment)ASTNodes.getParent(node, VariableDeclarationFragment.class);
	if (fFieldDeclaration == null) {
		return mappingErrorFound(result, node);
	}
	if (fFieldDeclaration.resolveBinding() == null) {
		if (!processCompilerError(result, node))
			result.addFatalError(RefactoringCoreMessages.SelfEncapsulateField_type_not_resolveable);
		return result;
	}
	computeUsedNames();
	return result;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:27,
代码来源:SelfEncapsulateFieldRefactoring.java

示例15: parsePartialCompilationUnit

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的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-Juno38,
代码行数:19,
代码来源:JavaHistoryActionImpl.java

示例16: getFieldSource

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的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,
代码行数:25,
代码来源:TypedSource.java

示例17: getParameterTypeNamesForSeeTag

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private static String[] getParameterTypeNamesForSeeTag(IMethod overridden) {
	try {
		ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
		parser.setProject(overridden.getJavaProject());
		IBinding[] bindings= parser.createBindings(new IJavaElement[] { overridden }, null);
		if (bindings.length == 1 && bindings[0] instanceof IMethodBinding) {
			return getParameterTypeNamesForSeeTag((IMethodBinding)bindings[0]);
		}
	} catch (IllegalStateException e) {
		// method does not exist
	}
	// fall back code. Not good for generic methods!
	String[] paramTypes= overridden.getParameterTypes();
	String[] paramTypeNames= new String[paramTypes.length];
	for (int i= 0; i < paramTypes.length; i++) {
		paramTypeNames[i]= Signature.toString(Signature.getTypeErasure(paramTypes[i]));
	}
	return paramTypeNames;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:20,
代码来源:StubUtility.java

示例18: constructCUContent

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
/**
 * Uses the New Java file template from the code template page to generate a
 * compilation unit with the given type content.
 * 
 * @param cu The new created compilation unit
 * @param typeContent The content of the type, including signature and type
 * body.
 * @param lineDelimiter The line delimiter to be used.
 * @return String Returns the result of evaluating the new file template
 * with the given type content.
 * @throws CoreException when fetching the file comment fails or fetching the content for the
 *             new compilation unit fails
 * @since 2.1
 */
protected String constructCUContent(ICompilationUnit cu, String typeContent, String lineDelimiter) throws CoreException {
	String fileComment= getFileComment(cu, lineDelimiter);
	String typeComment= getTypeComment(cu, lineDelimiter);
	IPackageFragment pack= (IPackageFragment) cu.getParent();
	String content= CodeGeneration.getCompilationUnitContent(cu, fileComment, typeComment, typeContent, lineDelimiter);
	if (content != null) {
		ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
		parser.setProject(cu.getJavaProject());
		parser.setSource(content.toCharArray());
		CompilationUnit unit= (CompilationUnit) parser.createAST(null);
		if ((pack.isDefaultPackage() || unit.getPackage() != null) && !unit.types().isEmpty()) {
			return content;
		}
	}
	StringBuffer buf= new StringBuffer();
	if (!pack.isDefaultPackage()) {
		buf.append("package ").append(pack.getElementName()).append(';'); //$NON-NLS-1$
	}
	buf.append(lineDelimiter).append(lineDelimiter);
	if (typeComment != null) {
		buf.append(typeComment).append(lineDelimiter);
	}
	buf.append(typeContent);
	return buf.toString();
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:40,
代码来源:NewTypeWizardPage.java

示例19: getRecoveredAST

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private CompilationUnit getRecoveredAST(IDocument document, int offset, Document recoveredDocument) {
	CompilationUnit ast= SharedASTProvider.getAST(fCompilationUnit, SharedASTProvider.WAIT_ACTIVE_ONLY, 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(ASTProvider.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:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:27,
代码来源:OverrideCompletionProposal.java

示例20: visitCompilationUnit

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private void visitCompilationUnit(IFile file) {
	ICompilationUnit cu= JavaCore.createCompilationUnitFrom(file);
	if (cu != null) {
		ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
		parser.setSource(cu);
		parser.setFocalPosition(0);
		CompilationUnit root= (CompilationUnit)parser.createAST(null);
		PackageDeclaration packDecl= root.getPackage();
		
		IPath packPath= file.getParent().getFullPath();
		String cuName= file.getName();
		if (packDecl == null) {
			addToMap(fSourceFolders, packPath, new Path(cuName));
		} else {
			IPath relPath= new Path(packDecl.getName().getFullyQualifiedName().replace('.', '/'));
			IPath folderPath= getFolderPath(packPath, relPath);
			if (folderPath != null) {
				addToMap(fSourceFolders, folderPath, relPath.append(cuName));
			}
		}
	}
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion,
代码行数:23,
代码来源:ClassPathDetector.java

示例21: createBoxed

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
StandardType createBoxed(PrimitiveType type, IJavaProject focus) {
	String fullyQualifiedName= BOXED_PRIMITIVE_NAMES[type.getId()];
	try {
		IType javaElementType= focus.findType(fullyQualifiedName);
		StandardType result= fStandardTypes.get(javaElementType);
		if (result != null)
			return result;
		ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
		parser.setProject(focus);
		IBinding[] bindings= parser.createBindings(new IJavaElement[] {javaElementType} , null);
		return createStandardType((ITypeBinding)bindings[0]);
	} catch (JavaModelException e) {
		// fall through
	}
	return null;
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion-Juno38,
代码行数:17,
代码来源:TypeEnvironment.java

示例22: getJavadocNode

点赞 3

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private static Javadoc getJavadocNode(IMember member, String rawJavadoc) {
	//FIXME: take from SharedASTProvider if available
	//Caveat: Javadoc nodes are not available when Javadoc processing has been disabled!
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=212207

	ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);

	IJavaProject javaProject= member.getJavaProject();
	parser.setProject(javaProject);
	Map<String, String> options= javaProject.getOptions(true);
	options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=212207
	parser.setCompilerOptions(options);

	String source= rawJavadoc + "class C{}"; //$NON-NLS-1$
	parser.setSource(source.toCharArray());

	CompilationUnit root= (CompilationUnit) parser.createAST(null);
	if (root == null)
		return null;
	List<AbstractTypeDeclaration> types= root.types();
	if (types.size() != 1)
		return null;
	AbstractTypeDeclaration type= types.get(0);
	return type.getJavadoc();
}
 

开发者ID:trylimits,
项目名称:Eclipse-Postfix-Code-Completion-Juno38,
代码行数:26,
代码来源:JavadocContentAccess2.java

示例23: getRoot

点赞 2

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
public CompilationUnit getRoot() {
  if (fRoot == null)
    fRoot =
        new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL)
            .parse(fCu, fOwner, fResolveBindings, fStatementsRecovery, fBindingsRecovery, null);
  return fRoot;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:8,
代码来源:CompilationUnitRewrite.java

示例24: checkInitialConditions

点赞 2

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
  // TargetProvider must get an untampered AST with original invocation node
  // SourceProvider must get a tweaked AST with method body / parameter names replaced

  RefactoringStatus result = new RefactoringStatus();

  if (fMethod == null) {
    if (!(fSelectionTypeRoot instanceof ICompilationUnit))
      return RefactoringStatus.createFatalErrorStatus(
          RefactoringCoreMessages.ReplaceInvocationsRefactoring_cannot_replace_in_binary);

    ICompilationUnit cu = (ICompilationUnit) fSelectionTypeRoot;
    CompilationUnit root = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(cu, true);
    fSelectionNode = getTargetNode(cu, root, fSelectionStart, fSelectionLength);
    if (fSelectionNode == null)
      return RefactoringStatus.createFatalErrorStatus(
          RefactoringCoreMessages.ReplaceInvocationsRefactoring_select_method_to_apply);

    if (fSelectionNode.getNodeType() == ASTNode.METHOD_DECLARATION) {
      MethodDeclaration methodDeclaration = (MethodDeclaration) fSelectionNode;
      fTargetProvider = TargetProvider.create(methodDeclaration);
      fMethodBinding = methodDeclaration.resolveBinding();
    } else {
      MethodInvocation methodInvocation = (MethodInvocation) fSelectionNode;
      fTargetProvider = TargetProvider.create(cu, methodInvocation);
      fMethodBinding = methodInvocation.resolveMethodBinding();
    }
    if (fMethodBinding == null)
      return RefactoringStatus.createFatalErrorStatus(
          RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);
    fMethod = (IMethod) fMethodBinding.getJavaElement();

  } else {
    ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
    parser.setProject(fMethod.getJavaProject());
    IBinding[] bindings = parser.createBindings(new IJavaElement[] {fMethod}, null);
    fMethodBinding = (IMethodBinding) bindings[0];
    if (fMethodBinding == null)
      return RefactoringStatus.createFatalErrorStatus(
          RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);

    fTargetProvider = TargetProvider.create(fMethodBinding);
  }

  result.merge(fTargetProvider.checkActivation());
  return result;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:49,
代码来源:ReplaceInvocationsRefactoring.java

示例25: createStandardType

点赞 2

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private StandardType createStandardType(String fullyQualifiedName, IJavaProject focus) {
  try {
    IType javaElementType = focus.findType(fullyQualifiedName);
    StandardType result = fStandardTypes.get(javaElementType);
    if (result != null) return result;
    ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
    parser.setProject(focus);
    IBinding[] bindings = parser.createBindings(new IJavaElement[] {javaElementType}, null);
    return createStandardType((ITypeBinding) bindings[0]);
  } catch (JavaModelException e) {
    // fall through
  }
  return null;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:15,
代码来源:TypeEnvironment.java

示例26: getCuNode

点赞 2

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private static CompilationUnit getCuNode(WorkingCopyOwner workingCopyOwner, ICompilationUnit cu) {
  ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
  p.setSource(cu);
  p.setResolveBindings(true);
  p.setWorkingCopyOwner(workingCopyOwner);
  p.setCompilerOptions(RefactoringASTParser.getCompilerOptions(cu));
  return (CompilationUnit) p.createAST(null);
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:9,
代码来源:ASTCreator.java

示例27: createSourceCuNode

点赞 2

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private CompilationUnit createSourceCuNode() {
  Assert.isTrue(getSourceCu() != null || getSourceClassFile() != null);
  Assert.isTrue(getSourceCu() == null || getSourceClassFile() == null);
  ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
  parser.setBindingsRecovery(true);
  parser.setResolveBindings(true);
  if (getSourceCu() != null) parser.setSource(getSourceCu());
  else parser.setSource(getSourceClassFile());
  return (CompilationUnit) parser.createAST(null);
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:11,
代码来源:ReorgPolicyFactory.java

示例28: parseType

点赞 2

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private static Type parseType(
    String typeString, IJavaProject javaProject, List<String> problemsCollector) {
  if ("".equals(typeString.trim())) // speed up for a common case //$NON-NLS-1$
  return null;
  if (!typeString.trim().equals(typeString)) return null;

  StringBuffer cuBuff = new StringBuffer();
  cuBuff.append("interface A{"); // $NON-NLS-1$
  int offset = cuBuff.length();
  cuBuff.append(typeString).append(" m();}"); // $NON-NLS-1$

  ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
  p.setSource(cuBuff.toString().toCharArray());
  p.setProject(javaProject);
  CompilationUnit cu = (CompilationUnit) p.createAST(null);
  Selection selection = Selection.createFromStartLength(offset, typeString.length());
  SelectionAnalyzer analyzer = new SelectionAnalyzer(selection, false);
  cu.accept(analyzer);
  ASTNode selected = analyzer.getFirstSelectedNode();
  if (!(selected instanceof Type)) return null;
  Type type = (Type) selected;
  if (MethodTypesSyntaxChecker.isVoidArrayType(type)) return null;
  IProblem[] problems = ASTNodes.getProblems(type, ASTNodes.NODE_ONLY, ASTNodes.PROBLEMS);
  if (problems.length > 0) {
    for (int i = 0; i < problems.length; i++) problemsCollector.add(problems[i].getMessage());
  }

  String typeNodeRange =
      cuBuff.substring(type.getStartPosition(), ASTNodes.getExclusiveEnd(type));
  if (typeString.equals(typeNodeRange)) return type;
  else return null;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:33,
代码来源:TypeContextChecker.java

示例29: parseSuperType

点赞 2

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; //导入依赖的package包/类
private static Type parseSuperType(String superType, boolean isInterface) {
  if (!superType.trim().equals(superType)) {
    return null;
  }

  StringBuffer cuBuff = new StringBuffer();
  if (isInterface) cuBuff.append("class __X__ implements "); // $NON-NLS-1$
  else cuBuff.append("class __X__ extends "); // $NON-NLS-1$
  int offset = cuBuff.length();
  cuBuff.append(superType).append(" {}"); // $NON-NLS-1$

  ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
  p.setSource(cuBuff.toString().toCharArray());
  Map<String, String> options = new HashMap<String, String>();
  JavaModelUtil.setComplianceOptions(options, JavaModelUtil.VERSION_LATEST);
  p.setCompilerOptions(options);
  CompilationUnit cu = (CompilationUnit) p.createAST(null);
  ASTNode selected = NodeFinder.perform(cu, offset, superType.length());
  if (selected instanceof Name) selected = selected.getParent();
  if (selected.getStartPosition() != offset
      || selected.getLength() != superType.length()
      || !(selected instanceof Type)
      || selected instanceof PrimitiveType) {
    return null;
  }
  Type type = (Type) selected;

  String typeNodeRange =
      cuBuff.substring(type.getStartPosition(), ASTNodes.getExclusiveEnd(type));
  if (!superType.equals(typeNodeRange)) {
    return null;
  }
  return type;
}
 

开发者ID:eclipse,
项目名称:che,
代码行数:35,
代码来源:TypeContextChecker.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)