Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.ICompilationUnit


          }
        }
        element = ((IJavaElement) element).getParent();
      }
      if (element instanceof ICompilationUnit) {
        ICompilationUnit cu= (ICompilationUnit)element;
        IType[] types= cu.getAllTypes();
 
        for (int i= 0; i < types.length; i++) {
          if (isBehaviorType(types[i])) {
            result.add(new ConfigurationState(types[i]));
          }
View Full Code Here


  private boolean isBehaviour(IJavaElement element) {
    try {
      IType testType = null;
      if (element instanceof ICompilationUnit) {
        ICompilationUnit cu = (ICompilationUnit) element;
        testType = cu.getType(Signature.getQualifier(cu
            .getElementName()));
      } else if (element instanceof IClassFile) {
        testType = ((IClassFile) element).getType();
      } else if (element instanceof IType) {
        testType = (IType) element;
View Full Code Here

        public IType createType(IPackageFragment pack, String cuName, String source) throws JavaModelException {
                StringBuffer buf= new StringBuffer();
                buf.append("package " + pack.getElementName() + ";\n");
                buf.append("\n");
                buf.append(source);
                ICompilationUnit cu= pack.createCompilationUnit(cuName, buf.toString(), false, null);
                return cu.getTypes()[0];
        }
View Full Code Here

  /**
   * @return the CompilationUint that is an ancestor JavaElement or the
   *         JavaElement itself
   */
  public ICompilationUnit getCompilationUnit() {
    ICompilationUnit result = null;
    IJavaElement input = getJavaElement();

    if (input.getElementType() == IJavaElement.COMPILATION_UNIT)
      result = (ICompilationUnit) input;
    else {
View Full Code Here

      IPackageFragment fragment = root.getPackageFragment(packageName);
      if(!fragment.exists()){
        return false;
      }

      ICompilationUnit unit = fragment.getCompilationUnit(className + ".java");
      return unit.exists();

    } catch(Exception ex){
      ex.printStackTrace();
      return false;
    }
View Full Code Here

  }
 
  public IContentProposal[] getProposals(String contents, int position) {
    try {
      CompletionProposalCollector collector = new CompletionProposalCollector(project);
      ICompilationUnit unit = FieldAssistUtils.getTemporaryCompilationUnit(project);
      contents = contents.substring(0, position);
      String source = "public class _xxx { public static void hoge(){ " + contents + "}}";
      FieldAssistUtils.setContentsToCU(unit, source);
      unit.codeComplete(source.length() - 2, collector, DefaultWorkingCopyOwner.PRIMARY);
      IJavaCompletionProposal[] proposals = collector.getJavaCompletionProposals();
      List<IContentProposal> result = new ArrayList<IContentProposal>();
     
      for(int j=0;j<proposals.length;j++){
        if(proposals[j].getImage()!=null){
View Full Code Here

      final JavaContentAssistInvocationContext jcaic = (JavaContentAssistInvocationContext) context;
      final IType expectedType = jcaic.getExpectedType();
      if (expectedType != null && "String".equals(expectedType.getElementName())) {

        final IDocument document = jcaic.getDocument();
        final ICompilationUnit cu = jcaic.getCompilationUnit();

        final IRegion wcr = DocumentHelper.findWicketComponentRegion(document, context.getInvocationOffset());
        if (wcr != null) {
          final IRegion javaRegion = DocumentHelper.findWord(document, wcr.getOffset());
          try {
            final IJavaElement[] jes = cu.codeSelect(javaRegion.getOffset(), javaRegion.getLength());
            if (jes.length == 1 && TypeHelper.isWicketJavaElement(jes[0])) {

              final IResource resource = cu.getResource();
              final String openKind = jes[0].getElementName().equals(DocumentHelper.GET_STRING) ? WicketHyperlink.PROPERTIES : WicketHyperlink.HTML;
              final WicketHyperlink wh = new WicketHyperlink(new Region(0, 0), "", openKind);
              final List<String> filenamesToOpen = wh.getFilenamesToOpen(resource, openKind);

              for (final String filename : filenamesToOpen) {
View Full Code Here

        if (javaFile == null || !javaFile.exists() || !FileSearcher.haveSameRelativePathToParentSourceFolder(javaFile, htmlFile)) {
          return false; // there is no Java File with this name
        }

        final ICompilationUnit compUnit = JavaCore.createCompilationUnitFrom(javaFile);
        try {
          final IType[] types = compUnit.getTypes();
          if (types.length > 0) {
            final SourceType type = (SourceType) types[0];
            final boolean isWicketComponent = TypeHelper.isWicketJavaElement(type);
            if (isWicketComponent) {
              this.compilationUnit = compUnit;
View Full Code Here

    proposal.sessionStarted();
    ContentAssistInvocationContext context = new ContentAssistInvocationContext(javaDocument, 0);
    IProgressMonitor monitor = new NullProgressMonitor();
    assertEquals(proposal.computeCompletionProposals(context, monitor).size(), 0);

    final ICompilationUnit cu = JavaCore.createCompilationUnitFrom(javaFile);
    ITextViewer viewer = new TextViewer(new Shell(), 0);
    int offset = 420;
    context = new JavaContentAssistInvocationContext(viewer, offset, new CompilationUnitEditor()) {
      @SuppressWarnings("restriction")
      @Override
View Full Code Here

  }

  public static List<Object> getSupertypes(final IFile javaFile) {
    final List<Object> list = new ArrayList<Object>();
    if (javaFile != null) {
      final ICompilationUnit icu = JavaCore.createCompilationUnitFrom(javaFile);
      try {
        final IType[] allTypes = icu.getAllTypes();
        for (final IType type : allTypes) {
          final ITypeHierarchy sth = type.newTypeHierarchy(null);
          final IType[] supertypes = sth.getAllSupertypes(type);
          for (final IType supertype : supertypes) {
            final IClassFile classFile = supertype.getClassFile();
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.ICompilationUnit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.