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


Java IImportDeclaration.getElementName方法代码示例

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


在下文中一共展示了IImportDeclaration.getElementName方法的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: 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

示例3: 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

示例4: getImportDeclaration

import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
public static String getImportDeclaration(IFile file, String className)
		throws JavaModelException {
	String fullyQualifiedName = null;
	ICompilationUnit currentFile = JavaCore.createCompilationUnitFrom(file);
	IImportDeclaration[] imports = currentFile.getImports();
	for (IImportDeclaration iImportDeclaration : imports) {
		if (iImportDeclaration.getElementName().endsWith(
				MethodUtil.PACKAGE_DOT + className)) {
			fullyQualifiedName = iImportDeclaration.getElementName();
			break;
		}
	}
	if (fullyQualifiedName == null || fullyQualifiedName.length() <= 0) {
		IPackageDeclaration packageDeclaration = currentFile
				.getPackageDeclarations()[0];
		fullyQualifiedName = packageDeclaration.getElementName()
				+ MethodUtil.PACKAGE_DOT + className;
	}
	return fullyQualifiedName;
}
 
开发者ID:dongdn,项目名称:get-set-generator,代码行数:21,代码来源:ProjectUtil.java

示例5: getMatchedPackage

import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
public static String getMatchedPackage(String className, ICompilationUnit cUnit) throws JavaModelException {
	int higherAccuracy = 0;
	String matchedPackage = cUnit.getPackageDeclarations()[0].getElementName();
	IImportDeclaration[] imports = cUnit.getImports();
	for (IImportDeclaration impDec : imports) {
		String fullName = impDec.getElementName();
		int dotIndex = fullName.lastIndexOf('.');

		String lastNameOfImport = fullName.substring(dotIndex + 1);
		if (lastNameOfImport.equals(className) && higherAccuracy < 2) {
			matchedPackage = fullName.substring(0, dotIndex);
			higherAccuracy = 2;
		} else if (lastNameOfImport.equals("*") && higherAccuracy < 1) {
			matchedPackage = fullName.substring(0, dotIndex);
			higherAccuracy = 1;
		}
	}

	if (higherAccuracy > 0) return matchedPackage;

	if (cUnit.getType(className) != null) return cUnit.getPackageDeclarations()[0].getElementName();

	return "java.lang";
}
 
开发者ID:EsfingeFramework,项目名称:querybuilder_plugin,代码行数:25,代码来源:ParserHelper.java

示例6: addSeeds

import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
/**
 * Adds locals, constants, and imports to seed the search.
 * @param typeConstraint The type constraint.
 * @throws DebugException
 * @throws JavaModelException
 */
private void addSeeds(TypeConstraint typeConstraint) throws DebugException, JavaModelException {
	for (IJavaVariable l : stack.getLocalVariables())
		candidates.addWeighted(expressionMaker.makeVar(l.getName(), (IJavaValue)l.getValue(), EclipseUtils.getTypeOfVariableAndLoadIfNeeded(l, stack), thread));
	if (!stack.isStatic())
		objects.addWeighted(expressionMaker.makeThis(stack.getThis(), thisType, thread));
	if (!(typeConstraint instanceof MethodConstraint) && !(typeConstraint instanceof FieldConstraint))  // If we have a method or field constraint, we can't have null.)
		nulls.addWeighted(expressionMaker.makeNull(thread));
	if (stack.isStatic() || stack.isConstructor())
		names.addWeighted(expressionMaker.makeStaticName(stack.getReceivingTypeName(), thisType, thread));
	for (IImportDeclaration imp : imports) {
		// TODO: Handle static imports.
		// TODO: Decomp with deterministic version?
		if (!imp.isOnDemand()) {
			String fullName = imp.getElementName();
			String shortName = EclipseUtils.getUnqualifiedName(fullName);  // Use the unqualified typename for brevity.
			if (!Flags.isStatic(imp.getFlags())) {
				IJavaReferenceType importedType = (IJavaReferenceType)EclipseUtils.getTypeAndLoadIfNeeded(fullName, stack, target, typeCache);
				if (importedType != null) {
					if (hasPublicStaticFieldOrMethod(importedType))
						names.addWeighted(expressionMaker.makeStaticName(shortName, importedType, thread));
				}
			}
		}
	}
}
 
开发者ID:jgalenson,项目名称:codehint,代码行数:32,代码来源:StochasticExpressionGenerator.java

示例7: getImportedTypes

import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private List<IImport> getImportedTypes(final IImportDeclaration[] importDeclarations) {
  final List<IImport> importedTypes = new ArrayList<>();
  for (final IImportDeclaration importDeclaration : importDeclarations) {
    final String importName = importDeclaration.getElementName();
    final Path importPath = create(null, importName);
    importedTypes.add(new Import(importName, importName.endsWith("*") //$NON-NLS-1$
        ? importPath.getParent()
        : importPath));
  }
  return importedTypes;
}
 
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:12,代码来源:WorkspaceDependenciesInvestigator.java

示例8: getUpdatedImport

import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private String getUpdatedImport(IImportDeclaration importDeclaration) {
  String fullyQualifiedImportType = importDeclaration.getElementName();
  int offsetOfDotBeforeTypeName = fPackage.getElementName().length();
  String result =
      getNewPackageName() + fullyQualifiedImportType.substring(offsetOfDotBeforeTypeName);
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:8,代码来源:RenamePackageProcessor.java

示例9: createStringForNewImport

import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private String createStringForNewImport(
    ICompilationUnit movedUnit, IImportDeclaration importDecl) {
  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));
  return result.toString();
}
 
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:MoveCuUpdateCreator.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:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:16,代码来源:MoveCuUpdateCreator.java

示例11: createStringForNewImport

import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private String createStringForNewImport(ICompilationUnit movedUnit, IImportDeclaration importDecl) {
  	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));
return result.toString();
  }
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:14,代码来源:MoveCuUpdateCreator.java

示例12: matchParameterType

import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private static final boolean matchParameterType(IType type, String parameter, String targetParameter) throws JavaModelException {
	// FQCN or primitive
	if(parameter.equals(targetParameter)) {
		return true;
	}
	// inner class
	if(parameter.indexOf("$") != -1) {
		if(parameter.replace("$", ".").equals(targetParameter)) {
			return true;
		}
		if(parameter.substring(parameter.indexOf("$") + 1).equals(targetParameter)) {
			return true;
		}
	}
	// generics type parameter
	if(targetParameter.indexOf("<") != -1 && parameter.equals(targetParameter.substring(0, targetParameter.indexOf("<")))) {
		return true;
	}
	// targetParameter is not FQCN
	if(parameter.startsWith("java.lang.") && parameter.equals("java.lang." + targetParameter)) {
		return true;
	}
	// same package
	if(parameter.equals(type.getPackageFragment().getElementName() + "." + targetParameter)) {
		return true;
	}
	ICompilationUnit unit = type.getCompilationUnit();
	if(unit != null) {
		for(IImportDeclaration imp : unit.getImports()) {
			String importClass = imp.getElementName();
			if(importClass.endsWith("." + targetParameter) && parameter.equals(importClass)) {
				return true;
			} else if(importClass.endsWith(".*") && parameter.equals(importClass.substring(0, importClass.length() - 1) + targetParameter)) {
				return true;
			}
		}
	}
	return false;
}
 
开发者ID:masao-kunii,项目名称:byteman-editor,代码行数:40,代码来源:JavaUtils.java

示例13: checkConflictingTypes

import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private RefactoringStatus checkConflictingTypes(IProgressMonitor pm) throws CoreException {
  RefactoringStatus result = new RefactoringStatus();
  IJavaSearchScope scope = RefactoringScopeFactory.create(fType);
  SearchPattern pattern =
      SearchPattern.createPattern(
          getNewElementName(),
          IJavaSearchConstants.TYPE,
          IJavaSearchConstants.ALL_OCCURRENCES,
          SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
  ICompilationUnit[] cusWithReferencesToConflictingTypes =
      RefactoringSearchEngine.findAffectedCompilationUnits(pattern, scope, pm, result);
  if (cusWithReferencesToConflictingTypes.length == 0) return result;
  ICompilationUnit[] cusWithReferencesToRenamedType = getCus(fReferences);

  Set<ICompilationUnit> conflicts =
      getIntersection(cusWithReferencesToRenamedType, cusWithReferencesToConflictingTypes);
  if (cusWithReferencesToConflictingTypes.length > 0) {
    cus:
    for (ICompilationUnit cu : cusWithReferencesToConflictingTypes) {
      String packageName = fType.getPackageFragment().getElementName();
      if (((IPackageFragment) cu.getParent()).getElementName().equals(packageName)) {
        boolean hasOnDemandImport = false;
        IImportDeclaration[] imports = cu.getImports();
        for (IImportDeclaration importDecl : imports) {
          if (importDecl.isOnDemand()) {
            hasOnDemandImport = true;
          } else {
            String importName = importDecl.getElementName();
            int packageLength = importName.length() - getNewElementName().length() - 1;
            if (packageLength > 0
                && importName.endsWith(getNewElementName())
                && importName.charAt(packageLength) == '.') {
              continue cus; // explicit import from another package => no problem
            }
          }
        }
        if (hasOnDemandImport) {
          // the renamed type in the same package will shadow the *-imported type
          conflicts.add(cu);
        }
      }
    }
  }

  for (ICompilationUnit conflict : conflicts) {
    RefactoringStatusContext context = JavaStatusContext.create(conflict);
    String message =
        Messages.format(
            RefactoringCoreMessages.RenameTypeRefactoring_another_type,
            new String[] {getNewElementLabel(), BasicElementLabels.getFileName(conflict)});
    result.addError(message, context);
  }
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:55,代码来源:RenameTypeProcessor.java

示例14: checkConflictingTypes

import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private RefactoringStatus checkConflictingTypes(IProgressMonitor pm) throws CoreException {
	RefactoringStatus result= new RefactoringStatus();
	IJavaSearchScope scope= RefactoringScopeFactory.create(fType);
	SearchPattern pattern= SearchPattern.createPattern(getNewElementName(),
			IJavaSearchConstants.TYPE, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
	ICompilationUnit[] cusWithReferencesToConflictingTypes= RefactoringSearchEngine.findAffectedCompilationUnits(pattern, scope, pm, result);
	if (cusWithReferencesToConflictingTypes.length == 0)
		return result;
	ICompilationUnit[] 	cusWithReferencesToRenamedType= getCus(fReferences);

	Set<ICompilationUnit> conflicts= getIntersection(cusWithReferencesToRenamedType, cusWithReferencesToConflictingTypes);
	if (cusWithReferencesToConflictingTypes.length > 0) {
		cus: for (ICompilationUnit cu : cusWithReferencesToConflictingTypes) {
			String packageName= fType.getPackageFragment().getElementName();
			if (((IPackageFragment) cu.getParent()).getElementName().equals(packageName)) {
				boolean hasOnDemandImport= false;
				IImportDeclaration[] imports= cu.getImports();
				for (IImportDeclaration importDecl : imports) {
					if (importDecl.isOnDemand()) {
						hasOnDemandImport= true;
					} else {
						String importName= importDecl.getElementName();
						int packageLength= importName.length() - getNewElementName().length() - 1;
						if (packageLength > 0
								&& importName.endsWith(getNewElementName())
								&& importName.charAt(packageLength) == '.') {
							continue cus; // explicit import from another package => no problem
						}
					}
				}
				if (hasOnDemandImport) {
					// the renamed type in the same package will shadow the *-imported type
					conflicts.add(cu);
				}
			}
		}
	}
	
	for (ICompilationUnit conflict : conflicts) {
		RefactoringStatusContext context= JavaStatusContext.create(conflict);
		String message= Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_another_type,
			new String[] { getNewElementLabel(), BasicElementLabels.getFileName(conflict)});
		result.addError(message, context);
	}
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:47,代码来源:RenameTypeProcessor.java

示例15: getUpdatedImport

import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private String getUpdatedImport(IImportDeclaration importDeclaration) {
	String fullyQualifiedImportType= importDeclaration.getElementName();
	int offsetOfDotBeforeTypeName= fPackage.getElementName().length();
	String result= getNewPackageName() + fullyQualifiedImportType.substring(offsetOfDotBeforeTypeName);
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:7,代码来源:RenamePackageProcessor.java


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