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


Java IImportDeclaration类代码示例

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


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

示例1: getFullQualifiedName

import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private static String getFullQualifiedName(IImportDeclaration[] imports,
		String paramType) {
	if (imports == null) {
		return null;
	}

	String importFullQualifiedName;
	String importType;

	for (IImportDeclaration importDeclaration : imports) {
		importFullQualifiedName = importDeclaration.getElementName();
		importType = importFullQualifiedName
				.substring(importFullQualifiedName.lastIndexOf(".") + 1);
		if (paramType.equals(importType)) {
			return importFullQualifiedName;
		}
	}

	return null;
}
 
开发者ID:junit-tools-team,项目名称:junit-tools,代码行数:21,代码来源:JDTUtils.java

示例2: getDeclarationNodes

import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
public static ASTNode[] getDeclarationNodes(IJavaElement element, CompilationUnit cuNode)
    throws JavaModelException {
  switch (element.getElementType()) {
    case IJavaElement.FIELD:
      return new ASTNode[] {getFieldOrEnumConstantDeclaration((IField) element, cuNode)};
    case IJavaElement.IMPORT_CONTAINER:
      return getImportNodes((IImportContainer) element, cuNode);
    case IJavaElement.IMPORT_DECLARATION:
      return new ASTNode[] {getImportDeclarationNode((IImportDeclaration) element, cuNode)};
    case IJavaElement.INITIALIZER:
      return new ASTNode[] {getInitializerNode((IInitializer) element, cuNode)};
    case IJavaElement.METHOD:
      return new ASTNode[] {
        getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) element, cuNode)
      };
    case IJavaElement.PACKAGE_DECLARATION:
      return new ASTNode[] {getPackageDeclarationNode((IPackageDeclaration) element, cuNode)};
    case IJavaElement.TYPE:
      return new ASTNode[] {getAbstractTypeDeclarationNode((IType) element, cuNode)};
    default:
      Assert.isTrue(false, String.valueOf(element.getElementType()));
      return null;
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:ASTNodeSearchUtil.java

示例3: checkTypesImportedInCu

import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private RefactoringStatus checkTypesImportedInCu() throws CoreException {
  IImportDeclaration imp = getImportedType(fType.getCompilationUnit(), getNewElementName());

  if (imp == null) return null;

  String msg =
      Messages.format(
          RefactoringCoreMessages.RenameTypeRefactoring_imported,
          new Object[] {
            getNewElementLabel(),
            BasicElementLabels.getPathLabel(
                fType.getCompilationUnit().getResource().getFullPath(), false)
          });
  IJavaElement grandParent = imp.getParent().getParent();
  if (grandParent instanceof ICompilationUnit)
    return RefactoringStatus.createErrorStatus(msg, JavaStatusContext.create(imp));

  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:RenameTypeProcessor.java

示例4: analyzeImportedTypes

import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private void analyzeImportedTypes(IType[] types, RefactoringStatus result, IImportDeclaration imp)
    throws CoreException {
  for (int i = 0; i < types.length; i++) {
    // could this be a problem (same package imports)?
    if (JdtFlags.isPublic(types[i]) && types[i].getElementName().equals(getNewElementName())) {
      String msg =
          Messages.format(
              RefactoringCoreMessages.RenameTypeRefactoring_name_conflict1,
              new Object[] {
                JavaElementLabels.getElementLabel(
                    types[i], JavaElementLabels.ALL_FULLY_QUALIFIED),
                BasicElementLabels.getPathLabel(getCompilationUnit(imp).getPath(), false)
              });
      result.addError(msg, JavaStatusContext.create(imp));
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:RenameTypeProcessor.java

示例5: analyzeImportDeclaration

import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private void analyzeImportDeclaration(IImportDeclaration imp, RefactoringStatus result)
    throws CoreException {
  if (!imp.isOnDemand()) return; // analyzed earlier

  IJavaElement imported = convertFromImportDeclaration(imp);
  if (imported == null) return;

  if (imported instanceof IPackageFragment) {
    ICompilationUnit[] cus = ((IPackageFragment) imported).getCompilationUnits();
    for (int i = 0; i < cus.length; i++) {
      analyzeImportedTypes(cus[i].getTypes(), result, imp);
    }
  } else {
    // cast safe: see JavaModelUtility.convertFromImportDeclaration
    analyzeImportedTypes(((IType) imported).getTypes(), result, imp);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:RenameTypeProcessor.java

示例6: addTypeImports

import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
/**
 * Add new imports to types in <code>typeReferences</code> with package <code>fPackage</code>.
 *
 * @param typeReferences type references
 * @throws CoreException should not happen
 */
private void addTypeImports(SearchResultGroup typeReferences) throws CoreException {
  SearchMatch[] searchResults = typeReferences.getSearchResults();
  for (int i = 0; i < searchResults.length; i++) {
    SearchMatch result = searchResults[i];
    IJavaElement enclosingElement = SearchUtils.getEnclosingJavaElement(result);
    if (!(enclosingElement instanceof IImportDeclaration)) {
      String reference = getNormalizedTypeReference(result);
      if (!reference.startsWith(fPackage.getElementName())) {
        // is unqualified
        reference = cutOffInnerTypes(reference);
        ImportChange importChange =
            fImportsManager.getImportChange(typeReferences.getCompilationUnit());
        importChange.addImport(fPackage.getElementName() + '.' + reference);
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:RenamePackageProcessor.java

示例7: updateTypeImports

import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
/**
 * Add new imports to types in <code>typeReferences</code> with package <code>fNewElementName
 * </code> and remove old import with <code>fPackage</code>.
 *
 * @param typeReferences type references
 * @throws CoreException should not happen
 */
private void updateTypeImports(SearchResultGroup typeReferences) throws CoreException {
  SearchMatch[] searchResults = typeReferences.getSearchResults();
  for (int i = 0; i < searchResults.length; i++) {
    SearchMatch result = searchResults[i];
    IJavaElement enclosingElement = SearchUtils.getEnclosingJavaElement(result);
    if (enclosingElement instanceof IImportDeclaration) {
      IImportDeclaration importDeclaration = (IImportDeclaration) enclosingElement;
      updateImport(
          typeReferences.getCompilationUnit(),
          importDeclaration,
          getUpdatedImport(importDeclaration));
    } else {
      String reference = getNormalizedTypeReference(result);
      if (!reference.startsWith(fPackage.getElementName())) {
        reference = cutOffInnerTypes(reference);
        ImportChange importChange =
            fImportsManager.getImportChange(typeReferences.getCompilationUnit());
        importChange.removeImport(fPackage.getElementName() + '.' + reference);
        importChange.addImport(getNewPackageName() + '.' + reference);
      } // else: already found & updated with package reference search
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:31,代码来源:RenamePackageProcessor.java

示例8: copyImportsToDestination

import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private void copyImportsToDestination(
    IImportContainer container,
    ASTRewrite rewrite,
    CompilationUnit sourceCuNode,
    CompilationUnit destinationCuNode)
    throws JavaModelException {
  ListRewrite listRewrite =
      rewrite.getListRewrite(destinationCuNode, CompilationUnit.IMPORTS_PROPERTY);

  IJavaElement[] importDeclarations = container.getChildren();
  for (int i = 0; i < importDeclarations.length; i++) {
    IImportDeclaration declaration = (IImportDeclaration) importDeclarations[i];

    ImportDeclaration sourceNode =
        ASTNodeSearchUtil.getImportDeclarationNode(declaration, sourceCuNode);
    ImportDeclaration copiedNode =
        (ImportDeclaration) ASTNode.copySubtree(rewrite.getAST(), sourceNode);

    if (getLocation() == IReorgDestination.LOCATION_BEFORE) {
      listRewrite.insertFirst(copiedNode, null);
    } else {
      listRewrite.insertLast(copiedNode, null);
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:ReorgPolicyFactory.java

示例9: copyImportToDestination

import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private void copyImportToDestination(
    IImportDeclaration declaration,
    ASTRewrite targetRewrite,
    CompilationUnit sourceCuNode,
    CompilationUnit destinationCuNode)
    throws JavaModelException {
  ImportDeclaration sourceNode =
      ASTNodeSearchUtil.getImportDeclarationNode(declaration, sourceCuNode);
  ImportDeclaration copiedNode =
      (ImportDeclaration) ASTNode.copySubtree(targetRewrite.getAST(), sourceNode);
  ListRewrite listRewrite =
      targetRewrite.getListRewrite(destinationCuNode, CompilationUnit.IMPORTS_PROPERTY);

  if (getJavaElementDestination() instanceof IImportDeclaration) {
    ImportDeclaration destinationNode =
        ASTNodeSearchUtil.getImportDeclarationNode(
            (IImportDeclaration) getJavaElementDestination(), destinationCuNode);
    insertRelative(copiedNode, destinationNode, listRewrite);
  } else {
    // dropped on container, we could be better here
    listRewrite.insertLast(copiedNode, null);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:ReorgPolicyFactory.java

示例10: addStaticImport

import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private void addStaticImport(
    ICompilationUnit movedUnit, IImportDeclaration importDecl, ImportRewrite rewrite) {
  String old = importDecl.getElementName();
  int oldPackLength = movedUnit.getParent().getElementName().length();

  StringBuffer result = new StringBuffer(fDestination.getElementName());
  if (oldPackLength == 0) // move FROM default package
  result.append('.').append(old);
  else if (result.length() == 0) // move TO default package
  result.append(old.substring(oldPackLength + 1)); // cut "."
  else result.append(old.substring(oldPackLength));
  int index = result.lastIndexOf("."); // $NON-NLS-1$
  if (index > 0 && index < result.length() - 1)
    rewrite.addStaticImport(
        result.substring(0, index), result.substring(index + 1, result.length()), true);
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:MoveCuUpdateCreator.java

示例11: isImportOfTestAnnotationExist

import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private boolean isImportOfTestAnnotationExist(
    ICompilationUnit compilationUnit, String testAnnotation) {
  try {
    IImportDeclaration[] imports = compilationUnit.getImports();
    for (IImportDeclaration importDeclaration : imports) {
      String elementName = importDeclaration.getElementName();
      if (testAnnotation.equals(elementName)) {
        return true;
      }
      if (importDeclaration.isOnDemand()
          && testAnnotation.startsWith(
              elementName.substring(0, elementName.length() - 3))) { // remove .*
        return true;
      }
    }
  } catch (JavaModelException e) {
    LOG.info("Can't read class imports.", e);
    return false;
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:JavaTestFinder.java

示例12: getDeclarationNodes

import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
public static ASTNode[] getDeclarationNodes(IJavaElement element, CompilationUnit cuNode) throws JavaModelException {
	switch(element.getElementType()){
		case IJavaElement.FIELD:
			return new ASTNode[]{getFieldOrEnumConstantDeclaration((IField) element, cuNode)};
		case IJavaElement.IMPORT_CONTAINER:
			return getImportNodes((IImportContainer)element, cuNode);
		case IJavaElement.IMPORT_DECLARATION:
			return new ASTNode[]{getImportDeclarationNode((IImportDeclaration)element, cuNode)};
		case IJavaElement.INITIALIZER:
			return new ASTNode[]{getInitializerNode((IInitializer)element, cuNode)};
		case IJavaElement.METHOD:
			return new ASTNode[]{getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) element, cuNode)};
		case IJavaElement.PACKAGE_DECLARATION:
			return new ASTNode[]{getPackageDeclarationNode((IPackageDeclaration)element, cuNode)};
		case IJavaElement.TYPE:
			return new ASTNode[]{getAbstractTypeDeclarationNode((IType) element, cuNode)};
		default:
			Assert.isTrue(false, String.valueOf(element.getElementType()));
			return null;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:ASTNodeSearchUtil.java

示例13: analyzeImportDeclaration

import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private void analyzeImportDeclaration(IImportDeclaration imp, RefactoringStatus result) throws CoreException{
	if (!imp.isOnDemand())
		return; //analyzed earlier

	IJavaElement imported= convertFromImportDeclaration(imp);
	if (imported == null)
		return;

	if (imported instanceof IPackageFragment){
		ICompilationUnit[] cus= ((IPackageFragment)imported).getCompilationUnits();
		for (int i= 0; i < cus.length; i++) {
			analyzeImportedTypes(cus[i].getTypes(), result, imp);
		}
	} else {
		//cast safe: see JavaModelUtility.convertFromImportDeclaration
		analyzeImportedTypes(((IType)imported).getTypes(), result, imp);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:RenameTypeProcessor.java

示例14: addTypeImports

import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
/**
 * Add new imports to types in <code>typeReferences</code> with package <code>fPackage</code>.
 * @param typeReferences type references
 * @throws CoreException should not happen
 */
private void addTypeImports(SearchResultGroup typeReferences) throws CoreException {
	SearchMatch[] searchResults= typeReferences.getSearchResults();
	for (int i= 0; i < searchResults.length; i++) {
		SearchMatch result= searchResults[i];
		IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(result);
		if (! (enclosingElement instanceof IImportDeclaration)) {
			String reference= getNormalizedTypeReference(result);
			if (! reference.startsWith(fPackage.getElementName())) {
				// is unqualified
				reference= cutOffInnerTypes(reference);
				ImportChange importChange= fImportsManager.getImportChange(typeReferences.getCompilationUnit());
				importChange.addImport(fPackage.getElementName() + '.' + reference);
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:RenamePackageProcessor.java

示例15: updateTypeImports

import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
/**
 * Add new imports to types in <code>typeReferences</code> with package <code>fNewElementName</code>
 * and remove old import with <code>fPackage</code>.
 * @param typeReferences type references
 * @throws CoreException should not happen
 */
private void updateTypeImports(SearchResultGroup typeReferences) throws CoreException {
	SearchMatch[] searchResults= typeReferences.getSearchResults();
	for (int i= 0; i < searchResults.length; i++) {
		SearchMatch result= searchResults[i];
		IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(result);
		if (enclosingElement instanceof IImportDeclaration) {
			IImportDeclaration importDeclaration= (IImportDeclaration) enclosingElement;
			updateImport(typeReferences.getCompilationUnit(), importDeclaration, getUpdatedImport(importDeclaration));
		} else {
			String reference= getNormalizedTypeReference(result);
			if (! reference.startsWith(fPackage.getElementName())) {
				reference= cutOffInnerTypes(reference);
				ImportChange importChange= fImportsManager.getImportChange(typeReferences.getCompilationUnit());
				importChange.removeImport(fPackage.getElementName() + '.' + reference);
				importChange.addImport(getNewPackageName() + '.' + reference);
			} // else: already found & updated with package reference search
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:RenamePackageProcessor.java


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