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


Java CompilationUnit类代码示例

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


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

示例1: createImportHandle

import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
/**
 * Creates an IImportDeclaration from the given import statement
 */
protected IJavaElement createImportHandle(ImportReference importRef) {
	char[] importName = CharOperation.concatWith(importRef.getImportName(), '.');
	if ((importRef.bits & ASTNode.OnDemand) != 0)
		importName = CharOperation.concat(importName, ".*" .toCharArray()); //$NON-NLS-1$
	Openable openable = this.currentPossibleMatch.openable;
	if (openable instanceof CompilationUnit)
		return ((CompilationUnit) openable).getImport(new String(importName));

	// binary types do not contain import statements so just answer the top-level type as the element
	IType binaryType = ((ClassFile) openable).getType();
	String typeName = binaryType.getElementName();
	int lastDollar = typeName.lastIndexOf('$');
	if (lastDollar == -1) return binaryType;
	return createTypeHandle(typeName.substring(0, lastDollar));
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:MatchLocator.java

示例2: createTypeHandle

import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
/**
 * Creates an IType from the given simple top level type name.
 */
protected IType createTypeHandle(String simpleTypeName) {
	Openable openable = this.currentPossibleMatch.openable;
	if (openable instanceof CompilationUnit)
		return ((CompilationUnit) openable).getType(simpleTypeName);

	IType binaryType = ((ClassFile) openable).getType();
	String binaryTypeQualifiedName = binaryType.getTypeQualifiedName();
	if (simpleTypeName.equals(binaryTypeQualifiedName))
		return binaryType; // answer only top-level types, sometimes the classFile is for a member/local type

	// type name may be null for anonymous (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=164791)
	String classFileName = simpleTypeName.length() == 0 ? binaryTypeQualifiedName : simpleTypeName;
	IClassFile classFile = binaryType.getPackageFragment().getClassFile(classFileName + SuffixConstants.SUFFIX_STRING_class);
	return classFile.getType();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:MatchLocator.java

示例3: prepareMoveChange

import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
private void prepareMoveChange(
    ChangeInfo changeInfo, org.eclipse.ltk.core.refactoring.Change ch) {
  changeInfo.setName(ChangeInfo.ChangeName.MOVE);
  for (org.eclipse.ltk.core.refactoring.Change change : ((CompositeChange) ch).getChildren()) {
    if (change instanceof MoveCompilationUnitChange) {
      MoveCompilationUnitChange moveChange = (MoveCompilationUnitChange) change;
      String className = moveChange.getCu().getPath().lastSegment();
      changeInfo.setPath(
          moveChange.getDestinationPackage().getPath().append(className).toString());
      changeInfo.setOldPath(
          ((CompilationUnit) change.getModifiedElement()).getPath().toString());
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:15,代码来源:CodeAssist.java

示例4: prepareChangesInfo

import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
/**
 * Prepare the information about changes which were applied.
 *
 * @param changes array of the applied changes
 * @param changesInfo prepared list of {@link ChangeInfo}
 */
public void prepareChangesInfo(Change[] changes, List<ChangeInfo> changesInfo) {
  for (Change ch : changes) {
    if (ch instanceof DynamicValidationStateChange) {
      prepareChangesInfo(((DynamicValidationStateChange) ch).getChildren(), changesInfo);
    } else {
      ChangeInfo changeInfo = DtoFactory.newDto(ChangeInfo.class);
      String refactoringName = ch.getName();
      if (ch instanceof UndoTextFileChange) {
        changeInfo.setName(ChangeInfo.ChangeName.UPDATE);
        changeInfo.setPath(((CompilationUnit) ch.getModifiedElement()).getPath().toString());
      }
      if (refactoringName.startsWith("Rename")) {
        if (ch instanceof RenameCompilationUnitChange) {
          prepareRenameCompilationUnitChange(changeInfo, ch);
        } else if (ch instanceof RenamePackageChange) {
          prepareRenamePackageChange(changesInfo, changeInfo, ch);
        }
      }
      if (refactoringName.startsWith("Move")) {
        prepareMoveChange(changeInfo, ch);
      }

      changesInfo.add(changeInfo);
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:33,代码来源:RefactoringSession.java

示例5: prepareMoveChange

import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
private void prepareMoveChange(ChangeInfo changeInfo, Change ch) {
  changeInfo.setName(ChangeInfo.ChangeName.MOVE);
  if (ch instanceof MoveCompilationUnitChange) {
    MoveCompilationUnitChange moveChange = (MoveCompilationUnitChange) ch;
    String className = moveChange.getCu().getPath().lastSegment();
    changeInfo.setOldPath(
        moveChange.getDestinationPackage().getPath().append(className).toString());
    changeInfo.setPath(((CompilationUnit) ch.getModifiedElement()).getPath().toString());
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:11,代码来源:RefactoringSession.java

示例6: prepareRenameCompilationUnitChange

import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
private void prepareRenameCompilationUnitChange(ChangeInfo changeInfo, Change ch) {
  changeInfo.setName(ChangeInfo.ChangeName.RENAME_COMPILATION_UNIT);
  changeInfo.setPath(((CompilationUnit) ch.getModifiedElement()).getPath().toString());
  RenameCompilationUnitChange renameChange = (RenameCompilationUnitChange) ch;
  changeInfo.setOldPath(
      renameChange
          .getResourcePath()
          .removeLastSegments(1)
          .append(renameChange.getNewName())
          .toString());
}
 
开发者ID:eclipse,项目名称:che,代码行数:12,代码来源:RefactoringSession.java

示例7: createPackageDeclarationHandle

import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
/**
 * Creates an IImportDeclaration from the given import statement
 */
protected IJavaElement createPackageDeclarationHandle(CompilationUnitDeclaration unit) {
	if (unit.isPackageInfo()) {
		char[] packName = CharOperation.concatWith(unit.currentPackage.getImportName(), '.');
		Openable openable = this.currentPossibleMatch.openable;
		if (openable instanceof CompilationUnit) {
			return ((CompilationUnit) openable).getPackageDeclaration(new String(packName));
		}
	}
	return createTypeHandle(new String(unit.getMainTypeName()));
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:14,代码来源:MatchLocator.java

示例8: isAffectedByOpenable

import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
protected boolean isAffectedByOpenable(IJavaElementDelta delta, IJavaElement element, int eventType) {
	// change to working copy
	if (element instanceof CompilationUnit && ((CompilationUnit)element).isWorkingCopy()) {
		return super.isAffectedByOpenable(delta, element, eventType);
	}

	// if no focus, hierarchy is affected if the element is part of the region
	if (this.focusType == null) {
		return this.region.contains(element);
	} else {
		return super.isAffectedByOpenable(delta, element, eventType);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:14,代码来源:RegionBasedTypeHierarchy.java

示例9: getContent

import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
@SuppressWarnings("restriction")
private static char[] getContent(IType source) throws JavaModelException {
    char[] charContent = null;
    IOpenable op = source.getOpenable();
    if (op instanceof CompilationUnit) {
        charContent = ((CompilationUnit) (op)).getContents();
    }
    if (charContent == null) {
        String content = source.getSource();
        if (content != null) {
            charContent = content.toCharArray();
        }
    }
    return charContent;
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:16,代码来源:MarkerUtil.java

示例10: matches

import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
@Override
public boolean matches(Object javaElement) {
  
  if (javaElement instanceof IType) {      
    
    return super.matches(javaElement);
    
  } else if (javaElement instanceof CompilationUnit) {
    // When a java file that is changed is referenced from a ui.xml file,
    // eclipse gives a CompilationUnit instead of an IType, so this
    // logic is needed for this case.

    String enclosingClassName = getFullyQualifiedName();
    
    // if this LogicalType represents an inner class, we want only the outermost
    // enclosing class, because the given CompilationUnit represents a 
    // java file, and hence an outermost class
    int dollarIndex = enclosingClassName.indexOf('$');
    if (dollarIndex != -1) {
      enclosingClassName = enclosingClassName.substring(0, dollarIndex); 
    }
    
    CompilationUnit cu = ((CompilationUnit) javaElement);
    
    // CompilationUnit class doesn't just give us the full qualified name
    // of the top-most class... so we must assemble it ourselves...
    IPackageDeclaration[] pkgs;
    try {
      pkgs = cu.getPackageDeclarations();
    } catch (JavaModelException e) {
      return false;
    }
    
    if (pkgs.length > 0) {
      // cu.getElementName() returns a filename, so lop off the extension to get the class name
      String className = cu.getElementName().substring(0, cu.getElementName().indexOf('.'));
      String cuName = pkgs[0].getElementName() + "." + className;
      if (enclosingClassName.equals(cuName)) {
        return true;
      }
    }
  }

  return false;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:46,代码来源:UiBinderImportReferenceType.java

示例11: createImportContainer

import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
protected ImportContainer createImportContainer(ICompilationUnit parent) {
	return new AssistImportContainer((CompilationUnit)parent, this.newElements);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:4,代码来源:CompletionUnitStructureRequestor.java

示例12: createPackageDeclaration

import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
protected PackageDeclaration createPackageDeclaration(JavaElement parent, String name) {
	return new AssistPackageDeclaration((CompilationUnit) parent, name, this.newElements);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:4,代码来源:CompletionUnitStructureRequestor.java

示例13: AssistImportContainer

import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
public AssistImportContainer(CompilationUnit parent, Map infoCache) {
	super(parent);
	this.infoCache = infoCache;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:5,代码来源:AssistImportContainer.java

示例14: AssistPackageDeclaration

import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
public AssistPackageDeclaration(CompilationUnit parent, String name, Map infoCache) {
	super(parent, name);
	this.infoCache = infoCache;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:5,代码来源:AssistPackageDeclaration.java

示例15: WorkingCopyDocument

import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
WorkingCopyDocument(org.eclipse.jdt.core.ICompilationUnit workingCopy, SearchParticipant participant) {
	super(workingCopy.getPath().toString(), participant);
	this.charContents = ((CompilationUnit)workingCopy).getContents();
	this.workingCopy = workingCopy;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:6,代码来源:MatchLocator.java


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