本文整理汇总了Java中org.eclipse.jdt.core.ICompilationUnit.getTypes方法的典型用法代码示例。如果您正苦于以下问题:Java ICompilationUnit.getTypes方法的具体用法?Java ICompilationUnit.getTypes怎么用?Java ICompilationUnit.getTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.ICompilationUnit
的用法示例。
在下文中一共展示了ICompilationUnit.getTypes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
final ICompilationUnit icu = JavaUI.getWorkingCopyManager().getWorkingCopy(editorPart.getEditorInput());
try {
final IType type = icu.getTypes()[0];
final List<Field> fields = new ArrayList<>();
for (final IField field : type.getFields()) {
final String fieldName = field.getElementName();
final String fieldType = Signature.getSignatureSimpleName(field.getTypeSignature());
fields.add(new Field(fieldName, fieldType));
}
new WizardDialog(HandlerUtil.getActiveShell(event), new BuilderGeneratorWizard(icu, fields)).open();
}
catch (final JavaModelException e) {
e.printStackTrace();
}
return null;
}
示例2: getTypeOfOpenJavaEditor
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public static IType getTypeOfOpenJavaEditor() {
IJavaElement activeEditorJavaInput = EditorUtility.getActiveEditorJavaInput();
if (activeEditorJavaInput != null) {
if (activeEditorJavaInput.getElementType() == IJavaElement.COMPILATION_UNIT) {
try {
ICompilationUnit iCompilationUnit = (ICompilationUnit) activeEditorJavaInput;
String elementName = iCompilationUnit.getElementName();
elementName = elementName.substring(0,
elementName.lastIndexOf('.'));
IType[] types = iCompilationUnit.getTypes();
for (IType type : types) {
String fullyQualifiedName = type
.getFullyQualifiedName();
if (fullyQualifiedName.contains(elementName)) {
return type;
}
}
} catch (JavaModelException e1) {
e1.printStackTrace();
}
}
} else {
System.err.println("Java Editor is not open");
}
return null;
}
示例3: findReferences
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public Map<ClassInfo, List<CodeReference>> findReferences(ICompilationUnit compilationUnit) throws CoreException {
Map<ClassInfo, List<CodeReference>> references = new HashMap<>();
for (IType type : compilationUnit.getTypes()) {
findReferences(type, references);
}
return references;
}
示例4: setup
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
@Before
public void setup() throws Exception {
javaProject = new JavaProjectKit();
javaProject.enableJava5();
final IPackageFragmentRoot root = javaProject.createSourceFolder("src");
final ICompilationUnit compilationUnit = javaProject.createCompilationUnit(
root, "testdata/src", "methodlocator/Samples.java");
JavaProjectKit.waitForBuild();
javaProject.assertNoErrors();
methodLocator = new MethodLocator(compilationUnit.getTypes()[0]);
}
示例5: setup
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
@Before
public void setup() throws Exception {
javaProject = new JavaProjectKit();
javaProject.enableJava5();
final IPackageFragmentRoot root = javaProject.createSourceFolder("src");
final ICompilationUnit compilationUnit = javaProject.createCompilationUnit(
root, "testdata/src", "signatureresolver/Samples.java");
JavaProjectKit.waitForBuild();
javaProject.assertNoErrors();
type = compilationUnit.getTypes()[0];
createMethodIndex();
}
示例6: processCompilationUnit
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
private void processCompilationUnit(ITypeVisitor visitor,
ICompilationUnit unit, IProgressMonitor monitor)
throws JavaModelException {
visitor.visit(unit);
for (final IType type : unit.getTypes()) {
if (monitor.isCanceled()) {
break;
}
processType(visitor, new BinaryTypeName(type), type, monitor);
}
}
示例7: calculateValue
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
/**
* @see IJavaModel#calculateValue
*/
@Override
public void calculateValue(ICompilationUnit unit) {
IMethod[] iMethods = null;
IField[] iFields = null;
try {
IType[] iTypes = unit.getTypes();
for (IType iType : iTypes){
iMethods = iType.getMethods();
iFields = iType.getFields();
}
if ((iFields != null && iMethods != null) && (iFields.length > 1 && iMethods.length > 1)) {
for (IField field: iFields){
sharedAttributesPerMethods.put(field.getElementName(), new HashSet<String>());
nonSharedAttributesPerMethods.put(field.getElementName(), new HashSet<String>());
}
for (IMethod method: iMethods){
connectedComponents.put(method.getElementName(), new HashSet<String>());
}
checkMethodsWithSharedAttributes(iMethods);
if (LCOMType.LCOM.toString() == getLcomType()){
setLcomValue(calculateLCOMValue());
}else if (LCOMType.LCOM2.toString() == getLcomType()){
setLcom2Value(calculateLCOM2Value());
}else{
setLcom4Value(calculateLCOM4Value());
}
}
} catch (JavaModelException exception) {
logger.error(exception);
}
}
示例8: _beforeAllCompilationUnits_setRootClass
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
private void _beforeAllCompilationUnits_setRootClass(List<ICompilationUnit> allCompilationUnits) {
// XXX. getReporter() still null here
IType mainType = null;
for (ICompilationUnit compUnit : allCompilationUnits) {
IType[] compUnitTypes = null;
try {
compUnitTypes = compUnit.getTypes();
}
catch (JavaModelException e) {
e.printStackTrace();
}
for (IType iType : compUnitTypes) {
String typeName = iType.getFullyQualifiedName();
// XXX. MainClass not fully qualified?
if (typeName.endsWith(Config.MAINCLASS)) {
mainType = iType;
break;
}
}
}
if (mainType == null) {
// XXX. Use getReporter(); but here, still null. So using System.err
// getReporter().reportUserProblem("Cannot find main type. Specify main type in properties file", null,
// getName());
System.err.println("Cannot find main type. Specify main type in properties file");
}
}
示例9: getAllClassesAndInterfaces
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
private void getAllClassesAndInterfaces() throws JavaModelException {
Crystal crystal = Crystal.getInstance();
TypeInfo typeInfo = TypeInfo.getInstance();
if (typeInfo == null)
return;
Iterator<ICompilationUnit> compilationUnitIterator = crystal.getCompilationUnitIterator();
if (compilationUnitIterator == null )
return;
while(compilationUnitIterator.hasNext()){
ICompilationUnit cu = compilationUnitIterator.next();
for(IType type :cu.getTypes()){
String fullyQualifiedName = type.getFullyQualifiedName();
Type archSumType = typeInfo.getType(fullyQualifiedName);
// Because the OGraph will contain types for things that are created, used, etc.
// Some Type objects may not be already created.
// This could cause problems when trying to use Type.getSubClasses(), etc.
// Here, we traverse the types in the project rather than the OGraph to create the Type objects
// If this Type object was not already created then create it!
// Make sure that initTypeStructures has been done by now
if(archSumType == null ) {
// archSumType = new Type(fullQualifiedName);
ITypeBinding typeBinding = crystal.getTypeBindingFromName(fullyQualifiedName);
if (typeBinding != null ) {
archSumType = Type.createFrom(typeBinding);
}
else {
System.err.println("Unexpected null");
}
}
// TODO: HIGH. The rest of this work is not necessary, is it? Could cut.
if(type.isInterface()){
allInterfaces.add(fullyQualifiedName);
//Interfaces only
}else if(Flags.isAbstract(type.getFlags())){
//Abstract Classes added to interfaces set and classes set
// XXX. This is fishy.
allInterfaces.add(fullyQualifiedName);
allClasses.add(fullyQualifiedName);
}else{
//Classes added to classes set
allClasses.add(fullyQualifiedName);
}
}
}
}
示例10: initProjectTypes
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
/**
* get all types of current project
*/
public static void initProjectTypes() {
//This time, the way to get all types of a project is correct
//TODO: may extend to get all inner types if possible and necessary in future study
Crystal instance = Crystal.getInstance();
Iterator<ICompilationUnit> compilationUnitIterator = instance
.getCompilationUnitIterator();
if (compilationUnitIterator != null) {
while (compilationUnitIterator.hasNext()) {
ICompilationUnit cu = compilationUnitIterator.next();
try {
for (IType type : cu.getTypes()) {
String key = type.getFullyQualifiedName();
// System.out.println(key);
projectTypes.add(key);
}
} catch (JavaModelException e) {
throw new RuntimeException(
"Unexpected problem: No nodes in " + instance);
}
}
}
/*
IWorkbenchWindow window = LoadUtils.getWindow();
if(window!=null){
IProject currentProject = WorkspaceUtilities.getCurrentProject(window);
if (currentProject != null) {
try {
IPackageFragment[] myPackages = JavaCore.create(currentProject).getPackageFragments();
for (IPackageFragment myPackage : myPackages) {
for (ICompilationUnit unit : myPackage.getCompilationUnits()) {
IPackageDeclaration[] pck = unit.getPackageDeclarations();
for (IPackageDeclaration pack : pck) {
String packName = pack.getElementName();
projectPacks.add(packName+".");
}
}
}
} catch (JavaModelException e) {
e.printStackTrace();
}
}
}*/
}