Package org.eclipse.dltk.ast.declarations

Examples of org.eclipse.dltk.ast.declarations.ModuleDeclaration


    // getAST:
    Object mdObj = context.get(IBuildContext.ATTR_MODULE_DECLARATION);
    if (!(mdObj instanceof ModuleDeclaration)) {
      return;
    }
    ModuleDeclaration md = (ModuleDeclaration) mdObj;
    IProblemReporter problemReporter = context.getProblemReporter();
    ISourceModule smod = context.getSourceModule();

    // get Types:
    Set<String> types = null;
    try {
      types = importBasicTypeSystem();
    } catch (InvalidXMLException e1) {
      System.err.println("ERROR: Failed to get BasicTypeSystem!! " + this.toString());
      // problemReporter.reportProblem(problem)
    } catch (IOException e1) {
      System.err.println("ERROR: Failed to get BasicTypeSystem!! " + this.toString());
    }
    if (types == null) {
      types = new TreeSet<String>();
    }

    // traverse:
    ISourceLineTracker linetracker = context.getLineTracker();

    Set<String> shortTypes = getShortTypeNames(types);
    try {
      ASTVisitor visitor = new TypeCheckerVisitor(problemReporter, linetracker, smod, types,
              shortTypes);
      md.traverse(visitor);
    } catch (Exception e) {
      RutaIdePlugin.error(e);
    }
  }
View Full Code Here


    return highlightings;
  }

  public void doOtherHighlighting(ISourceModule code,
          final ISemanticHighlightingRequestor semanticHighlightingRequestor) {
    ModuleDeclaration moduleDeclaration = SourceParserUtil
            .getModuleDeclaration((org.eclipse.dltk.core.ISourceModule) (code.getModelElement()));
    if (moduleDeclaration instanceof RutaModuleDeclaration) {
      RutaModuleDeclaration md = (RutaModuleDeclaration) moduleDeclaration;
      if (md != null) {
View Full Code Here

  protected String buildPathForClass(IType type) throws ModelException {
    String path = null;
    if (type != null) {
      ISourceModule sourceModule = type.getSourceModule();
      ModuleDeclaration moduleDeclaration = SourceParserUtil
          .getModuleDeclaration(sourceModule);
      TypeDeclaration typeDeclaration = PHPModelUtils.getNodeByClass(
          moduleDeclaration, type);
      path = getPHPDocLink(typeDeclaration);
View Full Code Here

  }

  protected String buildPathForMethod(IMethod method) {

    ISourceModule sourceModule = method.getSourceModule();
    ModuleDeclaration moduleDeclaration = SourceParserUtil
        .getModuleDeclaration(sourceModule);
    MethodDeclaration methodDeclaration;
    try {
      methodDeclaration = PHPModelUtils.getNodeByMethod(
          moduleDeclaration, method);
View Full Code Here

    return docBlockText;
  }

  private boolean isParameter(IField field) {
    ISourceModule sourceModule = field.getSourceModule();
    ModuleDeclaration moduleDeclaration = SourceParserUtil
        .getModuleDeclaration(sourceModule);
    ASTNode fieldDeclaration = null;
    try {
      fieldDeclaration = PHPModelUtils.getNodeByField(moduleDeclaration,
          field);
View Full Code Here

      project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
      PHPCoreTests.waitForIndexer();
      PHPCoreTests.waitForAutoBuild();

      ISourceModule sourceModule = DLTKCore.createSourceModuleFrom(file);
      ModuleDeclaration moduleDecl = SourceParserUtil
          .getModuleDeclaration(sourceModule);

      ASTNodeSearcher searcher = new ASTNodeSearcher(sourceModule,
          criteriaFunction);
      moduleDecl.traverse(searcher);

      Assert.assertNotNull("Method call " + criteriaFunction
          + "() in code: " + code, searcher.getResult());
      Assert.assertNotNull("Can't find context for " + criteriaFunction
          + "() in code: " + code, searcher.getContext());
View Full Code Here

    }

    final int offset = region.getOffset();

    final ISourceModule sourceModule = (ISourceModule) input;
    ModuleDeclaration moduleDeclaration = SourceParserUtil
        .getModuleDeclaration(sourceModule, null);
    if (moduleDeclaration == null) {
      return null;
    }

    IncludeHyperlinkVisitor includeVisitor = new IncludeHyperlinkVisitor(
        offset, sourceModule);
    try {
      moduleDeclaration.traverse(includeVisitor);
    } catch (Exception e) {
      PHPUiPlugin.log(e);
    }

    if (includeVisitor.getFile() != null) {
View Full Code Here

                    .getName();
                if (functionName.charAt(0) == '\\') {
                  functionName = functionName.substring(1);
                }
              } else {
                ModuleDeclaration parsedUnit = SourceParserUtil
                    .getModuleDeclaration(
                        field.getSourceModule(), null);
                org.eclipse.dltk.ast.ASTNode func = ASTUtils
                    .findMinimalNode(parsedUnit,
                        function.getStart(),
View Full Code Here

                // if (!useAlias) {
                // usePartName = usePartName
                // + NamespaceReference.NAMESPACE_SEPARATOR
                // + modelElement.getElementName();
                // }
                ModuleDeclaration moduleDeclaration = SourceParserUtil
                    .getModuleDeclaration(sourceModule);
                TextEdit edits = null;

                ASTParser parser = ASTParser
                    .newParser(sourceModule);
                parser.setSource(document.get().toCharArray());
                Program program = parser.createAST(null);

                // don't insert USE statement for current
                // namespace
                if (isSameNamespace(namespaceName, program,
                    sourceModule, offset)) {
                  return offset;
                }

                // find existing use statement:
                UsePart usePart = ASTUtils
                    .findUseStatementByNamespace(
                        moduleDeclaration, usePartName,
                        offset);

                List<String> importedTypeName = getImportedTypeName(
                    moduleDeclaration, offset);
                String typeName = namespaceName;
                // if (!useAlias) {
                // typeName = modelElement.getElementName()
                // .toLowerCase();
                // } else {
                // if (usePart != null
                // && usePart.getAlias() != null
                // && usePart.getAlias().getName() != null) {
                // typeName = usePart.getAlias().getName();
                // } else {
                // typeName = PHPModelUtils
                // .extractElementName(namespaceName)
                // .toLowerCase();
                // }
                // }

                // if the class/namesapce has not been imported
                // add use statement
                if (!importedTypeName.contains(typeName)) {

                  program.recordModifications();
                  AST ast = program.getAST();
                  NamespaceName newNamespaceName = ast
                      .newNamespaceName(
                          createIdentifiers(ast,
                              usePartName),
                          false, false);
                  UseStatementPart newUseStatementPart = ast
                      .newUseStatementPart(
                          newNamespaceName, null);
                  org.eclipse.php.internal.core.ast.nodes.UseStatement newUseStatement = ast
                      .newUseStatement(Arrays
                          .asList(new UseStatementPart[] { newUseStatementPart }));

                  NamespaceDeclaration currentNamespace = getCurrentNamespace(
                      program, sourceModule, offset - 1);
                  if (currentNamespace != null) {
                    // insert in the beginning of the
                    // current
                    // namespace:
                    int index = getLastUsestatementIndex(
                        currentNamespace.getBody()
                            .statements(), offset);
                    if (index > 0) {// workaround for bug
                            // 393253
                      try {
                        int beginLine = document
                            .getLineOfOffset(currentNamespace
                                .getBody()
                                .statements()
                                .get(index - 1)
                                .getEnd()) + 1;
                        newUseStatement
                            .setSourceRange(
                                document.getLineOffset(beginLine),
                                0);
                      } catch (Exception e) {
                      }
                    }
                    currentNamespace.getBody().statements()
                        .add(index, newUseStatement);
                  } else {
                    // insert in the beginning of the
                    // document:
                    int index = getLastUsestatementIndex(
                        program.statements(), offset);
                    if (index > 0) {// workaround for bug
                            // 393253
                      try {
                        int beginLine = document
                            .getLineOfOffset(program
                                .statements()
                                .get(index - 1)
                                .getEnd()) + 1;
                        newUseStatement
                            .setSourceRange(
                                document.getLineOffset(beginLine),
                                0);
                      } catch (Exception e) {
                      }
                    }
                    program.statements().add(index,
                        newUseStatement);
                  }
                  Map options = new HashMap(
                      PHPCorePlugin.getOptions());
                  // TODO project may be null
                  IScopeContext[] contents = new IScopeContext[] {
                      new ProjectScope(modelElement
                          .getScriptProject()
                          .getProject()),
                      InstanceScope.INSTANCE,
                      DefaultScope.INSTANCE };
                  for (int i = 0; i < contents.length; i++) {
                    IScopeContext scopeContext = contents[i];
                    IEclipsePreferences node = scopeContext
                        .getNode(PHPCorePlugin.ID);
                    if (node != null) {
                      if (!options
                          .containsKey(PHPCoreConstants.FORMATTER_USE_TABS)) {
                        String useTabs = node
                            .get(PHPCoreConstants.FORMATTER_USE_TABS,
                                null);
                        if (useTabs != null) {
                          options.put(
                              PHPCoreConstants.FORMATTER_USE_TABS,
                              useTabs);
                        }
                      }
                      if (!options
                          .containsKey(PHPCoreConstants.FORMATTER_INDENTATION_SIZE)) {
                        String size = node
                            .get(PHPCoreConstants.FORMATTER_INDENTATION_SIZE,
                                null);
                        if (size != null) {
                          options.put(
                              PHPCoreConstants.FORMATTER_INDENTATION_SIZE,
                              size);
                        }
                      }
                    }
                  }
                  ast.setInsertUseStatement(true);
                  edits = program.rewrite(document, options);
                  edits.apply(document);
                  ast.setInsertUseStatement(false);
                } else if (!useAlias
                    && (usePart == null || !usePartName
                        .equals(usePart
                            .getNamespace()
                            .getFullyQualifiedName()))) {
                  // if the type name already exists, use
                  // fully
                  // qualified name to replace
                  proposal.setReplacementString(NamespaceReference.NAMESPACE_SEPARATOR
                      + fullName);
                }

                // if (useAlias &&
                // needsAliasPrepend(modelElement)) {
                //
                // // update replacement string: add namespace
                // // alias prefix
                // String namespacePrefix = typeName
                // + NamespaceReference.NAMESPACE_SEPARATOR;
                // String replacementString = proposal
                // .getReplacementString();
                //
                // String existingNamespacePrefix =
                // readNamespacePrefix(
                // sourceModule, document, offset,
                // ProjectOptions
                // .getPhpVersion(editorElement));
                //
                // // Add alias to the replacement string:
                // if (!usePartName
                // .equals(existingNamespacePrefix)) {
                // replacementString = namespacePrefix
                // + replacementString;
                // }
                // proposal.setReplacementString(replacementString);
                // }

                if (edits != null) {
                  int replacementOffset = proposal
                      .getReplacementOffset()
                      + edits.getLength();
                  offset += edits.getLength();
                  proposal.setReplacementOffset(replacementOffset);
                }
              }
            }

          }
          return offset;
        }
        return offset;
      }
      // class members should return offset directly
      if (modelElement.getElementType() != IModelElement.TYPE
          && !(modelElement instanceof FakeConstructor)) {
        IModelElement type = modelElement
            .getAncestor(IModelElement.TYPE);
        if (type != null
            && !PHPFlags.isNamespace(((IType) type).getFlags())) {
          return offset;
        }
      }
    } catch (Exception e) {
      Logger.logException(e);
    }

    // add use statement if needed:
    IType namespace = PHPModelUtils.getCurrentNamespace(modelElement);
    if (namespace != null) {

      // find source module of the current editor:
      if (textViewer instanceof PHPStructuredTextViewer) {
        ITextEditor textEditor = ((PHPStructuredTextViewer) textViewer)
            .getTextEditor();
        if (textEditor instanceof PHPStructuredEditor) {
          IModelElement editorElement = ((PHPStructuredEditor) textEditor)
              .getModelElement();
          if (editorElement != null) {
            ISourceModule sourceModule = ((ModelElement) editorElement)
                .getSourceModule();

            try {
              String namespaceName = namespace.getElementName();
              String usePartName = namespaceName;
              boolean useAlias = !Platform
                  .getPreferencesService()
                  .getBoolean(
                      PHPCorePlugin.ID,
                      PHPCoreConstants.CODEASSIST_INSERT_FULL_QUALIFIED_NAME_FOR_NAMESPACE,
                      true, null);
              if (!useAlias) {
                usePartName = usePartName
                    + NamespaceReference.NAMESPACE_SEPARATOR
                    + modelElement.getElementName();
              }
              ModuleDeclaration moduleDeclaration = SourceParserUtil
                  .getModuleDeclaration(sourceModule);
              TextEdit edits = null;

              ASTParser parser = ASTParser
                  .newParser(sourceModule);
View Full Code Here

      }
    }

    public boolean visit(TraitUseStatement node) {
      ISourceModule sourceModule = getSourceModule();
      ModuleDeclaration moduleDeclaration = SourceParserUtil
          .getModuleDeclaration(sourceModule, null);
      FileContext context = new FileContext(sourceModule,
          moduleDeclaration, node.getStart());
      List<TraitStatement> tsList = node.getTsList();
      for (TraitStatement traitStatement : tsList) {
View Full Code Here

TOP

Related Classes of org.eclipse.dltk.ast.declarations.ModuleDeclaration

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.