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


Java ImportDeclaration类代码示例

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


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

示例1: ClassModel

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入依赖的package包/类
ClassModel(ASTNodeFactory astNodeFactory, String className, Type superClassType, PackageDeclaration packageDeclaration,
           List<FieldDeclaration> fields, List<MethodModel> methods, List<ImportDeclaration> imports,
           List<TypeModel> innerTypes, List<ASTNode> modifiers) {
    groovism = provide();

    this.className = className;
    this.packageDeclaration = packageDeclaration;
    this.fields = fieldDeclarations(fields);
    this.methods = unmodifiableList(new LinkedList<>(methods));
    this.modifiers = unmodifiableList(new LinkedList<>(modifiers));
    this.imports = imports;
    this.innerTypes = unmodifiableList(new LinkedList<>(innerTypes));
    if (isTestClass(methods)) {
        this.superClassType = Optional.of(astNodeFactory.simpleType(Specification.class.getSimpleName()));
        imports.add(0, astNodeFactory.importDeclaration(Specification.class));
    } else {
        this.superClassType = Optional.ofNullable(superClassType);
    }
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:20,代码来源:ClassModel.java

示例2: InterfaceModel

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入依赖的package包/类
InterfaceModel(String typeName, Type superClassType, PackageDeclaration packageDeclaration,
               List<FieldDeclaration> fields, List<MethodModel> methods, List<ImportDeclaration> imports,
               List<ASTNode> modifiers) {
    groovism = provide();

    LinkedList<ImportDeclaration> importDeclarations = new LinkedList<>(imports);

    this.superClassType = Optional.ofNullable(superClassType).map(Object::toString);

    this.typeName = typeName;
    this.packageDeclaration = packageDeclaration;
    this.fields = unmodifiableList(new LinkedList<>(fields));
    this.methods = unmodifiableList(new LinkedList<>(methods));
    this.imports = unmodifiableList(importDeclarations);
    this.modifiers = unmodifiableList(modifiers);
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:17,代码来源:InterfaceModel.java

示例3: visit

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入依赖的package包/类
public boolean visit(ImportDeclaration node) {
    if (node.isOnDemand()) {
        String pckgName = node.getName().getFullyQualifiedName();
        checkInDir(pckgName);
    } else {
        String importName = node.getName().getFullyQualifiedName();
        if (importName.endsWith("." + nameParts[0])) {
            fullName = importName;
            for (int i = 1; i < nameParts.length; i++) {
                fullName += "." + nameParts[i];
            }
            found = true;
        }
    }
    return true;
}
 
开发者ID:linzeqipku,项目名称:SnowGraph,代码行数:17,代码来源:NameResolver.java

示例4: forCompilationUnit

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入依赖的package包/类
static UnresolvableImportMatcher forCompilationUnit(CompilationUnit cu) {
	Collection<ImportDeclaration> unresolvableImports= determineUnresolvableImports(cu);

	Map<String, Set<String>> typeImportsBySimpleName= new HashMap<>();
	Map<String, Set<String>> staticImportsBySimpleName= new HashMap<>();
	for (ImportDeclaration importDeclaration : unresolvableImports) {
		String qualifiedName= importDeclaration.isOnDemand()
				? importDeclaration.getName().getFullyQualifiedName() + ".*" //$NON-NLS-1$
						: importDeclaration.getName().getFullyQualifiedName();

		String simpleName= qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1);

		Map<String, Set<String>> importsBySimpleName= importDeclaration.isStatic()
				? staticImportsBySimpleName : typeImportsBySimpleName;
		Set<String> importsWithSimpleName= importsBySimpleName.get(simpleName);
		if (importsWithSimpleName == null) {
			importsWithSimpleName= new HashSet<>();
			importsBySimpleName.put(simpleName, importsWithSimpleName);
		}

		importsWithSimpleName.add(qualifiedName);
	}

	return new UnresolvableImportMatcher(typeImportsBySimpleName, staticImportsBySimpleName);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:26,代码来源:OrganizeImportsOperation.java

示例5: endVisit

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入依赖的package包/类
@Override
public void endVisit(ImportDeclaration node) {
	boolean filtered = false;
	if (!node.isOnDemand()) { // if it is not x.y.*
		ITypeBinding tb = (ITypeBinding) node.resolveBinding();
		String qualifiedName = tb.getQualifiedName();
		for (String filter : filters) {
			Pattern patternJava = Pattern.compile(filter);
			Matcher matcherJava = patternJava.matcher(qualifiedName);
			if (matcherJava.matches()) {
				filtered = true;
			}
		}
		/*
		 * if (!model.hasMapping(qualifiedName) && !filtered) {
		 * model.addMapping(new Entry(qualifiedName)); }
		 */

	}
}
 
开发者ID:aroog,项目名称:code,代码行数:21,代码来源:GenerateDefaultMap.java

示例6: hasImportDeclaration

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入依赖的package包/类
private boolean hasImportDeclaration(CompilationUnit unit) {
   List imports = unit.imports();
for(Iterator iter = imports.iterator(); iter.hasNext() ; ) {
	Object next = iter.next();
	if (next instanceof ImportDeclaration ) {
		ImportDeclaration importDecl = (ImportDeclaration)next;
		Name name = importDecl.getName();
		if (name instanceof QualifiedName ) {
			QualifiedName qName = (QualifiedName)name;
			String qNameString = qName.getFullyQualifiedName();
			if (qNameString.startsWith("edu.cmu.cs.aliasjava.annotations") ) {
				return true;
			}
		}
	}
}
   return false;
  }
 
开发者ID:aroog,项目名称:code,代码行数:19,代码来源:SaveAnnotations.java

示例7: getUsedVariableNames

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入依赖的package包/类
public Collection<String> getUsedVariableNames(int offset, int length) {
  HashSet<String> result = new HashSet<String>();
  IBinding[] bindingsBefore = getDeclarationsInScope(offset, VARIABLES);
  for (int i = 0; i < bindingsBefore.length; i++) {
    result.add(bindingsBefore[i].getName());
  }
  IBinding[] bindingsAfter = getDeclarationsAfter(offset + length, VARIABLES);
  for (int i = 0; i < bindingsAfter.length; i++) {
    result.add(bindingsAfter[i].getName());
  }
  List<ImportDeclaration> imports = fRoot.imports();
  for (int i = 0; i < imports.size(); i++) {
    ImportDeclaration decl = imports.get(i);
    if (decl.isStatic() && !decl.isOnDemand()) {
      result.add(ASTNodes.getSimpleNameIdentifier(decl.getName()));
    }
  }
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:ScopeAnalyzer.java

示例8: createOccurrenceUpdate

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入依赖的package包/类
private OccurrenceUpdate<? extends ASTNode> createOccurrenceUpdate(
    ASTNode node, CompilationUnitRewrite cuRewrite, RefactoringStatus result) {
  if (BUG_89686
      && node instanceof SimpleName
      && node.getParent() instanceof EnumConstantDeclaration) node = node.getParent();

  if (Invocations.isInvocationWithArguments(node))
    return new ReferenceUpdate(node, cuRewrite, result);
  else if (node instanceof SimpleName && node.getParent() instanceof MethodDeclaration)
    return new DeclarationUpdate((MethodDeclaration) node.getParent(), cuRewrite, result);
  else if (node instanceof MemberRef || node instanceof MethodRef)
    return new DocReferenceUpdate(node, cuRewrite, result);
  else if (ASTNodes.getParent(node, ImportDeclaration.class) != null)
    return new StaticImportUpdate(
        (ImportDeclaration) ASTNodes.getParent(node, ImportDeclaration.class), cuRewrite, result);
  else if (node instanceof LambdaExpression)
    return new LambdaExpressionUpdate((LambdaExpression) node, cuRewrite, result);
  else if (node.getLocationInParent() == ExpressionMethodReference.NAME_PROPERTY)
    return new ExpressionMethodRefUpdate(
        (ExpressionMethodReference) node.getParent(), cuRewrite, result);
  else return new NullOccurrenceUpdate(node, cuRewrite, result);
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:ChangeSignatureProcessor.java

示例9: copyImportsToDestination

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入依赖的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

示例10: copyImportToDestination

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入依赖的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

示例11: createStubTypeContext

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入依赖的package包/类
public static StubTypeContext createStubTypeContext(
    ICompilationUnit cu, CompilationUnit root, int focalPosition) throws CoreException {
  StringBuffer bufBefore = new StringBuffer();
  StringBuffer bufAfter = new StringBuffer();

  int introEnd = 0;
  PackageDeclaration pack = root.getPackage();
  if (pack != null) introEnd = pack.getStartPosition() + pack.getLength();
  List<ImportDeclaration> imports = root.imports();
  if (imports.size() > 0) {
    ImportDeclaration lastImport = imports.get(imports.size() - 1);
    introEnd = lastImport.getStartPosition() + lastImport.getLength();
  }
  bufBefore.append(cu.getBuffer().getText(0, introEnd));

  fillWithTypeStubs(bufBefore, bufAfter, focalPosition, root.types());
  bufBefore.append(' ');
  bufAfter.insert(0, ' ');
  return new StubTypeContext(cu, bufBefore.toString(), bufAfter.toString());
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:TypeContextChecker.java

示例12: visit

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入依赖的package包/类
@Override
public boolean visit(final CompilationUnit node) {
	if (node.getPackage() != null) {
		currentPackageName = node.getPackage().getName()
				.getFullyQualifiedName();
	}
	for (final Object decl : node.imports()) {
		final ImportDeclaration imp = (ImportDeclaration) decl;
		if (!imp.isStatic()) {
			final String fqn = imp.getName().getFullyQualifiedName();
			importedNames.put(fqn.substring(fqn.lastIndexOf('.') + 1),
					fqn);
		}
	}
	return true;
}
 
开发者ID:mast-group,项目名称:tassal,代码行数:17,代码来源:JavaTypeHierarchyExtractor.java

示例13: visit

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入依赖的package包/类
@Override
public boolean visit(QualifiedName node) {
	if (isMovedMember(node.resolveBinding())) {
		if (node.getParent() instanceof ImportDeclaration) {
			ITypeBinding typeBinding= node.resolveTypeBinding();
			if (typeBinding != null)
			 	fCuRewrite.getImportRewrite().removeImport(typeBinding.getQualifiedName());
			String imp= fCuRewrite.getImportRewrite().addImport(fTarget.getQualifiedName() + '.' + node.getName().getIdentifier());
			fCuRewrite.getImportRemover().registerAddedImport(imp);
		} else {
			rewrite(node, fTarget);
		}
		return false;
	} else {
		return super.visit(node);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:ReferenceAnalyzer.java

示例14: createOccurrenceUpdate

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入依赖的package包/类
private OccurrenceUpdate<? extends ASTNode> createOccurrenceUpdate(ASTNode node, CompilationUnitRewrite cuRewrite, RefactoringStatus result) {
	if (BUG_89686 && node instanceof SimpleName && node.getParent() instanceof EnumConstantDeclaration)
		node= node.getParent();

	if (Invocations.isInvocationWithArguments(node))
		return new ReferenceUpdate(node, cuRewrite, result);

	else if (node instanceof SimpleName && node.getParent() instanceof MethodDeclaration)
		return new DeclarationUpdate((MethodDeclaration) node.getParent(), cuRewrite, result);

	else if (node instanceof MemberRef || node instanceof MethodRef)
		return new DocReferenceUpdate(node, cuRewrite, result);

	else if (ASTNodes.getParent(node, ImportDeclaration.class) != null)
		return new StaticImportUpdate((ImportDeclaration) ASTNodes.getParent(node, ImportDeclaration.class), cuRewrite, result);

	else if (node instanceof LambdaExpression)
		return new LambdaExpressionUpdate((LambdaExpression) node, cuRewrite, result);

	else if (node.getLocationInParent() == ExpressionMethodReference.NAME_PROPERTY)
		return new ExpressionMethodRefUpdate((ExpressionMethodReference) node.getParent(), cuRewrite, result);

	else
		return new NullOccurrenceUpdate(node, cuRewrite, result);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:ChangeSignatureProcessor.java

示例15: endVisit

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入依赖的package包/类
@Override
public final void endVisit(final QualifiedName node) {
	final ASTNode parent= node.getParent();
	final Name qualifier= node.getQualifier();
	IBinding binding= qualifier.resolveBinding();
	if (binding instanceof ITypeBinding) {
		final ConstraintVariable2 variable= fModel.createTypeVariable((ITypeBinding) binding, new CompilationUnitRange(RefactoringASTParser.getCompilationUnit(node), new SourceRange(qualifier.getStartPosition(), qualifier.getLength())));
		if (variable != null)
			qualifier.setProperty(PROPERTY_CONSTRAINT_VARIABLE, variable);
	}
	binding= node.getName().resolveBinding();
	if (binding instanceof IVariableBinding && !(parent instanceof ImportDeclaration))
		endVisit((IVariableBinding) binding, qualifier, node);
	else if (binding instanceof ITypeBinding && parent instanceof MethodDeclaration)
		endVisit((ITypeBinding) binding, node);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:SuperTypeConstraintsCreator.java


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