Package org.eclipse.dltk.core

Examples of org.eclipse.dltk.core.IType


                receiverTypes = PDTTypeInferenceUtils.getTypes((PHPCallExpression) receiverReference, sourceModule);
              } else if (receiverReference instanceof TypeReference) {
                receiverTypes = PDTTypeInferenceUtils.getTypes((TypeReference) receiverReference, sourceModule);
              }
              if (receiverTypes != null && receiverTypes.length > 0) {
                IType ancestorType = (IType) modelElement.getAncestor(IModelElement.TYPE);
                if (ancestorType != null && new PHPType(receiverTypes[0]).isInstanceOf(ancestorType)) {
                  replaceEdit = createReplaceEdit(astNode);
                }
              }
            }
View Full Code Here


    return modelElement.getElementName();
  }

  @Override
  public boolean canEnableUpdateReferences() {
    IType enclosingType = (IType) modelElement.getAncestor(IModelElement.TYPE);
    if (enclosingType == null) return false;

    try {
      return new PHPType(enclosingType).inResourceWithSameName();
    } catch (CoreException e) {
View Full Code Here

   * @return Returns the generated stub.
   * @throws CoreException
   */
  public static String getGetterStub(IField field, String getterName, boolean addComments, int flags, String indent) throws CoreException {
    String fieldName= field.getElementName();
    IType parentType= field.getDeclaringType();
   
   
    String typeName= "function";
    String accessorName = field.getType();
   
    if (accessorName == null)
      accessorName = "unknown_type";
   
    String lineDelim= "\n"; // Use default line delimiter, as generated stub has to be formatted anyway //$NON-NLS-1$
    StringBuffer buf= new StringBuffer();
    if (addComments) {
      String comment= CodeGeneration.getGetterComment(field.getScriptProject(), parentType.getFullyQualifiedName(), getterName, field.getElementName(), typeName, accessorName, lineDelim);
      if (comment != null) {
        buf.append(comment);
        buf.append(lineDelim);
      }         
    }
   
    buf.append(PHPFlags.toString(flags));
    buf.append(' ');     
     
    buf.append(typeName);
    buf.append(' ');
    buf.append(getterName);
    buf.append("() {"); //$NON-NLS-1$
    buf.append(lineDelim);
           
    fieldName= "$this->" + fieldName.replace("$", ""); //$NON-NLS-1$
   
    String body= org.eclipse.php.ui.CodeGeneration.getGetterMethodBodyContent(field.getScriptProject(), parentType.getTypeQualifiedName(), getterName, fieldName, lineDelim);
    if (body != null) {
      buf.append(indent + body);
    }
   
    buf.append(lineDelim);
View Full Code Here

   * @throws CoreException
   */
  public static String getSetterStub(IField field, String setterName, String typeName, boolean addComments, int flags, String indent, boolean fluent) throws CoreException {
   
    String fieldName= field.getElementName();
    IType parentType= field.getDeclaringType();
    IScriptProject project= field.getScriptProject();
    String accessorName = fieldName;
   
    String commentTypeName = typeName != null ? typeName : "unknown_type";
     

    String lineDelim= "\n"; // Use default line delimiter, as generated stub has to be formatted anyway //$NON-NLS-1$
    StringBuffer buf= new StringBuffer();
    if (addComments) {
      String comment= org.eclipse.php.ui.CodeGeneration.getSetterComment(project, parentType.getFullyQualifiedName(), setterName, field.getElementName(), commentTypeName, fieldName, accessorName, lineDelim);
      if (comment != null) {
        buf.append(comment);
        buf.append(lineDelim);
      }
    }
    buf.append(PHPFlags.toString(flags));
    buf.append(' ')
     
    buf.append("function "); //$NON-NLS-1$
    buf.append(setterName);
    buf.append('(');
   
    if (typeName != null) {
      buf.append(typeName);
      buf.append(' ');
    }
   
    buf.append(fieldName);
    buf.append(") {"); //$NON-NLS-1$
    buf.append(lineDelim);

    String argname = fieldName;
    fieldName= "$this->" + fieldName.replace("$", ""); //$NON-NLS-1$
   
    String body= org.eclipse.php.ui.CodeGeneration.getSetterMethodBodyContent(project, parentType.getFullyQualifiedName(), setterName, fieldName, argname, lineDelim);
    if (body != null) {
      buf.append(indent + body);
    }
   
    if (fluent) {
View Full Code Here

//    }
//  }
 
  protected QuerySpecification createQuery(DefUnit defunit) throws ModelException {
    ISourceModule sourceModule = EditorUtility.getEditorInputModelElement(deeEditor, false);
    IType type = (IType) DeeModelEngine.findCorrespondingModelElement(defunit, sourceModule);
    if (type == null) {
      return super.createQuery(defunit);
    }
    DLTKSearchScopeFactory factory = DLTKSearchScopeFactory.getInstance();
    IDLTKSearchScope scope = SearchEngine.createHierarchyScope(type);
View Full Code Here

    this.srcModule = srcModule;
    this.topLevelElement = srcModule.getType("sampledefs");
  }
 
  public void visitAll() {
    IType moduleType = topLevelElement;
   
    IField variable = topLevelElement.getField("Variable");
    IField variable2 = topLevelElement.getField("Variable2");
    IField varExtended = topLevelElement.getField("VarExtended");
    IField varExtended2 = topLevelElement.getField("VarExtended2");
    IField autoVar = topLevelElement.getField("AutoVar");
    IField autoVar2 = topLevelElement.getField("AutoVar2");
   
    IMethod function_ = topLevelElement.getMethod("Function");
    IMethod autoFunction = topLevelElement.getMethod("AutoFunction");
   
    IType struct_ = topLevelElement.getType("Struct");
    IType union_ = topLevelElement.getType("Union");
    IType class_ = topLevelElement.getType("Class");
    IType interface_ = topLevelElement.getType("Interface");
    IType template = topLevelElement.getType("Template");
    IType enum_ = topLevelElement.getType("Enum");
    IField enum_memberA = topLevelElement.getType("Enum").getField("EnumMemberA");
    IField enum_memberB = topLevelElement.getType("Enum").getField("EnumMemberB");
    IType mixin = topLevelElement.getType("Mixin");
    IType aliasVarDecl = topLevelElement.getType("AliasVarDecl");
    IType aliasFunctionDecl = topLevelElement.getType("AliasFunctionDecl");
    IType aliasFrag = topLevelElement.getType("AliasFrag");
    IType aliasFrag2 = topLevelElement.getType("AliasFrag2");
   
    // Nested elements:
    IField otherClass_fieldA = topLevelElement.getType("OtherClass").getField("fieldA");
    IMethod otherClass_methodB = topLevelElement.getType("OtherClass").getMethod("methodB");
    IMethod otherClass_this = topLevelElement.getType("OtherClass").getMethod("this");
    final IType otherTemplate = topLevelElement.getType("OtherTemplate");
    IType _OtherTemplate_TplNestedClass = otherTemplate.getType("TplNestedClass");
    IMethod tplFunc = otherTemplate.getType("TplNestedClass").getMethod("tplFunc");
   
   
    visitAllModelElements(
      moduleType,
View Full Code Here

 
  @Test
  public void testBasic() throws Exception { testBasic$(); }
  public void testBasic$() throws Exception {
    ISourceModule srcModule = getSourceModule(TR_SAMPLE_SRC1, "sampledefs.d");
    final IType topLevelElement = srcModule.getType("sampledefs");
   
    new SampleModelElementsVisitor(srcModule) {
      @Override
      public void visitAllModelElements(
        IType _Module,
        IField _Variable,
        IField _Variable2,
        IField _VarExtended,
        IField _VarExtended2,
        IField _AutoVar,
        IField _AutoVar2,
       
        IMethod _Function,
        IMethod _AutoFunction,
       
        IType _Struct,
        IType _Union,
        IType _Class,
        IType _Interface,
        IType _Template,
        IType _Enum,
        IField _Enum_memberA,
        IField _Enum_memberB,
       
        IType _Mixin,
        IType _AliasVarDecl,
        IType _AliasFunctionDecl,
        IType _AliasFrag,
        IType _AliasFrag2,
        IField _OtherClass_fieldA,
        IMethod _OtherClass_methodB,
        IMethod _OtherClass_this,
        IType _OtherTemplate_TplNestedClass,
        IMethod tplFunc
      ) {
       
        runCheckElementExists( _Module, EArcheType.Module, "module sampledefs;");
   
        runCheckElementExists(_Variable, EArcheType.Variable, "int Variable");
        runCheckElementExists(_Variable2, EArcheType.Variable, "Variable2");
        runCheckElementExists(_VarExtended, EArcheType.Variable, "/** DDOC */\r\nstatic ");
        runCheckElementExists(_VarExtended2, EArcheType.Variable, "VarExtended2");
       
       
        runCheckElementExists(_AutoVar, EArcheType.Variable, "auto AutoVar =");
        runCheckElementExists(_AutoVar2, EArcheType.Variable, "AutoVar2");
       
        runCheckElementExists(_Function, EArcheType.Function, "void Function(int fooParam)");
        runCheckElementExists(_AutoFunction, EArcheType.Function, "static AutoFunction(int fooParam)");
       
        runCheckElementExists(_Struct, EArcheType.Struct, "struct Struct { }");
        runCheckElementExists(_Union, EArcheType.Union, "union Union { }");
        runCheckElementExists(_Class, EArcheType.Class, "class Class {");
        runCheckElementExists(_Interface, EArcheType.Interface, "interface Interface { }");
   
        runCheckElementExists(_Template, EArcheType.Template, "template Template(");
        runCheckElementExists(_Enum, EArcheType.Enum, "enum Enum {");
        runCheckElementExists(_Enum_memberA, EArcheType.EnumMember, "EnumMemberA");
        runCheckElementExists(_Enum_memberB, EArcheType.EnumMember, "EnumMemberB");
       
       
        runCheckElementExists(_Mixin, EArcheType.Mixin, "mixin foo!() Mixin;");
       
        runCheckElementExists(_AliasVarDecl, EArcheType.Alias, "alias TargetFoo AliasVarDecl;");
        runCheckElementExists(_AliasFunctionDecl, EArcheType.Alias, "alias TargetFoo AliasFunctionDecl(");
        runCheckElementExists(_AliasFrag, EArcheType.Alias, "alias AliasFrag = int");
        runCheckElementExists(_AliasFrag2, EArcheType.Alias, "AliasFrag2 = char");
       
        runCheckElementExists(_OtherClass_fieldA, EArcheType.Variable, "int fieldA;");
        runCheckElementExists(_OtherClass_methodB, EArcheType.Function, "void methodB() { }");
        runCheckElementExists(_OtherClass_this,
          EArcheType.Constructor, "/*this*/ ", "this(int ctorParam)");
       
        runCheckElementExists(_OtherTemplate_TplNestedClass, EArcheType.Class, "class TplNestedClass  {");
        runCheckElementExists(tplFunc, EArcheType.Function, "void tplFunc(asdf.qwer parameter) {");
       
      }
     
      protected void runCheckElementExists(IMember element, EArcheType archeType, String code) {
        runCheckElementExists(element, archeType, null, code);
      }
      protected void runCheckElementExists(IMember element, EArcheType archeType, String nameKey, String code) {
        try {
          doCheckElementExists(srcModule, element, archeType, nameKey, code);
        } catch(ModelException e) {
          throw melnorme.utilbox.core.ExceptionAdapter.unchecked(e);
        }
      }
     
    }.visitAll();
   
    assertTrue(topLevelElement.getMethod("OtherFunction").exists());
    // TODO: need to re-enable this test, but need to complete search engine tests first
    if(false) {
      assertTrue(topLevelElement.getMethod("OtherFunction").getChildren().length == 0);
    }
  }
View Full Code Here

    ISourceModule srcModule = getSourceModule(TR_SAMPLE_SRC1, "moduleDeclImplicitName.d");
    assertEquals(srcModule.getElementName(), "moduleDeclImplicitName.d");
   
    assertTrue(ModelElementTestUtils.getChildren(srcModule, "moduleDeclImplicitName").size() > 0);
   
    IType topLevelElement = srcModule.getType("moduleDeclImplicitName");
   
    assertTrue(topLevelElement.getNameRange().getOffset() == 0);
   
    checkElementExists(srcModule, topLevelElement.getType("Foo"),
      EArcheType.Class, "class Foo");
    checkElementExists(srcModule, topLevelElement.getType("Foo").getMethod("func"),
      EArcheType.Function, "void func()");
   
  }
View Full Code Here

  }
 
  @Test
  public void testNameSpace() throws Exception { testNameSpace$(); }
  public void testNameSpace$() throws Exception {
    IType topLevelElement;
    topLevelElement = getTopLevelElement(TR_SAMPLE_SRC1, "/", "sampledefs");
    testNameSpace(topLevelElement, "", "Class");
   
    topLevelElement = getTopLevelElement(TR_SAMPLE_SRC3, "pack/", "mod1");
    testNameSpace(topLevelElement, "pack", "Mod1Class");
View Full Code Here

    return getSourceModule(srcFolder, folderName+"/"+moduleName+".d").getType(moduleName);
  }
 
  protected void testNameSpace(IType topLevelElement, String nameSpace, String sampleSubType) throws ModelException {
    assertEquals(topLevelElement.getNamespace().getQualifiedName("."), nameSpace);
    IType subElement = topLevelElement.getType(sampleSubType);
    assertTrue(subElement.exists() && subElement.getNamespace() == null);
  }
View Full Code Here

TOP

Related Classes of org.eclipse.dltk.core.IType

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.